Skip to content

fix: emit server_tool_use block on agentic-loop web search path - #31687

Closed
haha1903 wants to merge 1 commit into
BerriAI:litellm_oss_stagingfrom
haha1903:fix/agentic-web-search-server-tool-use
Closed

haha1903 wants to merge 1 commit into
BerriAI:litellm_oss_stagingfrom
haha1903:fix/agentic-web-search-server-tool-use

Conversation

@haha1903

Copy link
Copy Markdown

Relevant issues

Follow-up to #27886, which added native server_tool_use + web_search_tool_result blocks on the short-circuit web search path. This PR brings the agentic-loop path to parity.

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all CI/CD checks (lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have requested a Greptile review

Type

🐛 Bug Fix

Changes

WebSearchInterceptionLogger._build_native_result_blocks (used by the agentic-loop path for providers that have native Anthropic Messages support — anthropic, bedrock, vertex_ai, azure_ai) emitted only a web_search_tool_result block per tool call, omitting the paired server_tool_use block.

Anthropic-native clients (Claude Code, Claude Desktop, the Anthropic SDK) require both blocks to render citation cards. Without the server_tool_use block the client reports "Did 0 searches" even though the search ran and results were returned.

The short-circuit path already emits the pair (added in #27886). This makes the two paths consistent: each web_search_tool_result is now preceded by a server_tool_use block carrying the query, with a matching tool_use_id.

 for i, tool_call in enumerate(tool_calls):
     tool_use_id = tool_call.get("id") or ""
+    tool_input = tool_call.get("input") or {}
+    query = tool_input.get("query") if isinstance(tool_input, dict) else None
     structured = structured_results[i] if i < len(structured_results) else None
+    blocks.append({
+        "type": "server_tool_use", "id": tool_use_id,
+        "name": "web_search",
+        "input": {"query": query} if query is not None else {},
+    })
     blocks.append(WebSearchTransformation.build_web_search_tool_result_block(...))

Tests

Updated test_websearch_native_blocks.py to assert the paired shape on both the plan path and the legacy path, including that server_tool_use.id == web_search_tool_result.tool_use_id.

pytest tests/test_litellm/integrations/websearch_interception/ -q
99 passed, 2 skipped

Proof of fix

Running a proxy that routes Claude requests through the agentic-loop web search path, a web_search_20250305 request now returns the full native shape:

content block types: ['server_tool_use', 'web_search_tool_result', 'text']

Before this fix the same request returned only ['web_search_tool_result', 'text'], and Claude Code showed "Did 0 searches" with no citation card. After, the client renders citation cards normally.

@CLAassistant

CLAassistant commented Jun 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codspeed

codspeed Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing haha1903:fix/agentic-web-search-server-tool-use (d690712) with main (0ade44f)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes the agentic-loop web search response match the native Anthropic block shape. The main changes are:

  • Adds a server_tool_use block before each web_search_tool_result block.
  • Carries the original search query into the server_tool_use.input payload.
  • Updates tests to verify paired block ordering and matching tool-use IDs.

Confidence Score: 5/5

Safe to merge based on the narrow response-shape change and focused test coverage.

The change is isolated to native web search block construction and tests cover the paired block ordering and matching tool-use IDs.

T-Rex T-Rex Logs

What T-Rex did

  • Performed a base-state check of native websearch blocks and confirmed block_count is 1 with only web_search_tool_result for toolu_one.
  • Performed an after-state check on head and confirmed block_count is 2, with server_tool_use at index 0 for id toolu_one and input.query: what is litellm, followed by web_search_tool_result at index 1 with tool_use_id: toolu_one.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "fix: emit server_tool_use block on agent..." | Re-trigger Greptile

@codecov

codecov Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@haha1903
haha1903 force-pushed the fix/agentic-web-search-server-tool-use branch from 9ee8b7a to d690712 Compare June 30, 2026 03:47
haha1903 added a commit to haha1903/litellm that referenced this pull request Jun 30, 2026
Builds ghcr.io/haha1903/litellm on push of a patched-v* tag, carrying the
agentic-loop web_search server_tool_use fix on top of upstream until it lands
upstream (PR BerriAI#31687).
@haha1903
haha1903 changed the base branch from main to litellm_oss_staging June 30, 2026 09:25
@haha1903
haha1903 force-pushed the fix/agentic-web-search-server-tool-use branch from d690712 to 0ab94c8 Compare June 30, 2026 15:56
@Sameerlite
Sameerlite force-pushed the litellm_oss_staging branch from 26ac40c to cca71a0 Compare July 1, 2026 03:58
The agentic-loop web search path (providers with native Anthropic Messages
support — anthropic, bedrock, vertex_ai, azure_ai) built only a
web_search_tool_result block per tool_call via _build_native_result_blocks,
omitting the paired server_tool_use block. Anthropic-native clients (Claude
Code, Claude Desktop, the SDK) need both to render citation cards, so without
it the client reports "Did 0 searches".

The short-circuit path already emits the pair (BerriAI#27886); this brings the
agentic-loop path to parity. Each result block is now preceded by a
server_tool_use block carrying the query, with a matching tool_use_id.
@haha1903
haha1903 force-pushed the fix/agentic-web-search-server-tool-use branch from 0ab94c8 to 9df0fa5 Compare July 1, 2026 07:54
@haha1903

haha1903 commented Jul 1, 2026

Copy link
Copy Markdown
Author

Hi @krrish-berri-2 — friendly ping for review when you have a moment.

This is a small follow-up to #31669 (which you merged): that PR added the native server_tool_use + web_search_tool_result blocks on the short-circuit path, but the agentic-loop path (_build_native_result_blocks) still emits only the web_search_tool_result block. Anthropic-native clients (e.g. Claude Code) need the paired server_tool_use block too, otherwise they report "Did 0 searches" with no citation card. This PR brings the agentic-loop path to parity.

  • Rebased onto litellm_oss_staging, no conflicts, CI green.
  • Greptile confidence 5/5.
  • Scope is isolated: one change in _build_native_result_blocks + tests.

Thanks!

@haha1903 haha1903 closed this Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants