Repository navigation
fix(responses): backport Claude tool search replay to lts/1.108.x - #50472
mateo-berri wants to merge 17 commits into
Conversation
Claude tool search on /v1/responses now returns a tool_search_output after each tool_search_call, streamed and not, listing the tools the search loaded as the caller sent them A stateless follow-up sends the search back to Anthropic as the server_tool_use and tool_search_tool_result Claude produced, and the Anthropic request drops a replayed search whose loaded tools are no longer sent, so a changed tool list no longer answers 400 The guardrail write-back for SDK output items reads part text through a typed helper, so the new output item type adds no attribute errors (cherry picked from commit beedaab)
The streamed tool_search_output item was announced at the end of the stream with an output index reserved earlier, so output_item.added events arrived as 0, 2, 1 and the OpenAI SDK's stream helper raised IndexError. The item is now emitted when Claude's search result arrives. (cherry picked from commit e610512)
A tool name Anthropic cannot take gets rewritten on the request, so Claude's tool_search_tool_result named the rewritten tool. The response now maps those tool references back to the caller's names, streamed and not, and a replayed search result maps them forward again on the next turn. (cherry picked from commit 5d56e18)
Regenerates the lazy OpenAPI snapshot and the dashboard API types for the tool_search_output item the picks add to the Responses API output union
A follow-up sent to a route that cannot run tool search, a Claude model without it included, now leaves out the replayed search the way it did before, instead of sending Claude search blocks that model cannot take. The stateless gate and the stored-turn filter now use the same check that already decides whether the tool_search tool itself is kept A streamed tool_search_call now gets its output_item.done when Claude's search result arrives, so it finishes before its tool_search_output. Clients that build history from done events, like Codex, kept the output ahead of its call (cherry picked from commit 3e61760)
…'s own search tool A Claude model the cost map does not flag for tool search still runs it when the request carries Anthropic's own tool_search_tool_regex or bm25 tool, which is how turn 1 already decides to keep it. Both replay gates now follow that rule, so a stored follow-up on such a model keeps Claude's search as it did before, and a stateless one replays it (cherry picked from commit 24bc04e)
[Medium impact] The PR appears safe to merge, with no new actionable findings SummaryAdds Claude tool-search results and replay to the LTS Responses bridge
Reviews (8) · Last reviewed commit: "fix(responses): merge current LTS into C..." · Reviewed by Greptile |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
(cherry picked from commit 0274d84)
|
bugbot run |
|
bugbot run |
… prune only missing tools A replayed Claude tool search now reaches pre-call guardrails and the Purview DLP scan with its search arguments, a stale search drops only the tool references the follow-up no longer sends, and the stored previous_response_id path keeps the base gate for routes the cost map does not flag
|
bugbot run |
…when it still sends a search tool A store false follow-up that sent no search tool still got the search replayed, and Claude then said it called a tool it no longer had. Same change as fe560fc on the main branch
|
bugbot run |
… still sends a search tool A previous_response_id follow-up that sent no search tool still got the stored search, the same gap a store false follow-up had. The stale search pruning now logs the tools it leaves out at debug level. Same change as 0a748dd on the main branch.
|
bugbot run |
…all id The guardrail test reused toolu_01Weather, an id that streaming and bridge tests already put in the process-wide TOOL_CALLS_CACHE. When one of those ran first in the same worker, the guardrail write-back took its rebuild path and the test failed for a reason unrelated to the replayed search. (cherry picked from commit 6d49b25)
|
bugbot run |
…nd stored follow-ups A search-only assistant turn now gets its search result renamed to the sanitized tool names too, so the stale-tool trim no longer drops it. Stored follow-ups on Claude routes replay the search as base did, trimmed to the tools still sent, and Bedrock invoke sends the tool search beta whenever the history holds a search (cherry picked from commit 0a27b5b)
… a follow-up without a search tool (cherry picked from commit afa708b)
A chat history whose search result used the request's tool names (weather.get) got Anthropic's 400 when replayed on a proxy still on the old code, during a rolling deploy or a rollback. Chat completions now returns Claude's search result as main does, and the Responses bridge maps a rewritten name back to the request's tool when it builds tool_search_output. That also fills tool_search_output on Bedrock invoke streams, which carry no name map (cherry picked from commit 4249121)
The line keeps Claude's search in tool_calls, so the picked fixtures store it there, and the chat test file drops the duplicate and unrelated tests the conflict resolution brought in from main
Comments Outside DiffThese findings could not be posted inline.
|
|
bugbot run |
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6207d9e. Configure here.
| ] | ||
| if kept == blocks: | ||
| return message | ||
| return {**message, "content": kept} if kept else None |
There was a problem hiding this comment.
Dropped search leaves consecutive user turns
Medium Severity
When a replayed Claude search is the only content on an assistant turn and none of its loaded tools remain, without_stale_tool_search_results removes that whole assistant message. That runs after anthropic_messages_pt has already merged adjacent roles, so the wire history can become two user turns in a row, which Anthropic rejects.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 6207d9e. Configure here.
There was a problem hiding this comment.
Anthropic merges consecutive same-role turns, so two user turns are accepted. Main #50821 behaves identically and its test pins this shape, so LTS keeps parity
|
Superseded by #53007, which carries the same commits plus a merge of the current lts/1.108.x so it can land |
Pull request was closed


On the 1.108 LTS line, Claude's tool search through
/v1/responsesis lost on the next turn, and a follow-up without a tool the search loaded fails with Anthropic's 400This brings the same fix as #50821 to the line
Original
TLDR
Problem this solves:
tool_search_outputfor Claude's searchstore: falsefollow-ups drop Claude's searchHow it solves it:
tool_search_outputfrom the request's tools and their names, streamed and notstore: falseturns that still send a search tooltool_search_call's arguments to guardrails and Purview DLPIntentional product change: a replayed search keeps only the loaded tools a follow-up still sends, where Anthropic answered 400, and is left out when none remain, on
/v1/chat/completionstooBackport checklist
tool_callstool_search_output. Two picks conflicted intransformation.pyand keep the line's names, since it has no native compaction. 0a27b5b conflicted in the Responsestransformation.pyand keeps the line's stored-message check. 4249121 conflicted inhandler.py, which goes back to its base version, as main's change does. 6e11cc5 stores Claude's search intool_callsin the picked tests, as the line does, and drops tests the conflict brought in from mainenterprise/orlitellm-proxy-extras/change, so no package bumpRelevant issues
Part of #50104, the search record lost on later turns
User Flow
Before: a developer using OpenAI tool search on Claude through
/v1/responsesloses the search on later turns, and a changed tool list failstoolsholding{"type": "tool_search"}plus deferredget_weatherandget_local_time, asking for the weather in Paristool_search_callthenfunction_call get_weather, but notool_search_outputnaming the loaded tools, streamed or not"store": false, replaying every turn 1 item plus afunction_call_output, and Claude says it ran no tool searchprevious_response_idand without a tool the search loaded, and get HTTP 400 "Tool reference '' not found in available tools"After: turn 1 returns the search result, Claude remembers its search on turn 2, and a changed tool list still answers 200
tool_search_outputlisting the loaded tools, streamed or not"store": falseturn 2, and Claude lists the tool search it ran and what it foundprevious_response_idturn 2 and get HTTP 200, and Claude's search keeps every loaded tool still sentPre-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 moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Each leg ran the curl scripts on Anthropic
claude-sonnet-5-5and Vertex AI, and the reporter's Agents SDK client on Bedrock Sonnet 5.5 and Opus 5, against one proxy with Postgres and one worker, since--reloadignores--num_workerson this lineProxy command, config.yaml, and env var names
The proxy reads
ANTHROPIC_API_KEY,GOOGLE_APPLICATION_CREDENTIALS(a service account key file),VERTEXAI_PROJECT,LITELLM_MASTER_KEY,DATABASE_URL(a fresh Postgres database per leg),LITELLM_LOCAL_MODEL_COST_MAP=True, andLITELLM_PRISMA_COMMAND_TIMEOUT=600. Bedrock calls use the default AWS profile, an SSO role with Bedrock inference, and no AWS env vars. The scripts readINTEGRATION_PROXY_URLandINTEGRATION_MASTER_KEY.agents_qa.pyruns onopenai-agents==0.24.0qa.sh (cases 1 to 5), qa-bm25.sh (cases 6 to 8), qa-nosearch.sh (cases 9 and 10), and agents_qa.py
The Vertex AI runs use
qa.shandqa-nosearch.shwithvertex-claude-sonnet-5-5in place ofclaude-sonnet-5-5tool_search_outputtool_search_outputat index 1, in orderstore: falseturn 2get_weatheror every tool goneget_weathergonetool_search_outputstore: falseturn 2tool_search_tool_bm25get_local_timegoneget_weatherweather_getweather.getstore: falseturn 2tool_namespacetoolsBefore (831a14c)
Raw, unedited output of each script above, agents_qa.py once per model
qa.sh
qa-bm25.sh
qa-nosearch.sh
agents_qa.py
agents_qa.py on Opus 5
qa.sh on Vertex AI
qa-nosearch.sh on Vertex AI
After (0997304)
Raw, unedited output of each script above, agents_qa.py once per model
qa.sh
qa-bm25.sh
qa-nosearch.sh
agents_qa.py
agents_qa.py on Opus 5
qa.sh on Vertex AI
qa-nosearch.sh on Vertex AI
Last updated: 6e11cc5. QA ran on 0997304. Changes since QA: three picks from main and a test fit. Proof remains valid because the picks touch only renamed tools, stored turns without a search tool, and Bedrock's beta. Verification: the smoke rows
Smoke, 831a14c and 6e11cc5
Scripts and raw output are in this gist
Raw output of case 10 on Bedrock Sonnet 4.5 and case 13 on Anthropic
Before (831a14c), qa-nosearch.sh on bedrock-claude-sonnet-4-5
After (6e11cc5), qa-nosearch.sh on bedrock-claude-sonnet-4-5
Before (831a14c), qa-renamed-responses.sh
After (6e11cc5), qa-renamed-responses.sh
Type
🐛 Bug Fix
Caveats (if any)
Medium
tool_namespacetools workLow
store: falsefollow-ups still drop Claude's search and stored ones replay it, as on base, since replaying made Claude claim a tool it lacked and dropping breaks stored follow-ups that workweather_get, notweather.get, as on basetool_referenceto a dropped tool still gets Anthropic's 400, as on baseFinal Attestation
Bugbot summary