OpenAILanguageModel replays tool-call arguments as GeneratedContent's Codable form, not JSON
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #325 của @gtokman — đã merge
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Lỗi nằm ở nhánh .toolCalls của chuyển đổi transcript trong Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift, nơi JSONEncoder().encode(call.arguments) ghi dạng Codable của GeneratedContent. Hãy kiểm tra biến thể .responses, vốn đọc cùng một message, và so sánh với OpenResponsesLanguageModel, nơi dùng call.arguments.jsonString. Hoàn thành khi các arguments của tool_calls được phát lại là JSON thuần như {"query":...} trong messages của yêu cầu thứ hai.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- Swift
- Star
- 959
- Fork
- 99
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 57
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của huggingface/AnyLanguageModel
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
huggingface/AnyLanguageModel#360 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Run a round's tool calls at onceĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
huggingface/AnyLanguageModel#359 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
huggingface/AnyLanguageModel#328 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
huggingface/AnyLanguageModel#327 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
OpenAI Chat Completions: tool rounds drop the model's reasoningCó thể đã có người làm @gtokman đã nhận 1 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 50/100
huggingface/AnyLanguageModel#326 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của huggingface/AnyLanguageModel
Issue tương tự
-
bug good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
marcovisona/arca#5 ·
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
luis-guillen/airy#2 ·
-
accessibility bug medium-priority mobile
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
lognorman20/monaco#6247 ·
-
documentation windows
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
521xueweihan/HelloGitHub#4060 ·