litellm/tests/unit/rust_bridge/host
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
..
routes fix(websearch_interception): answer a web search turn that reaches max_agentic_loops (#54053) 2026-11-24 01:55:38 -08:00
__init__.py refactor(rust_bridge): route Python state reads through host modules (#45689) 2026-10-11 14:10:16 -07:00
test_cache.py feat(messages): serve azure ai foundry messages on rust only (#51721) 2026-11-14 13:40:38 -08:00
test_cache_invalidation.py refactor(auth_cache_invalidation): move the invalidation channel to the native client (#51135) 2026-11-21 18:58:27 +09:00
test_callbacks_legacy_python.py feat(cost): price native /v1/messages calls in the Rust route and hand the receipt to logging (#52624) 2026-11-23 16:27:46 -08:00
test_model_capabilities.py feat(messages): serve bedrock invoke messages on rust only (#51330) 2026-11-15 16:58:31 -08:00
test_model_cost.py feat(cost): price Claude token calls, budget holds and auth price checks in Rust (#52484) 2026-11-23 22:00:28 +00:00
test_preflight.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
test_redis_credentials.py feat(redis): extend the native Redis foundation for the store families (#50169) 2026-11-06 12:30:07 +09:00
test_redis_events.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_route_groups.py refactor(auth): decide route rules in Rust (#51531) 2026-11-16 18:55:32 +09:00
test_secret_manager.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_settings.py feat(bedrock): derive STS session tags and session name from caller identity (#52978) 2026-11-19 17:11:09 -08:00