litellm/tests/unit/rust_bridge
martenj4 8ef5cf1f25
fix(websearch_interception): answer a web search turn that reaches max_agentic_loops (#54053)
* fix(websearch_interception): answer from gathered results on the last follow-up the loop cap allows

When a web search turn reached max_agentic_loops, the last follow-up still
offered the search tool, so the model asked for one more search, the loop
refused it, and the user got no answer (an empty end_turn on /v1/messages and
a dangling litellm_web_search call on chat and responses).

The follow-up the cap allows last now drops the intercepted search tool and
keeps client tools. When no tools remain it sends tool_choice none, because
Claude otherwise calls the search tool it saw in the history. This applies to
anthropic, azure_ai, vertex_ai, openai and gemini, the providers probed live.
Bedrock and other providers keep today's behavior.

The deployment hook now passes the callback's max_agentic_loops into the call,
so the dispatchers and the builder agree on the ceiling. Chat follow-ups carry
the loop depth in litellm_metadata, so the openai and http chat paths can see
it.

* fix(websearch_interception): answer a capped turn with a max_uses_exceeded result and one last call without search

Claude ended a capped turn with no text when the last allowed follow-up simply
dropped the search tool, since it still wanted to search. The dispatchers now
let a callback that opts in through answers_tool_calls_at_agentic_loop_cap run
once more at the cap. The websearch hook answers the refused search calls with
a max_uses_exceeded search result instead of searching, and sends one last call
without the search tool (client tools kept, tool_choice none when nothing is
left). Bedrock is not opted in and keeps the old refusal.

The three per-surface search loops are now one helper.

* fix(anthropic messages): keep the client's max_tokens on every agentic follow-up

The request transform popped max_tokens off the params dict the agentic hooks
read afterwards, so every /v1/messages follow-up fell back to 1024 and a capped
turn could stop at max_tokens before answering. The handler now gives the
transform its own copy.

* fix(websearch_interception): keep the allowed_tools limit on the capped call and strip loop controls from client metadata

* fix(websearch): keep the capped last call from searching again or calling a forced client tool

The refused search now tells the model to answer from the results it has. If the
last call at the cap still asks for a search, the chat and Responses gates claim it
so the loop ends the turn with that call removed instead of handing the client a
tool it never declared. A tool_choice that forces some tool is relaxed to auto on
that call, while a choice naming one client tool stays. ARCHITECTURE.md now says the
feature-level cap covers all three routes and which providers get the last call

* docs(websearch_interception): say the loop cap counts rounds of searching, not single searches

* fix(websearch_interception): keep the one-tool-call limit and drop parallel_tool_calls on the last call at the cap

The tool-free last chat call no longer sends parallel_tool_calls, which OpenAI rejects without tools

A forced choice relaxed to auto keeps disable_parallel_tool_use on /v1/messages, and a choice forcing the search tool becomes auto instead of being dropped

/v1/messages drops a search call the capped call still made, like chat and Responses already do

The chat capped call reads the request's tool_choice the same way the other routes do

* fix(azure_ai): drop tool_choice when a chat request has no tools, as the OpenAI config does

* fix(websearch_interception): keep the feature-level max_agentic_loops on /v1/messages only, as on main

Chat and Responses read the deployment's own max_agentic_loops or the default of 3. Applying the feature-level value there ended turns empty on Bedrock and other providers outside the answer-at-cap list once it was below 3

* test(websearch_interception): type the cap-source parameters of the chat and Responses cap tests

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-24 01:55:38 -08:00
..
host fix(websearch_interception): answer a web search turn that reaches max_agentic_loops (#54053) 2026-11-24 01:55:38 -08:00
messages feat(messages): serve bedrock invoke messages on rust only (#51330) 2026-11-15 16:58:31 -08:00
ocr refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
trace refactor(lens): connect LiteLLM to the independent Lens service (#45529) 2026-10-09 16:17:05 -07:00
__init__.py test: migrate phase 15 legacy tests to tests/unit 2026-09-20 11:55:43 +00:00
AGENTS.md refactor(rust-bridge): decide native routing in the catalog, drop the bypass predicates (#46750) 2026-10-20 15:06:24 -07:00
native_route_wheel_test.py fix(bedrock): omit system prompt from audio transcription and report its token usage (#41565) 2026-10-28 19:23:15 -07:00
stubtest.ini test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_bindings.py refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
test_catalog.py feat(messages): serve bedrock claude_platform messages on rust only (#52681) 2026-11-19 14:34:02 -08:00
test_clickhouse.py refactor(lens): connect LiteLLM to the independent Lens service (#45529) 2026-10-09 16:17:05 -07:00
test_configuration.py ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
test_detectors.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00
test_execution.py refactor(rust-bridge): return an unstarted Execution from native entrypoints and drive it in Python (#46299) 2026-10-14 17:50:44 -07:00
test_failures.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_fork_guard.py refactor(rust-bridge): require the native extension (#48852) 2026-10-28 13:16:56 -07:00
test_logger.py refactor(rust_bridge): send every Rust log line through one subscriber (#53738) 2026-11-23 17:53:54 +09:00
test_public_call.py fix(rust): run native async calls through python's async wrapper steps (#50423) 2026-11-10 00:24:20 +00:00
test_runtime.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00
test_token_counter.py fix(proxy): count the request's tool_choice on the token count routes (#51133) 2026-11-14 07:53:27 -05:00
test_tokenizer.py refactor(sdk): separate core AWS and tokenizer dependencies (#44447) 2026-10-08 19:07:57 -07:00
test_verify_linux_native_wheel.py chore: move scripts and runtime sources under litellm (#51006) 2026-11-12 04:19:57 +00:00