Problem
When an AI agent is streaming a response that includes tool calls (like searching the web or checking the weather), the tool call arguments arrive as partial JSON chunks that get assembled piece by piece. Once all chunks arrive, the framework parses the assembled JSON string.
The bug: If that JSON string is malformed — for example, because the network dropped mid-stream, the API had a hiccup, or the response got truncated — the JSON.parse call throws an error with no safety net around it. This crashes the entire streaming pipeline, and everything the agent had built up so far is lost: the text it was writing, any other tool calls it was making, token usage stats — all gone.
In simple terms: imagine you're on a phone call and someone reads you a long list of instructions. If they mumble one word, you'd just skip it and keep listening. But right now, the framework hangs up the entire call over that one mumbled word.
Impact
- Affects both OpenAI and Anthropic model integrations
- Users see unexpected crashes during streaming with no way to recover
- The agent loses all progress from that response and the conversation may stall
Locations
packages/adk/src/models/openai-llm.ts — 3 unprotected JSON.parse calls (lines ~188, ~299, ~348)
packages/adk/src/models/anthropic-llm.ts — 1 unprotected JSON.parse call (line ~282)
Expected Behavior
When tool call arguments can't be parsed, the framework should log a warning and continue with empty arguments rather than crashing the entire stream.
Fix
PR #644
Problem
When an AI agent is streaming a response that includes tool calls (like searching the web or checking the weather), the tool call arguments arrive as partial JSON chunks that get assembled piece by piece. Once all chunks arrive, the framework parses the assembled JSON string.
The bug: If that JSON string is malformed — for example, because the network dropped mid-stream, the API had a hiccup, or the response got truncated — the
JSON.parsecall throws an error with no safety net around it. This crashes the entire streaming pipeline, and everything the agent had built up so far is lost: the text it was writing, any other tool calls it was making, token usage stats — all gone.In simple terms: imagine you're on a phone call and someone reads you a long list of instructions. If they mumble one word, you'd just skip it and keep listening. But right now, the framework hangs up the entire call over that one mumbled word.
Impact
Locations
packages/adk/src/models/openai-llm.ts— 3 unprotectedJSON.parsecalls (lines ~188, ~299, ~348)packages/adk/src/models/anthropic-llm.ts— 1 unprotectedJSON.parsecall (line ~282)Expected Behavior
When tool call arguments can't be parsed, the framework should log a warning and continue with empty arguments rather than crashing the entire stream.
Fix
PR #644