{{ message }}
Repository navigation
fix: ensure tool_result messages have matching tool_use after token trimming (#2450) - #3820
Merged
Merged
Conversation
jpr5
requested review from
ataibarkai,
mme,
ranst91 and
tylerslaton
as code owners
April 12, 2026 22:03
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📣 Social Copy GeneratorGenerate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.
|
jpr5
force-pushed
the
fix/token-trimming-tool-pairing-2450
branch
from
April 14, 2026 23:23
03d4c9d to
78c65a8
Compare
AlemTuzlak
approved these changes
Apr 16, 2026
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
…rimming (CopilotKit#2450) (CopilotKit#3820) ## Summary Fixes CopilotKit#2450 Token trimming in the Anthropic adapter could remove assistant messages containing `tool_use` blocks while keeping the corresponding user messages with `tool_result` blocks. Anthropic's API rejects orphaned `tool_result` messages. This adds a post-processing step that removes orphaned `tool_result` blocks after trimming. ## Test plan - [ ] Verify token trimming preserves tool_use/tool_result pairing - [ ] Verify orphaned tool_result blocks are removed - [ ] Verify messages with mixed content (tool_result + text) retain non-orphaned content
This branch was successfully deployed
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.

Summary
Fixes #2450
Token trimming in the Anthropic adapter could remove assistant messages containing
tool_useblocks while keeping the corresponding user messages withtool_resultblocks. Anthropic's API rejects orphanedtool_resultmessages. This adds a post-processing step that removes orphanedtool_resultblocks after trimming.Test plan