All challengesHow to investigate an intermittent streaming bug
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.
Step 1 of 5
Capture raw
Log the exact bytes or events as they arrive, before any parsing. You cannot reason about a stream you have only seen through your own code.
Intermittent usually means a hidden variable. Capture the raw data and find what the bad cases share.
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 JSONStream chunks
chunk 1: '{"city": "San'
chunk 2: ' Francisco", "days":'
chunk 3: ' 5}' Tasks
- 1Explain why it crashes
- 2Fix the parser
- 3Add a safety net