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

Streaming Tool Call Executed With Empty Args {} Due To SSE Fragmentation Of Tool Call Arguments

Streaming tool calls over SSE can fragment arguments; langchain-core parses the first empty args fragment as a valid empty tool call, causing Field required validation errors and tool execution failure.

highConfidence 85%LangChainVector StoresRetrieversAffected V1.2.14

Origin Analysis

langchain-core's AIMessageChunk.tool_calls property parses each tool_call_chunks entry independently using parse_partial_json. The first fragment with empty args ('') yields {} and is treated as a complete tool call before later argument fragments arrive.
1. Use langchain.agents.create_agent with ChatOpenAI streaming enabled and a tool that requires arguments (e.g., my_tool(url: str)). 2. Send a request that triggers a tool call. 3. Observe streamed AIMessageChunk events: first chunk has name='my_tool', args='', id='call_...'; subsequent chunks contain args='{' etc. 4. The agent executes the tool with empty args {}, causing pydantic validation error 'Field required'.

Fixing Code Block

Edge Case Audit

Monkey-patching an internal property is version-specific and may break in future langchain-core updates. Only use as a temporary hotfix. For production, upgrade to a version with the official fix or set streaming=False. Ensure index-based grouping does not merge distinct parallel tool calls with identical indexes (rare). Rollback: remove the patch and restart the process.

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