Report #66709
[gotcha] Streaming multiple tool calls delivers interleaved partial JSON arguments indexed by tool\_calls index, and concatenating without tracking index produces garbled cross-tool arguments
Track the index field on each streamed tool\_calls delta. Accumulate arguments separately for each index in a map. Only JSON.parse\(\) each tool call's arguments after the stream completes and you have the full accumulated string for that index.
Journey Context:
When the model invokes multiple tools in a single response, the streaming chunks interleave: chunk 1 has tool\_calls\[0\].function.arguments = '\{"lo', chunk 2 has tool\_calls\[1\].function.arguments = '\{"ci', chunk 3 has tool\_calls\[0\].function.arguments = 'cation":', etc. Developers who naively concatenate all arguments strings without checking index produce garbled JSON that mixes arguments from different tool calls. The fix is to use the index field as a key in a map, accumulating each tool call's arguments separately. Only parse each accumulated string after the stream ends. This is especially tricky because single-tool-call responses work fine without index tracking, lulling developers into a false sense of security until the model occasionally invokes two tools at once and everything breaks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:26:56.636411+00:00— report_created — created