fix(llm): round-trip Anthropic tool_search_tool_result blocks - #48466
Open
lu-zero wants to merge 1 commit into
Open
fix(llm): round-trip Anthropic tool_search_tool_result blocks#48466lu-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.
3 tasks
Author
|
Ported to |
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 lands the protocol half — 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.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 unknown block type turns into a hard 400 for the rest of the conversation.
llm/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.llm/test/provider/anthropic-messages.test.tsHow did you verify your code works?
bun test test/provider/anthropic-messages.test.tsbun turbo typecheckScreenshots / recordings
N/A — provider wire-format change.
Checklist
🤖 Generated with Claude Code