Repository navigation
fix: support native Messages web search - #174
Merged
Merged
Conversation
Signed-off-by: Francisco Javier Arceo <[email protected]>
franciscojavierarceo
marked this pull request as ready for review
August 13, 2026 19:00
franciscojavierarceo
requested review from
bbrowning,
jiahuei,
leseb,
maralbahari,
noobHappylife,
qandrew and
tjtanaa
as code owners
August 13, 2026 19:00
There was a problem hiding this comment.
Pull request overview
This PR adds first-class support for Anthropic Messages-native web search declarations (web_search_20250305) by validating policy fields, translating the native tool declaration into a vLLM-compatible function-tool schema, and executing the search internally in both streaming and non-streaming Messages loops (plus normalization on /v1/messages/count_tokens).
Changes:
- Validate native web-search tool declarations (version gating,
max_uses, domain filters,allowed_callers, anduser_location) and reject unsupported/invalid requests early. - Normalize native
web_search_20250305declarations into function-tool shape for vLLM, while enforcing a request-widemax_usesbudget in loop + streaming paths. - Expand tests/docs to cover normalization, rejection, and policy enforcement; extend web-search config to support
blocked_domains.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates gateway usage docs to reflect native Messages web search support and legacy alias behavior. |
| crates/agentic-server/tests/messages_test.rs | Adds integration tests for count_tokens normalization and request validation/rejection. |
| crates/agentic-server/src/handler/http/messages.rs | Validates native web search before streaming commits; normalizes count_tokens payload for upstream. |
| crates/agentic-server-core/tests/messages_stream_test.rs | Adds streaming tests for normalization and max_uses enforcement behavior. |
| crates/agentic-server-core/tests/messages_loop_test.rs | Adds loop tests for domain/location configuration and max_uses enforcement. |
| crates/agentic-server-core/src/types/tools/params.rs | Extends WebSearchFilters with blocked_domains. |
| crates/agentic-server-core/src/types/messages/tool_seam.rs | Introduces native tool type constant and maps native declaration fields into web-search executor config. |
| crates/agentic-server-core/src/types/messages/request.rs | Updates module docs to reflect normalization behavior before forwarding upstream. |
| crates/agentic-server-core/src/tool/web_search.rs | Applies blocked_domains configuration when building provider request payloads. |
| crates/agentic-server-core/src/executor/mod.rs | Wires in shared request-prep module exports. |
| crates/agentic-server-core/src/executor/messages_stream.rs | Normalizes native declarations and enforces max_uses budget during streaming tool rounds. |
| crates/agentic-server-core/src/executor/messages_request.rs | Adds shared validation/normalization + budget tracking for native web-search declarations. |
| crates/agentic-server-core/src/executor/messages_loop.rs | Normalizes native declarations and enforces max_uses budget during loop tool rounds. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Francisco Javier Arceo <[email protected]>
franciscojavierarceo
pushed a commit
that referenced
this pull request
Sep 30, 2026
## Summary Anthropic defines `max_uses` on the web search tool as a hard cap on searches: "The `max_uses` parameter limits the number of searches performed." The Messages loops charge that budget once per tool call. That was exact when #174 added it, because a call carried one `query`. #214 then let the shared `web_search` function tool batch up to five `queries` per call, and that tool is what a native declaration is normalized to for the upstream model. One call can therefore run five searches, and `max_uses: N` allows up to `5N`. With `max_uses: 2` and a model that asks for eight searches over three tool rounds: | Round | Call | Queries | `main` | This PR | | --- | --- | --- | --- | --- | | 1 | `t1` | 3 | runs 3 searches | refused | | 1 | `t2` | 1 | runs 1 search | runs 1 search | | 1 | `t3` | 2 | refused | refused | | 2 | `t4` | 1 | refused | runs 1 search | | 3 | `t5` | 1 | refused | refused | | | Searches performed | | **4** | **2** | The budget now counts searches: - Each gateway call is admitted in model order, before any call starts, only if the remaining budget covers every query it would run. The count comes from the web search handler's own argument parser, so it is the number of searches the handler would perform. - A call the budget cannot cover is refused whole with the existing `max_uses` `tool_result` and leaves the budget for a later call that fits. A call's result is therefore either the output of the call the model made or the `max_uses` error, never the output of a shortened call. - A call whose arguments cannot be parsed performs no search and is no longer charged. An admitted call is charged for the searches it requests whatever their outcome, as a call was before. - Requests without `max_uses`, aliased client tools, mixed client and gateway rounds, and the normalized tool schema are unchanged, so batching stays available. Both loops now dispatch through one function, `executor/messages_tools.rs`, so JSON and SSE cannot apply the rule differently. The streaming path had no `max_uses` test; it has one now. `messages_stream.rs` loses three production lines and stays under its file-size cap. The README and `ARCHITECTURE.md` state the budget unit. Related: #313 and Enterprise Readiness #316 (bounded, predictable built-in tool execution for Messages). ## Test Plan Red on unmodified `main` (d162633) and green with this change. The red run used a separate worktree at `main` with only the test files applied and the workspace crates rebuilt from that worktree. - `native_web_search_max_uses_counts_every_batched_query` and `messages_stream_max_uses_counts_every_batched_query` run the scenario in the table through the JSON and SSE loops and assert the queries the search backend received and every fed-back `tool_result`. On `main` four searches reach the backend. - `native_web_search_malformed_calls_do_not_use_the_budget` and its streaming twin put an empty `queries` list and a non-object input ahead of a valid search under `max_uses: 1`. On `main` the malformed call uses up the budget and the valid search never runs. - `messages_web_search_budget_test.rs` drives the table scenario through the HTTP gateway with `stream: false` and `stream: true`, against an inference and a search backend on a real listener. On `main` both fail with four searches. - Controls that pass on `main` and here: a batch the budget covers runs in full, a request without `max_uses` is not limited, and one search per call is limited as before on both transports. - Unit tests cover `requested_searches` against the handler's parser and the admission rule of the budget. - Against the real `agentic-server` binary with a stdlib inference and search backend, over JSON and SSE: the upstream model is offered the batched `queries` parameter, the binary built from `main` runs four searches under `max_uses: 2`, and the one built from this commit runs exactly two and returns `200` with the final answer and no gateway call. - `pre-commit run --all-files` (including `rust-file-sizes` with `RUST_FILE_SIZE_BASE=origin/main`), `cargo fmt -- --check`, `cargo clippy --all-targets -- -D warnings`, and `cargo test --no-fail-fast` across the workspace pass on the exact commit from a clean worktree. Signed-off-by: Chuyue Wang <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
web_search_20250305declarations into the ordinary function-tool schema accepted by vLLM while keeping gateway execution internal.max_uses, domain filters,allowed_callers, and supported location data, for streaming and non-streaming requests./v1/messages/count_tokensand document that native Claude web search does not require MCP or a client-side alias.Test Plan
cargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo test/Users/farceo/.local/bin/uv tool run pre-commit run --all-files