Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

OpenAILanguageModel replays tool-call arguments as GeneratedContent's Codable form, not JSON

未关闭 适合新手
#324 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@gtokman 已经在做这个了。

开始于 2026年10月13日。

  • #325 来自 @gtokman —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
swift
领域
api

调研方向

错误位于 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

  1. LanguageModelSession with OpenAILanguageModel (Chat Completions) and any tool.
  2. Ask something that makes the model call the tool, then ask a follow-up in the same session.
  3. Inspect the second request's messages: the assistant tool_calls[].function.arguments hold 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

huggingface/AnyLanguageModel 的其他 Issue

查看 huggingface/AnyLanguageModel 的全部 Issue

相似的 Issue

更多 Swift Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。