Repository navigation
fix(responses): round-trip an Anthropic server tool search through the Responses bridge - #50107
Closed
homenshum-cheiron wants to merge 3 commits into
Closed
homenshum-cheiron wants to merge 3 commits into
homenshum-cheiron wants to merge 3 commits into
Conversation
…e Responses bridge Bug: Claude runs a tool search on the server. Its reply holds a server_tool_use block, a tool_search_tool_result block with tool_references, and the tool_use of the tool it found. The bridge returned only a tool_search_call item and dropped the result. On the next turn the client replays its history, the bridge dropped the tool_search_call too, and Claude received only the tool_use of a deferred tool with no record of the search that loaded it. What the model did next varied: in one live run it searched again on 3 of 4 later calls, in another it did not. Fix: - Reply side: next to each server tool_search_call, return a tool_search_output item (execution "server") whose tools are the request's tool definitions named in the tool_references. Namespaced tools keep their namespace and list only the named members. Streaming emits the same item as output_item.added and output_item.done events at the next dense output index. - Request side: a replayed server tool_search_call that a tool_search_output answers becomes an assistant tool call with the search result in provider_specific_fields.tool_results. The Anthropic prompt factory already rebuilds server_tool_use, tool_search_tool_result and tool_use from that shape, in order, in one assistant turn. - Unanswered search calls, client-executed searches and non-Anthropic routes keep today's behaviour: the call is dropped and nothing reaches the provider. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ool search tool The replay rebuilt server_tool_use and tool_search_tool_result for every Anthropic route. A turn can hold a server search in its history while the request sends no tool search tool: the caller left it out (for example a handoff to an agent without tool search), or the bridge dropped it because the model cannot run tool search. That tool is what adds the tool-search beta, so those turns sent the search blocks with no tool and no beta, where main sent the tool_use alone. The replay now needs an outbound Anthropic tool search tool as well as an Anthropic route. Otherwise the search is dropped as before. The route check still runs only when a replayed search is present. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…story too The previous commit kept a replayed server search only beside an outbound tool search tool, but only for the request's own input. History rebuilt from previous_response_id is turned into messages later, in the session handler, and kept every replayed server search on an Anthropic route. A later turn without the tool (a handoff to an agent without tool search) still sent server_tool_use and tool_search_tool_result with no tool and no beta. Stored history now follows the same rule: without an outbound Anthropic tool search tool, without_replayed_server_searches drops the stored search and keeps the tool_use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 4, 2026
7 tasks done
Contributor
|
Closing this as superseded by #50821, which merged the Claude tool search replay for Responses follow-up turns. Thanks for the report and fix |
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.
Handwritten 1-3 sentence description
<make-me-human-readable>When Claude searches for tools on the server during an agent run, the Responses endpoint now returns the search result and sends the full search record back to Claude on the next turn. Before, the record was dropped, so on later turns Claude saw a call to a tool with no record of the search that loaded it.
</make-me-human-readable>Details
TLDR
Problem this solves:
tool_usewith no search recordHow it solves it:
tool_search_outputitem naming the found toolsserver_tool_use,tool_search_tool_result,tool_usein orderprevious_response_idhistory follows the same ruleUser Flow
Before: on turn 2 of an Agents SDK chat on Claude, the search record is gone
{"type": "tool_search"}, modelclaude-opus-5(Bedrock Invoke)tool_search_calland afunction_call, but no item with the search resulttool_usealone, with noserver_tool_useortool_search_tool_resultAfter: turn 2 reaches Claude with the whole search
tool_search_call,tool_search_output(the found tool's definition) andfunction_callserver_tool_use,tool_search_tool_resultandtool_use, in that order, in one assistant turnRelevant issues
Part of #50104 (item 2). Related: #46444 fixed the other direction (GPT tool search through the chat bridge); #49132 checks
tool_search_outputitems againstallowed_tools, which now applies to the items this PR returns.Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Shared setup: Agents SDK 0.24.0,
OpenAIResponsesModelpointed at the proxy's/v1/responses, 6 deferred function tools plusToolSearchTool(), two user turns. Proxy config as in #50104, with a callback that records each request body sent to Bedrock.Before (fd4cef2 plus fixes for items 1 and 3 of #50104, without this PR)
tool_usealone: the assistant turns are[tool_use]and[tool_use, text], with noserver_tool_useortool_search_tool_result. This step ran against a local Bedrock stubAfter (tested on a build of this PR plus the other two PRs for #50104)
server_tool_use,tool_search_tool_resultandtool_usein that order in the assistant turnFocused checks on this PR's tip:
test_litellm_completion_responses.py:test_server_tool_search_result_becomes_a_tool_search_output_item,test_tool_search_output_holds_only_the_tools_the_search_named,test_tool_search_call_without_a_search_result_gets_no_output_item,test_replayed_server_tool_search_reaches_claude_before_the_tool_use,test_server_tool_search_is_not_replayed_to_a_provider_that_cannot_run_it,test_server_tool_search_call_without_its_output_is_not_replayed,test_server_tool_search_is_not_replayed_without_a_tool_search_tool[request_without_tool_search|model_without_tool_search].test_streaming_iterator_transformation.py:test_anthropic_server_tool_search_result_streams_as_tool_search_output_item(sync and async).test_anthropic_responses_bridge.py:test_previous_response_id_replays_a_stored_server_search_only_beside_a_tool_search_tool[request_without_tool_search|request_with_tool_search].test_tool_search_items_are_not_replayed_to_chat_messages, which asserted the drop.uv run pytest tests/unit/responses/ tests/unit/llms/bedrock/messages/: 2158 passed. The only failures aretest_reasoning_effort_grid_wire_shapes[*-vertex-ai](needs the Google Cloud SDK) andtest_every_openai_sdk_response_error_code_has_explicit_status_mapping; both fail the same way onmain.Type
🐛 Bug Fix
Caveats (if any)
Medium
chat.completionresponse (aMessageobject) skips the new rulemainLow
tool_search_outputafter thefunction_callcall_id, so both orders replay the same waytool_search_tool_regex, like a hosted web search replaymainFinal Attestation
🤖 Generated with Claude Code