litellm/tests/test_litellm/integrations/websearch_interception
Shivam Rawat de82f78e5b
fix(websearch): sync tool_choice when converting web_search tools (#31375)
failing test is not related to the pr

* fix(websearch): sync tool_choice when converting web_search tools

Claude Code forces native web search via tool_choice pointing at web_search
while websearch_interception renames the tool to litellm_web_search, causing
Anthropic 400s. Forward tool_choice into pre-request hooks and rewrite forced
tool_choice to match the converted tool name.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(websearch): re-wrap agentic loop responses as SSE for streaming clients

When websearch interception converts stream=true to false for the agentic
loop, dict responses from the loop were returned as application/json even
though the client requested SSE. Wrap those responses in
FakeAnthropicMessagesStreamIterator so /v1/messages streaming callers
(e.g. Claude Code) receive text/event-stream after search completes.

Fixes #27721

Co-authored-by: Cursor <cursoragent@cursor.com>

* test(websearch): cover tool_choice sync and post-loop SSE wrap; fix UP006

Add regression tests for both websearch interception fixes: _sync_forced_tool_choice
repointing a forced web_search tool_choice to litellm_web_search (the 400 fix) and
_maybe_websearch_fake_stream_wrap re-wrapping agentic loop dict responses as SSE for
streaming clients (#27721). Switch the new helper annotations to builtin dict/list so
the ruff UP006 strict-rule ceiling stays within budget.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(websearch): resolve merge conflict and unify fake stream wrapping

Remove the duplicate _maybe_websearch_fake_stream_wrap helper left by a bad merge that caused a SyntaxError in CI, and route all call sites through _maybe_wrap_in_fake_stream instead.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Shivam Rawat <shivamrawat@Shivams-MacBook-Pro.local>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Shivam Rawat <shivamrawat@Shivams-MBP.localdomain>
2026-06-26 19:44:57 -07:00
..
test_websearch_chat_completion.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_websearch_interception_handler.py fix(websearch): sync tool_choice when converting web_search tools (#31375) 2026-06-26 19:44:57 -07:00
test_websearch_interception_thinking.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_websearch_native_blocks.py Emit native web_search_tool_result blocks for Anthropic clients (Claude Desktop / Cowork citations) (#27886) 2026-05-14 12:30:47 -07:00
test_websearch_short_circuit.py Emit native web_search_tool_result blocks for Anthropic clients (Claude Desktop / Cowork citations) (#27886) 2026-05-14 12:30:47 -07:00
test_websearch_streaming_wrap.py fix(websearch): wrap agentic loop response in fake stream for streaming requests (#31484) 2026-06-26 18:45:53 -07:00
test_websearch_thinking_constraint.py Emit native web_search_tool_result blocks for Anthropic clients (Claude Desktop / Cowork citations) (#27886) 2026-05-14 12:30:47 -07:00