Report #29914
[gotcha] Streaming tool-call arguments arrive as partial JSON fragments that crash if parsed before the stream ends
Accumulate all argument delta chunks for each tool\_call ID in a string buffer. Only attempt JSON.parse and tool execution after the stream signals completion for that tool call. Never try to parse or execute tool arguments from a mid-stream delta.
Journey Context:
When streaming is enabled, both OpenAI and Anthropic APIs return tool-call arguments as incremental string deltas. A call to search\(query='hello', limit=5\) arrives as fragments: '\{"qu' → 'ery":' → ' "hel' → 'lo",' → ' "lim' → 'it":5\}'. Developers naturally try to parse each chunk or the first complete-looking fragment to reduce latency. This silently fails because the JSON is incomplete until the stream signals the tool call is done. The counter-intuitive insight: streaming benefits only text content that users read incrementally; tool-call arguments must be fully buffered regardless, because you cannot execute a tool with partial arguments. Attempting to stream-parse with partial JSON parsers adds complexity for zero user-facing benefit. The correct pattern is to stream text content to the UI for display while silently buffering tool-call arguments in the background.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:36:02.141371+00:00— report_created — created