Repository navigation
fix(sdk-js): preserve AIMessage metadata in middleware - #6091
Merged
BenTaylorDev merged 4 commits intoJul 23, 2026
Merged
Conversation
JYbill
requested review from
jpr5,
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
July 21, 2026 13:17
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
BenTaylorDev
approved these changes
Jul 23, 2026
BenTaylorDev
left a comment
Contributor
There was a problem hiding this comment.
Approving. Reviewed adversarially against current main and the actual installed @langchain/[email protected]:
- The fix is mechanically correct where it counts. For v1 messages, langchain's AIMessage constructor re-derives
tool_callsfrom anytool_callblocks left incontent(ai.js:62-64) — so without the newusesV1ContentBlocksfilter, the intercepted frontend tool call would leak straight back intotool_calls. Theoutput_version === "v1"guard is the same condition langchain itself uses (ai.js:51), so there's no detection gap and non-v1 messages are correctly left untouched. - Complete: the only two metadata-dropping reconstruction sites (
middleware.ts:490/544) are both routed through the shared helper; the twoutils.tsconstructions synthesize fresh interrupt messages with no source metadata to preserve, correctly out of scope. - Clean scope, no drift, not superseded, and a thorough test covering metadata + content-block preservation through both interception and restoration.
CI note: sdk-js build + tests pass (middleware suite 47/47). The lone red on unit (20.x) is the unrelated "Verify packed Runtime managed Channels contract" packed-install gate, not attributable to this change (the PR doesn't touch runtime).
I bless the code with a glad heart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
AIMessagefields when frontend tool calls are intercepted inafterModeland restored inafterAgent, includingadditional_kwargs,response_metadata,usage_metadata,invalid_tool_calls,id, andname.tool_callsas the source of truth. For LangChain v1 content blocks, remove staletool_callandtool_call_chunkblocks before reconstructing the message.reasoning + backend/frontend tool calls -> afterModel -> afterAgentflow, including metadata preservation and v1 content block synchronization.Related PRs and Issues
Checklist