langchain · difficulty ◆◆◆
normalize_v1_streamed_tool_calls: The Reliable Stream Fix
Downstream consumers get well-formed ToolCall objects, every time.
A streamed tool call should be one well-formed ToolCall, not a pile of fragments. This fix guarantees it.
$ pip install -U langchain-openai langchain-coreWhat it does
When you use LangChain’s OpenAI integration with tool calling in streaming mode, the model can emit tool call chunks in a non-deterministic order or with inconsistent formatting. The normalize_v1_streamed_tool_calls fix standardizes how these streamed events are normalized, ensuring tool arguments are correctly reconstructed even when the model emits partial or reordered chunks. Concretely, it patches the streaming path so AIMessageChunk.tool_calls is always a consistent list of ToolCall objects with the correct name, args, and id fields.
Why it matters
Streaming tool calls are critical in real-time agentic pipelines, such as a customer-service bot that streams a tool use while the user is still watching. If streamed tool calls are malformed or duplicated, downstream components that consume tool_calls directly (like a ReAct agent or a tool-executing loop) can crash or silently skip tool execution. This fix eliminates the most common source of streaming tool-call bugs in LangChain’s OpenAI integration.
Example
$ Accumulate streamed tool callsReceived tool_call chunk: ToolCall(name='get_weather', args='{"city": "Tokyo"}', id='...')
Total tool calls received: 1Multiple partial chunks accumulate into one non-duplicated top-level ToolCall after the fix.
Common flags
- AIMessageChunk.tool_calls
- Normalized list of ToolCall objects on streaming chunks
- PydanticStructurableMixin
- Enables Pydantic models as tool schemas, benefiting from normalization
History
Origin
Released in langchain-openai 1.3.1 and langchain-core 1.4.7 (2026-06-13), PR #35983, covered in the June 18 tutorial.
Same-day context
langchain==1.3.9 bundled anthropic 1.4.6 and an allowed_prefixes fix for file search; core 1.4.7 carried the Pydantic v1 tools fix.
Fun facts
Pros & cons
pros
- + No duplicate top-level tool calls
- + Well-formed name/args/id
- + Protects real-time agents
cons
- − Requires both packages updated
- − Streaming accumulation logic still needed
Takeaways
- 1Upgrade langchain-openai and langchain-core together.
- 2Inspect AIMessageChunk.tool_calls while streaming to see normalized ToolCall objects.
- 3Your tool-executing loops stay reliable in real-time streaming agents.