Command Palette

Search for a command to run...

All challenges
DebuggingAdvanced

Tool Call Split Across Chunks

Your streaming agent occasionally crashes with 'Invalid tool call: missing arguments'. It only happens for long tool calls and is intermittent.

Symptoms
  • Intermittent 'Invalid tool call' errors
  • Happens for longer tool call arguments
  • Parser crashes mid-stream
  • Reproduces inconsistently
Evidence

Stream parser

def parse_chunk(chunk):
    tool_call = json.loads(chunk.delta.tool_calls[0].function.arguments)
    # crashes with JSONDecodeError on partial JSON

Stream chunks

chunk 1: '{"city": "San'
chunk 2: ' Francisco", "days":'
chunk 3: ' 5}'
Tasks
  • 1Explain why it crashes
  • 2Fix the parser
  • 3Add a safety net