Skip to content

fix(langgraph-api): recover tool_call args from cumulative-args providers at end of call - #2697

Open
Serhiy Bzhezytskyy (serhiy-bzhezytskyy) wants to merge 2 commits into
langchain-ai:mainfrom
serhiy-bzhezytskyy:fix/cumulative-tool-args-recovery
Open

fix(langgraph-api): recover tool_call args from cumulative-args providers at end of call#2697
Serhiy Bzhezytskyy (serhiy-bzhezytskyy) wants to merge 2 commits into
langchain-ai:mainfrom
serhiy-bzhezytskyy:fix/cumulative-tool-args-recovery

Conversation

@serhiy-bzhezytskyy

Copy link
Copy Markdown

Summary

Implements the end-of-call recovery proposed in #2570 (comment) for providers that re-send the cumulative tool_call args string per chunk instead of a delta: the concatenation never parses, and messages/partial ends with Malformed args. / invalid_tool_calls even though the model's own final message is clean.

Changes

  • src/stream.mts — keep concatenating during the stream; when the model run ends and an args string does not parse, and its chunks form a growing prefix chain whose last chunk parses on its own, a final messages/partial frame carries that last chunk instead. Anything whose concatenation parses is untouched; mid-stream frames are unchanged.

Test plan

  • Seven new tests in tests/stream.test.mts: cumulative snapshots recovered; compliant deltas untouched, including chunks that happen to chain (self-similar args split at the seam); broken output without a chain preserved; the design trade pinned — already-invalid output that chains is read as its only parsing interpretation ({{"a":1} split as { + {"a":1}); a real compiled graph confirms the production on_chat_model_end shape fires the recovery and the rebuilt message carries parsed tool_calls; two parallel tool calls stay isolated
  • The distinguishability matrix behind the design is in the linked comment: per-chunk detection is unsound (a compliant self-similar stream is prefix-identical to cumulative snapshots), and stop-once-valid cannot recover a stream that never passes through a valid state
  • Changeset for @langchain/langgraph-api; package suite 108 passed (3 file-load failures identical on clean main)

Related

…ders at end of call

A provider that re-sends the cumulative args string per chunk instead
of a delta (langchain-ai#2570) leaves messages/partial with a concatenation that
never parses. Keep concatenating during the stream; once the model run
ends, an args string that does not parse, whose chunks form a growing
prefix chain and whose last chunk parses on its own, is replaced by
that last chunk in a final messages/partial frame.

Anything whose concatenation parses is untouched, so compliant streams
never change — including chunks that happen to chain. Output that was
already invalid and chains may be read as its only parsing
interpretation instead of surfacing as Malformed args; that trade is
pinned by a dedicated test.
@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b8f0b5c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@langchain/langgraph-api Patch
@langchain/langgraph-cli Patch
@langchain/langgraph-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…isfy oxfmt

The build tsc rejects tool_call_chunks on BaseMessageChunk — the
recording loop now runs only for AIMessageChunk, matching the guard
the recovery itself already had. Formatting aligned with oxfmt.
@pkg-pr-new

pkg-pr-new Bot commented Aug 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

@langchain/langgraph-checkpoint

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint@2697

@langchain/langgraph-checkpoint-mongodb

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-mongodb@2697

@langchain/langgraph-checkpoint-postgres

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-postgres@2697

@langchain/langgraph-checkpoint-redis

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-redis@2697

@langchain/langgraph-checkpoint-sqlite

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-sqlite@2697

@langchain/langgraph-checkpoint-validation

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-validation@2697

create-langgraph

npm i https://pkg.pr.new/langchain-ai/langgraphjs/create-langgraph@2697

@langchain/langgraph-api

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-api@2697

@langchain/langgraph-cli

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-cli@2697

@langchain/langgraph

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph@2697

@langchain/langgraph-cua

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-cua@2697

@langchain/langgraph-supervisor

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-supervisor@2697

@langchain/langgraph-swarm

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-swarm@2697

@langchain/langgraph-ui

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-ui@2697

@langchain/langgraph-sdk

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-sdk@2697

@langchain/angular

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/angular@2697

@langchain/react

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/react@2697

@langchain/svelte

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/svelte@2697

@langchain/vue

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/vue@2697

commit: b8f0b5c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant