fix(ai): round-trip Anthropic tool_search_tool_result blocks - #48485
Open
lu-zero wants to merge 1 commit into
Open
fix(ai): round-trip Anthropic tool_search_tool_result blocks#48485lu-zero wants to merge 1 commit into
lu-zero wants to merge 1 commit into
Conversation
The native Anthropic protocol dropped `tool_search_tool_result` content blocks at stream-decode time and refused to lower them back onto the wire. Both gaps keyed off the same hardcoded three-entry server-tool list, which predates Anthropic's tool-search server tools. A tool search puts signed `thinking`, `server_tool_use`, `tool_search_tool_result` and `tool_use` in a single assistant turn. Dropping the result block means the replayed turn no longer matches the original response, and Anthropic rejects the signed thinking block: "`thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified." Also records `server_tool_use` id -> name in the parser state, because `tool_search_tool_bm25` and `tool_search_tool_regex` both report through one `tool_search_tool_result` block type and the result block carries no name of its own. Port of the same fix made against `dev` in anomalyco#48466, where the file lives at `packages/llm/src/protocols/anthropic-messages.ts`. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Found one related PR:
This is not a duplicate of the current PR (#48485). According to the PR description, #48466 is the companion fix against the |
3 tasks
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.
Issue for this PR
Fixes #45527.
Scope note: this is the protocol half only — the wire round-trip for Anthropic tool-search blocks. It does not add the config seam (
defer_loadingpassthrough, declaring a provider-defined tool) that #45527 also asks for; happy to keep that issue open if maintainers prefer.Targets
beta. The same fix againstdevis #48466, where the file lives atpackages/llm/src/protocols/anthropic-messages.ts;betahas the identical gap atpackages/ai/src/protocols/anthropic-messages.ts.Type of change
What does this PR do?
The native Anthropic protocol dropped
tool_search_tool_resultcontent blocks at stream-decode time and refused to lower them back onto the wire. Both gaps keyed off the same hardcoded three-entry server-tool list, which predates Anthropic's tool-search server tools.A tool search puts signed
thinking,server_tool_use,tool_search_tool_resultandtool_usein one assistant turn. Dropping the result block means the replayed turn no longer matches the original response, and Anthropic rejects the signed thinking block:One unhandled block type turns into a hard 400 for the rest of the conversation.
ai/src/protocols/anthropic-messages.tstool_search_tool_result; recordserver_tool_useid → name in parser state, becausetool_search_tool_bm25andtool_search_tool_regexboth report through one result block type that carries no name of its own.ai/test/provider/anthropic-messages.test.tsHow did you verify your code works?
bun test test/provider/anthropic-messages.test.tstool-resultevent is absent entirelybun turbo typecheckScreenshots / recordings
N/A — provider wire-format change.
Checklist
🤖 Generated with Claude Code