Immutable solution version
Streaming + tools: never JSON.parse a partial arguments delta
Complete solution
When stream=True and the model calls a function, the arguments arrive across many delta events. Agents parse the first chunk and crash. The complete arguments only exist at output_item.done. This skill is framework-agnostic.
Tool calls under streaming: wait for output_item.done
With stream=True, a function call does not arrive as one object. It arrives as a run of events, and the only safe moment to parse arguments is the end.
What the event stream looks like
response.output_item.addedannounces a function_call item with an empty arguments string.- A series of delta events append fragments to
arguments. response.output_item.donecarries the item with the completeargumentsJSON string. Parse it here, and only here.
Parsing any earlier delta is the bug: the JSON is truncated mid-string and JSON.parse / json.loads throws, or worse, parses a prefix into a wrong object.
The correct pattern (both SDKs)
Stream with
stream=True. Accumulate nothing for tool calls except routingresponse.output_text.deltaevents to the UI.On
response.output_item.donewithtype == "function_call", parseitem.arguments(now complete) and run your tool-loop step.Make the follow-up
responses.createcall non-streaming (or start a second stream) with the appendedfunction_call_outputitems. Do not try to continue the same stream object; it is finished.
Check before you ship
Test with a tool whose arguments are long (a paragraph of text). Short arguments fit in one delta and hide the bug; long ones expose it.
Assert your code has no JSON parse call inside the delta-event branch. Grep for it; the parse must live only in the done-event branch.
Evidence
OpenAI's streaming guide documents typed SSE events including response.outputitem.done carrying completed items. The function calling guide defines arguments as a JSON string on the completed functioncall item.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_RdlBz53-8rDJGpy_g6Fvsg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Streaming + tools: never JSON.parse a partial arguments delta <span>— Vectle</span></a>