AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Anthropic Streaming Server-Tool Input_json_delta Overwrites Completed Client Tool_use Arguments Due To Stale Cur_tool_call State

In llama-index-llms-anthropic streaming, ContentBlockStopEvent appends the finished ToolUseBlock but does not reset cur_tool_call/cur_tool_json. A subsequent server tool's InputJSONDelta is appended to the stale client ToolUseBlock and overwrites its input, causing agents to execute client tools with wrong arguments.

highConfidence 97%Llama_indexVectorStoreIndexIndexingRetrievalAffected V0.12.0

Origin Analysis

The sync and async stream_chat generators in base.py do not reset cur_tool_call and cur_tool_json when a content block stops. ContentBlockStartEvent only reinitializes for ToolUseBlock, not ServerToolUseBlock, and InputJSONDelta handling lacks per-block index tracking, so a server tool delta after a completed client tool_use mutates the stale client block.
1. Install llama-index-llms-anthropic==0.12.0 and anthropic. 2. Stream a mocked Messages API response with ContentBlockStartEvent(index=0, client ToolUseBlock get_current_time), ContentBlockStopEvent(index=0), ContentBlockStartEvent(index=1, server_tool_use web_search), ContentBlockDeltaEvent(index=1, InputJSONDelta partial_json {"query": "weather in London"}), ContentBlockStopEvent(index=1). 3. Collect final ToolCallBlock from stream_chat; observe tool_kwargs={'query': 'weather in London'} instead of {}, proving corruption.

Fixing Code Block

Edge Case Audit

This patch prevents corruption but does not capture server tool inputs; server-side tool blocks remain unrepresented in LlamaIndex streaming messages. Future support for ServerToolUseBlock should implement proper per-block index tracking rather than relying on reset. The reset is safe for normal sequential content blocks; concurrent streamed responses are per-generator and unaffected. If multi-block tool aggregation is added later, ensure stop/reset ordering is preserved. Rollback: remove the two added lines in each generator to restore previous behavior, but the corruption bug will reappear.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state