Repository navigation
fix(responses bridge): round-trip tool_search_call and tool_search_output items between turns - #46444
Conversation
…he Responses API Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… so Final stays valid Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…tput items between turns Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ields through typed helpers Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@litereview code-review |
|
bugbot run |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. Completed · Some checks not run. No correctness findings. I traced the new Checks and execution details
Manual E2E evidence (PR description). The author made real OpenAI calls through 2-worker proxies. The before runs used merge base
Integration tests. The PR adds proxy wire contracts under
View review · Reviewed |
…ge or tool call Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@litereview code-review |
|
bugbot run |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@litereview code-review |
|
bugbot run |
PR overviewThe PR updates the Responses bridge to round-trip Two issues have been addressed, and one remains open. An authenticated caller can supply replayed tool-search arguments that bypass pre-call content-filter BLOCK/MASK rules and are forwarded unchanged to the provider, allowing protected values to leave despite the configured guardrail. Open issues (1)
Fixed/addressed: 2 · PR risk: 6/10 |
…eplay adds no empty message Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@litereview code-review |
|
bugbot run |
…, count replayed tools in the allowlist, keep namespace off guardrails
|
@litereview code-review |
|
bugbot run |
…tool_search to Responses Under drop_params, defer_loading is dropped when no tool_search tool is sent, so the 400 it would cause upstream goes away as before. A non-bool value answers 400 without drop_params and is dropped with it. A null tool-level value falls back to the nested function value. A request carrying a tool_search tool now bridges to Responses on OpenAI and Azure endpoints even with reasoning_effort none, since chat completions rejects the tool_search type.
…ount replayed tools in tool policy Store the ordered output prefix through the last tool search item, reasoning included, so a second reasoning item no longer makes OpenAI reject the replay. The shared chat-to-Responses converter now replays tool search items and namespace only when the bridge opts in, so Noma, the complexity router and guardrail payloads keep their shape. The tool policy guardrail and the allowlist count replayed tools only when the request can send them.
[Medium impact] Adds tool search round-trip support to the responses bridge. The PR appears safe to merge, with a non-blocking gap in preserving reasoning for text-only streamed replies. Findings
SummaryThe PR keeps tool searches and each call's
Acknowledged by
Reviews (1) · Last reviewed commit: "fix(responses bridge): forward defer_loa..." · Reviewed by Greptile |
| typed_chunks: Final = cast(Sequence[object], chunks) # cast-ok: chunks are untyped upstream | ||
| reasoning_items: Final = tuple(chain.from_iterable(_chunk_reasoning_items(chunk) for chunk in typed_chunks)) | ||
| if reasoning_items: | ||
| response["choices"][0]["message"]["reasoning_items"] = list(reasoning_items) |
There was a problem hiding this comment.
Text replies lose saved reasoning
When a streamed Responses reply has encrypted reasoning but no tool calls, search items, or reasoning summary text, stream_chunk_builder returns through its text-only shortcut before this copy runs. _NON_TEXT_DELTA_FIELDS does not include reasoning_items, so the rebuilt message loses them and the next request cannot reuse that reasoning.
Add reasoning_items to the shortcut's field check and cover a text-only reply.
There was a problem hiding this comment.
Fixed in ae18b82. reasoning_items now counts as a non-text delta field, so text-only streamed replies keep it, covered by a unit test
…y, streamed and not
|
Automatic reviews are disabled for this repository. |
…d keep streamed reasoning_items on text replies Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…' into litellm_bridge_tool_search_items
|
@litereview code-review |
|
bugbot run |
…earch_items Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # tests/integration/providers/test_responses_bridge_tool_search_chaos.py # tests/integration/providers/test_responses_bridge_tool_search_wire.py
…ecuted tool_search Forwarding defer_loading beside a client tool_search made GPT stop with a search call the chat client has to answer by hand, so a plain question that used to get tool calls got none. Keep main's behavior of dropping it there.
|
@litereview code-review |
|
bugbot run |
|
@litereview code-review |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 87db61a. Configure here.
…and #46444 landed Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
TLDR
Problem this solves:
tool_searchchat turns lose the search and each call'snamespace, so GPT searches againtool_searchanswers 500, or an empty streamHow it solves it:
provider_specific_fields.tool_search_itemsnamespacelitellm.run_tool_loopkeeps the search andnamespacebetween roundsDecisions and their alternatives:
tool_search_itemsends at the last search item, which OpenAI wants right after its reasoningtool_searchtool_search, since gpt-5-mini answers 400 otherwisefinish_reason: "stop", since"tool_calls"with no calls can break clientsdefer_loadingstill drops beside a clienttool_search, as onmain, so a plain question still gets tool callsreasoning_contentstays for Fireworks, Groq and Together, since Fireworks replays itUser Flow
Before: on turn 2 of an SDK tool chat, GPT searches again
completion(model="openai/responses/gpt-5.5")with{"type": "tool_search"}and deferredget_weatherandget_local_timeAfter: turn 2 keeps the search, so GPT calls the tools right away
provider_specific_fields.tool_search_itemsWith a client-executed
tool_search, turn 1 answered 500 or an empty stream. Now it returns GPT's search for the client to answerLinear ticket
Resolves LIT-9578
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 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
Real OpenAI calls through 2-worker proxies. Before ran at the merge base 314f179 on
main, after at 87db61arun_tool_loop, round 2get_weathercalledget_weathercalledrun_shell, allowlisted keytool_searchinextra_body.toolstool_searchtool_searchRevert recheck at 87db61a (912096e)
Real OpenAI
gpt-5.5through 2-worker proxies started with--detailed_debug, before at f7e7491 (workers 3536/3537) and after at 87db61a (workers 3593/3594), curl on/v1/chat/completions. The upstream column is read from the outboundapi.openai.com/v1/responsesbody in the proxy debug logdefer_loadingupstream before / aftertool_searchplus deferredget_weather,reasoning_effort: "none", 3 runstool_search_calltool_search_calltool_search_callin the streamtool_search_callin the streamtool_searchplus deferredget_weatherget_weathercalledget_weathercalledtool_searchget_weathercalledget_weathercalledIn the replay, turn 1 ran on pid 3594 and returned the
tool_search_call. Turn 2 replayed it with thetool_search_outputon pid 3593 and gotget_weather({"city":"Paris"}). Turn 3 sent the tool result on pid 3594 and got "The weather in Paris is currently 18°C". The other worker was paused with SIGSTOP on each turn so the request could only land where shown. The tool description says "Always call this first", so the model picked the client search on turn 1 on both commits| Tool policy blocks
run_shell| 200, twice | 400, twice || Client search replay, admin key | 500 |
run_shellcalled || Tool permission, block mode | 500 | 400 |
| Tool permission, rewrite mode | 500 | 200, no
run_shellcall || Turn 2 to strict providers | 200 | 200 |
Headline case, SDK non-streaming, run 1
Scripts and configs
Each SDK mode runs 3 times and each Router mode once. SDK, Router and proxy cases run at
reasoning_effort: "high", and the client search and strict-provider cases at"none".leg.sh <tree> <label> <qa dir>boots a 2-worker proxy on a random free port with its own Postgres database, runstwo_turns.pyandproxy_cases.sh, then drops the database. The security leg is the same script withconfig_sec.yamlandsecurity_cases.sh, and no SDK runs. The client search leg runsclient_cases.shagainst a proxy booted fromconfig_client.yamlleg.shtwo_turns.py <tree> <nostream|stream> <runs> <sdk|router>proxy_cases.sh <url> <master key> <out dir>client_cases.sh <url> <master key> <out dir>security_cases.sh <url> <master key> <out dir>tool_loop_case.py <tree>config.yamlconfig_client.yamlconfig_sec.yamlBefore (314f179)
SDK and Router, every run
The steps are in the after leg. Turn 1
tool_search_itemswas[]on every runProxy, `/v1/chat/completions`, steps and output
The steps are in the after leg
Proxy, client-executed `tool_search`, steps and output
The steps are in the after leg
Proxy, tool permission and `extra_body.tools`, steps and output
The steps are in the after leg
`litellm.run_tool_loop`, Paris then Tokyo
After (87db61a)
SDK and Router, every run
Each run prints the lines that change between the legs.
streamruns rebuild each turn withlitellm.stream_chunk_builder, and Router runs callRouter.completionwithmodel="gpt-5.5"Proxy, `/v1/chat/completions`, steps and output
POST /v1/chat/completionswith{"model":"gpt-5.5","reasoning_effort":"high","tools":[tool_search, 3 deferred tools],"messages":[Paris and Berlin question]}"stream": true, printing each SSE chunk that has a tool call, tool search items, or a finish reasonjq(content, tool calls with theirprovider_specific_fields,reasoning_items,provider_specific_fields), sent back streamed with the tool results and the Tokyo questionPOST /key/generatewith{"metadata":{"allowed_tools":["get_weather","get_local_time","get_air_quality"]}}tool_search_itemshold atool_search_outputthat loads arun_shellfunction"model":"gpt-5-mini"and plain function tools instead oftool_searchPOST /v1/tool/policywith{"tool_name":"run_shell","input_policy":"blocked"}, then P3a's body twice with the admin keyProxy, client-executed `tool_search`, steps and output
A third 2-worker proxy per leg with
gpt-5.5(openai/gpt-5.5). C1 and C2 set"reasoning_effort":"none"andtoolsto{"type":"tool_search","execution":"client",...}plus a deferredget_weatherPOST /v1/chat/completionsasking GPT to search for weather tools first, then get the weather in Paristool_search_outputthat answers GPT's search and loadsget_weather, added to itstool_search_items"stream": true, the turn 2 message rebuilt from the turn 1 chunks withjq"reasoning_effort":"low", a clienttool_searchplus deferredget_weatherandget_local_time, and a plain question about the weather and local time in ParisProxy, tool permission and `extra_body.tools`, steps and output
A second proxy per leg, booted from
config_sec.yamlwith twotool_permissionguardrails that deny^run_shell$, one in block mode and one in rewrite mode, both off by defaultrun_shell, with a clienttool_searchtool and deferredget_weatherintools, then asks to run it"guardrails":["deny-shell-block"]"guardrails":["deny-shell-rewrite"]POST /key/generatewith{"metadata":{"allowed_tools":["get_weather"]}}tool_searchand deferredget_weathermoved toextra_body.toolstool_search, sent togpt-5.5-search, whose deploymentlitellm_params.toolsadds it`litellm.run_tool_loop`, Paris then Tokyo
Raw proxy responses, long strings cut at 40 characters
P1 turn 1,
.choices[0].message.provider_specific_fields, which the client sends back unchanged{ "tool_search_items": [ { "id": "rs_0e01ad173e7907d7006ad0538a1e6887d2a1a...", "summary": [], "type": "reasoning", "content": [], "encrypted_content": "gAAAAABq0FOLDJLUn4dppguX-kSCq6CPJ_3JfcXN..." }, { "id": "tsc_0e01ad173e7907d7006ad0538ac22887d289...", "arguments": { "paths": [ "get_weather", "get_local_time" ] }, "execution": "server", "status": "completed", "type": "tool_search_call" }, { "id": "tso_0e01ad173e7907d7006ad0538aecfc87d280...", "execution": "server", "status": "completed", "tools": [ { "name": "get_weather", "parameters": { "type": "object", "properties": { "city": { "type": "string" } }, "required": [ "city" ] }, "strict": false, "type": "function", "defer_loading": true, "description": "Get the current weather for a city", "output_schema": null }, { "name": "get_local_time", "parameters": { "type": "object", "properties": { "city": { "type": "string" } }, "required": [ "city" ] }, "strict": false, "type": "function", "defer_loading": true, "description": "Get the current local time in a city", "output_schema": null } ], "type": "tool_search_output" } ] }C1 turn 1,
.choices[0], whosetool_search_itemsthe client answers{ "finish_reason": "stop", "index": 0, "message": { "role": "assistant", "provider_specific_fields": { "tool_search_items": [ { "id": "tsc_082d2a013dcbd8c3006ad0529c949087d2b7...", "arguments": { "query": "weather" }, "call_id": "call_RicT4FbbVrA8tdl1ZFOYRaJE", "execution": "client", "status": "completed", "type": "tool_search_call" } ] }, "content": null } }Turn 2 sent to Groq, Fireworks and Mistral, steps and output
A 2-worker proxy with
gpt-5.6-bridge(openai/responses/gpt-5.6),fireworks-oss,groq-oss,mistral-medium, andgpt-5.6-bridge-broken(bad key) falling back tofireworks-oss. Turn 1 asks the bridge withtool_searchand two deferred tools atreasoning_effort: none. Turn 2 sends the returned assistant message, the tool results and a follow-up to each model with plain function tools.gpt-5.6-chatanswers 400 on both commits because OpenAI refuses function tools with reasoning there. An earlier commit of this PR, 38e00ef, answered 400 on Fireworks and Groq, 422 on Mistral and 401 through the fallback for the same turn 2Before (314f179)
After (87db61a)
Tests
The integration test
test_chat_bridge_replays_tool_search_items_on_the_next_turnchecks the exact second request on the wire and fails on the base. Unit tests cover the replay order with one and with two reasoning items, the streamed namespace and reasoning item, a turn that only searched, a client search turn streamed and not streamed (500 and no items onmain),defer_loadingdropped beside a clienttool_search, replay left out when the request has notool_searchtool, and the shared converter's unchanged default output. Guardrail tests coverallowed_toolswithtool_searchintoolsand inextra_body.tools, the tool policy guardrail, and the tool permission guardrail in block mode (400) and rewrite mode (only the message whose search loaded the denied tool loses itstool_search_items). Each new guardrail test fails when its fix is revertedType
🐛 Bug Fix
✅ Test
Caveats (if any)
Medium
finish_reason: "stop"with no contenttool_search_itemsLow
nullfields on tool search items are dropped on replaycreated_by: nullon input itemstool_search_itemsandreasoning_itemsallowed_toolsdotool_search_itemsor the replayednamespaceFinal Attestation
Bugbot summary