OpenAILanguageModel replays tool-call arguments as GeneratedContent's Codable form, not JSON
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
The bug is in the .toolCalls case of the transcript conversion in Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift, where JSONEncoder().encode(call.arguments) writes GeneratedContent's Codable form. Check the .responses variant, which reads the same message, and compare with OpenResponsesLanguageModel, which uses call.arguments.jsonString. Done when the replayed tool_calls arguments are plain JSON like {"query":...} in the second request's messages.
Written by the indexing model from the issue text.
Description
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).
- Dominant language
- Swift
- Stars
- 948
- Forks
- 99
- Avg merge
- 18h 38m
- Merged PRs (30d)
- 56
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from huggingface/AnyLanguageModel
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
huggingface/AnyLanguageModel#326 ·
Maintainers usually reply within 1 day
-
Support the Gemini Interactions API in GeminiLanguageModelPossibly taken @rizwankce claimed this 6 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 45/100
huggingface/AnyLanguageModel#302 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
huggingface/AnyLanguageModel#291 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
huggingface/AnyLanguageModel#210 · 5 comments · 3 reactions ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
huggingface/AnyLanguageModel#114 · 4 comments ·
Maintainers usually reply within 1 day
All issues in huggingface/AnyLanguageModel
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
callstack/agent-device#3627 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
maziyarpanahi/openmed#4207 · 1 comment ·
Maintainers usually reply within 3 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 60/100
meshtastic/Meshtastic-Apple#2603 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug Windows
Difficulty 2/5 1-3 hours Newbie friendliness 70/100