mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(allowed_tools): stop the Responses web search follow-up forcing another call
The Responses-shaped follow-up after a web search left tool_choice out of its patch, so the caller's required choice went out again through the chat to Responses bridge and looped to the loop limit. It now carries a kept allowed_tools choice in mode auto, like the chat follow-up
This commit is contained in:
parent
478fb95d6b
commit
08eb785ee2
2 changed files with 38 additions and 3 deletions
|
|
@ -1291,9 +1291,13 @@ class WebSearchInterceptionLogger(CustomLogger):
|
|||
|
||||
tools_param: Final = optional_params.get("tools")
|
||||
optional_params_clean: Final = {
|
||||
k: v
|
||||
for k, v in optional_params.items()
|
||||
if k not in {"tools", "tool_choice", "stream", "model_alias_map", "stream_response", "custom_prompt_dict"}
|
||||
**{
|
||||
k: v
|
||||
for k, v in optional_params.items()
|
||||
if k
|
||||
not in {"tools", "tool_choice", "stream", "model_alias_map", "stream_response", "custom_prompt_dict"}
|
||||
},
|
||||
**_kept_allowed_tools_tool_choice(_OPTIONAL_PARAMS.validate_python(optional_params)),
|
||||
}
|
||||
|
||||
kwargs_for_followup: Final = {
|
||||
|
|
|
|||
|
|
@ -364,6 +364,37 @@ async def test_responses_followup_keeps_the_caller_model_across_the_chat_complet
|
|||
assert followup_model == requested_model
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.usefixtures("perplexity_search")
|
||||
@pytest.mark.parametrize(
|
||||
("tool_choice", "followup_tool_choice"),
|
||||
[
|
||||
(
|
||||
{"type": "allowed_tools", "mode": "required", "tools": [{"type": "function", "name": "litellm_web_search"}]},
|
||||
{"type": "allowed_tools", "mode": "auto", "tools": [{"type": "function", "name": "litellm_web_search"}]},
|
||||
),
|
||||
({"type": "function", "name": "litellm_web_search"}, None),
|
||||
("required", None),
|
||||
],
|
||||
)
|
||||
async def test_responses_followup_keeps_only_an_allowed_tools_choice_without_forcing_another_call(
|
||||
tool_choice: object, followup_tool_choice: object
|
||||
) -> None:
|
||||
plan: Final = await WebSearchInterceptionLogger().async_build_responses_agentic_loop_plan(
|
||||
tools={**_WEB_SEARCH_FUNCTION_CALL, "provider": "azure"},
|
||||
model="gpt-5.4-mini",
|
||||
messages=[{"role": "user", "content": "What's the latest AI news?"}],
|
||||
response=_responses_output_with_web_search(),
|
||||
optional_params={"tools": [{"type": "function", "name": "litellm_web_search"}], "tool_choice": tool_choice},
|
||||
logging_obj=None,
|
||||
stream=False,
|
||||
kwargs={"custom_llm_provider": "azure", "_agentic_loop_api_surface": RESPONSES_AGENTIC_SURFACE},
|
||||
)
|
||||
|
||||
assert plan.request_patch is not None
|
||||
assert plan.request_patch.optional_params.get("tool_choice") == followup_tool_choice
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_deployment_hook_converts_native_responses_web_search_tool():
|
||||
"""async_pre_call_deployment_hook converts a native Responses web_search tool
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue