Repository navigation
fix: anthropic tool call issues #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
35652a0
fix: anthropic tool call issues
jherr 9cd7717
fixing pnpm lock
jherr 6842032
ci: apply automated fixes
autofix-ci[bot] 4ccfe30
reworking model to uimessage conversions
jherr f74105d
simplifying the message conversion handling
jherr a2002d9
merging in auto-fixes
jherr 713b661
ci: apply automated fixes
autofix-ci[bot] 87ede43
more small fixups
jherr f82a198
simplifying the message conversion handling
jherr 96fd5d3
addings docs and tests
jherr 65892f6
small test fixups
jherr 61f2ccd
last fixups
jherr 28482da
ci: apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| "@tanstack/ai-anthropic": patch | ||
| --- | ||
|
|
||
| fix(ai-anthropic): fix multi-turn conversations failing after tool calls | ||
|
|
||
| - Fix consecutive user-role messages violating Anthropic's alternating role requirement by merging them in `formatMessages` | ||
| - Deduplicate `tool_result` blocks with the same `tool_use_id` | ||
| - Filter out empty assistant messages from conversation history | ||
| - Suppress duplicate `RUN_FINISHED` event from `message_stop` when `message_delta` already emitted one | ||
| - Fix `TEXT_MESSAGE_END` incorrectly emitting for `tool_use` content blocks | ||
| - Add Claude Opus 4.6 model support with adaptive thinking and effort parameter |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TEXT_MESSAGE_ENDmay emit spuriously for non-text, non-tool_use block types (e.g.,thinking).The
elsebranch fires for anycontent_block_stopwherecurrentBlockType !== 'tool_use', which includesthinkingblocks. If a text block preceded the thinking block, this would emit a spuriousTEXT_MESSAGE_ENDwhen the thinking block stops β becausehasEmittedTextMessageStartandaccumulatedContentare both still truthy.In practice Anthropic puts thinking blocks before text blocks, so this isn't currently triggered. But if the response ordering changes or new block types are added, it could surface.
Suggested guard
} else { - // Emit TEXT_MESSAGE_END only for text blocks (not tool_use blocks) - if (hasEmittedTextMessageStart && accumulatedContent) { + // Emit TEXT_MESSAGE_END only when a text block ends + if ( + currentBlockType === 'text' && + hasEmittedTextMessageStart && + accumulatedContent + ) { yield { type: 'TEXT_MESSAGE_END', messageId, model, timestamp, } } }π€ Prompt for AI Agents