OpenAILanguageModel replays tool-call arguments as GeneratedContent's Codable form, not JSON
维护者通常 1 天内回复
评估
调研方向
错误位于 Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift 中转录转换的 .toolCalls 分支,其中 JSONEncoder().encode(call.arguments) 写入的是 GeneratedContent 的 Codable 形式。请检查读取同一消息的 .responses 变体,并与使用 call.arguments.jsonString 的 OpenResponsesLanguageModel 进行比较。当重放的 tool_calls 参数在第二个请求的 messages 中是纯 JSON,例如 {"query":...},即完成。
由索引模型根据 Issue 内容生成。
描述
Summary
OpenAILanguageModel replays earlier tool calls with their arguments encoded by GeneratedContent's Codable conformance instead of as plain JSON. On the next turn the model sees arguments like:
{"kind":{"type":"structure","properties":{"query":{"kind":{"type":"string","value":"Apple stock 2026"}}},"orderedKeys":["query"]}}
instead of {"query":"Apple stock 2026"}. Models then copy that shape in their own new tool calls, the arguments don't match the tool's schema, and decoding them throws LanguageModelSession.ToolCallError, which ends the response.
Where
Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift, in the .toolCalls case of the transcript conversion (line 1369 at 0.16.0, line 1374 on main / 1.0.0):
if let data = try? JSONEncoder().encode(call.arguments),
let jsonString = String(data: data, encoding: .utf8)
GeneratedContent.encode(to:) writes id and kind, so this isn't the arguments' JSON. The .responses variant converts from the same message, so it's affected too. OpenResponsesLanguageModel already does it correctly with call.arguments.jsonString.
Suggested fix
let argumentsJSON = call.arguments.jsonString
Reproduce
LanguageModelSessionwithOpenAILanguageModel(Chat Completions) and any tool.- Ask something that makes the model call the tool, then ask a follow-up in the same session.
- Inspect the second request's
messages: the assistanttool_calls[].function.argumentshold the{"kind":…}encoding.
Impact we measured
Benchmarking 4 models over 11 multi-turn conversations through the Vercel AI Gateway (Chat Completions): Gemini 4 Argon and Claude Haiku 5.5 each produced follow-up tool calls in the {"kind":…} shape (decoded as empty arguments, or failing to decode), which ended the reply. Claude Sonnet 5.5 happened to ignore it.
Seen on 0.16.0; the line is unchanged on main (1.0.0).
- 主要语言
- Swift
- 星标
- 948
- 派生
- 99
- 平均合并
- 19 小时 57 分钟
- 30 天内合并 PR
- 50
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
huggingface/AnyLanguageModel 的其他 Issue
-
MLXLanguageModel tool calling: flaky repeat check, missing assistant tool-call turn, and tool-round limits可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 4/5 3-5 天 新手友好度 18/100
huggingface/AnyLanguageModel#328 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 62/100
huggingface/AnyLanguageModel#327 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 50/100
huggingface/AnyLanguageModel#326 · 1 条评论 ·
维护者通常 1 天内回复
-
Support the Gemini Interactions API in GeminiLanguageModel可能重新可做 @rizwankce 于 7 天前认领,目前没有进行中的 PR。 未关闭
难度 5/5 一周以上 新手友好度 45/100
huggingface/AnyLanguageModel#302 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
huggingface/AnyLanguageModel#291 · 1 个 reaction ·
维护者通常 1 天内回复
查看 huggingface/AnyLanguageModel 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
nightscout/nightguard#368 ·
-
builtin-port enhancement
难度 2/5 1-3 小时 新手友好度 62/100
cmlarsen/writemorebetter#235 ·
维护者通常 1 天内回复
-
bug-pending-triage
难度 2/5 1-3 小时 新手友好度 70/100
NativeScript/NativeScript#11525 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
callstack/agent-device#3627 ·
维护者通常 1 天内回复