langchain · difficulty ◆◆
normalize_v1_streamed_tool_calls: Clean Streamed Tool Calls
Stream tool calls without duplicate invocations or None fields.
Streaming agents were silently dropping or duplicating tool calls. One core upgrade normalizes every chunk.
fully AI-generatedThis text is fully AI-generated and was published without human editorial review.$ pip install -U langchain-core>=1.4.6 langchain-openai>=1.2.1- langchain-core 1.4.6
- Release
- #35983
- PR
- All OpenAI users
- Impact
Normalize v1 streamed tool calls
What it does
normalize_v1_streamed_tool_calls is an internal langchain-core function that normalizes tool calls streamed from the OpenAI v1 API into LangChain’s canonical ToolCall format. A bug in the prior version caused malformed or duplicated tool call chunks when the model streamed incremental deltas, especially with function_call style mixed with the newer tool_calls format. The fix ensures chunks merge correctly regardless of streaming order or format variant.
Why it matters
If you build any LLM pipeline that uses OpenAI tool calling with streaming enabled (an agent loop, a code interpreter, a RAG-with-tools chain), this bug could cause silent failures: duplicate tool invocations, dropped arguments, or ToolCall objects with None fields. The fix is in langchain-core, so upgrading to >=1.4.6 resolves it automatically for all partner packages (OpenAI, Anthropic, etc.).
Example
$ Stream a tool call and collect resultsTool calls collected: 1
Result: content='Sunny in Berlin'astream_events surfaces the on_tool_end event with a clean, non-duplicated result.
Common flags
- --streaming
- Enable streaming tool-call output
- --v1-api
- OpenAI v1 API format normalization
History
Origin
Fixes landed in langchain-core==1.4.6 (published June 11, 2026), PR #35983.
Scope
Because normalization lives in core, the fix propagates to every partner integration that relies on canonical ToolCall output.
Under the hood
The merge problem
Streamed tool calls arrive as incremental deltas that must be merged in order. The old code mishandled interleaved function_call and tool_calls formats; the fix standardizes the merge so fields are never dropped or duplicated.
Fun facts
Pros & cons
pros
- + Fixes duplicate invocations
- + No dropped arguments
- + Propagates to all partner packages
cons
- − Requires core upgrade
- − Internal function, not a public API
Takeaways
- 1Upgrade langchain-core to >=1.4.6 for the fix.
- 2Stream tool calls with astream_events to observe clean on_tool_end output.
- 3Compare against core 1.4.4 to see the old malformed behavior.
archive entry — written and published by a scheduled job, never editorially reviewed. Kept for reference: out of the site’s search index, and no ads run here. the reviewed library →
