Repository navigation
fix: make Messages web search max_uses limit searches, not calls - #391
Merged
franciscojavierarceo merged 1 commit intoSep 30, 2026
Conversation
max_uses on a native web_search_20250305 declaration limits the searches a request may perform. The Messages loops charged that budget once per tool call, which was exact while a call carried one query. Since vllm-project#214 the normalized tool sent upstream also accepts a batch of up to five queries, so one call could run five searches and max_uses: N allowed up to 5N. 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. A call the budget cannot cover is refused whole with the existing max_uses result and leaves the budget for a later call that fits. A call whose arguments cannot be parsed performs no search and is no longer charged. Both loops now dispatch through one function in messages_tools.rs, so the JSON and SSE paths cannot apply the rule differently. The normalized tool schema is unchanged, so batching stays available. Signed-off-by: Chuyue Wang <[email protected]>
StevenWang-CY
requested review from
bbrowning,
franciscojavierarceo,
haoshan98,
jiahuei,
leseb,
maralbahari,
noobHappylife,
qandrew and
tjtanaa
as code owners
September 29, 2026 19:44
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The shared implementation matches the documented semantics and has comprehensive coverage across both transports.
Review effort: Balanced
Findings: None
What changed in this PR
Corrects Messages web-search budgeting so max_uses limits individual searches rather than tool calls.
Changes:
- Adds shared JSON/SSE gateway-tool admission and dispatch.
- Counts validated batched queries and rejects oversized calls atomically.
- Adds unit, transport, and end-to-end coverage plus documentation.
| File | Description |
|---|---|
README.md |
Documents search-budget semantics. |
ARCHITECTURE.md |
Describes shared dispatch and admission. |
crates/agentic-server/tests/messages_web_search_budget_test.rs |
Tests HTTP JSON and SSE behavior. |
crates/agentic-server-core/tests/messages_stream_test.rs |
Covers streaming budget scenarios. |
crates/agentic-server-core/tests/messages_loop_test.rs |
Covers non-streaming budget scenarios. |
crates/agentic-server-core/src/tool/web_search/args.rs |
Counts validated requested searches. |
crates/agentic-server-core/src/executor/mod.rs |
Registers the shared dispatch module. |
crates/agentic-server-core/src/executor/messages_tools.rs |
Centralizes admission and execution. |
crates/agentic-server-core/src/executor/messages_stream/blocks.rs |
Routes reconstructed calls through shared dispatch. |
crates/agentic-server-core/src/executor/messages_stream.rs |
Applies shared budgeting to SSE rounds. |
crates/agentic-server-core/src/executor/messages_request.rs |
Implements all-or-nothing budget admission. |
crates/agentic-server-core/src/executor/messages_loop.rs |
Uses shared dispatch for JSON rounds. |
crates/agentic-server-core/src/executor/messages_context.rs |
Exposes request-wide search admission. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
franciscojavierarceo
approved these changes
Sep 30, 2026
franciscojavierarceo
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed budget admission, argument parsing, and shared JSON/SSE dispatch. No actionable correctness or regression findings. Local validation: 906 tests passed, with 5 ignored, including HTTP JSON/SSE budget regressions; CI is green.
franciscojavierarceo
added a commit
that referenced
this pull request
Sep 30, 2026
## Summary An upstream Messages round without `message_start` can currently dispatch a built-in tool or report completion. Require a start in each round before accepting content-block events or terminal message events. Invalid order produces a fixed `api_error` before dispatch or completion; upstream errors and harmless unknown events retain their handling. Follow-up to #345, part of #313 and #316. Move the accumulator's existing ingestion methods into a private module to keep the single parsing/validation path within the file-size limit, and remove the old exception. Four existing unit fixtures now include their required round starts. Broader schema validation and resource budgets remain open; search-budget accounting is separate work in #391. ## Test Plan - New regression failed on current main: omitting a round's start still dispatched search. It removes the start from both recorded rounds and separately checks content deltas/stops and message deltas/stops before a start. - Core library: 914 passed, 5 ignored. Messages streaming integration: 16 passed. HTTP Messages completion/tool choice: 25 passed (955 total). - Workspace all-target Clippy with warnings denied and all-files pre-commit checks passed, including formatting and file sizes. - Compared extracted ingestion methods with the original: unchanged except for the ordering guard and private module visibility. Deterministic local fixtures; no live inference. Signed-off-by: Francisco Javier Arceo <[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
Anthropic defines
max_useson the web search tool as a hard cap on searches: "Themax_usesparameter 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 onequery. #214 then let the sharedweb_searchfunction tool batch up to fivequeriesper call, and that tool is what a native declaration is normalized to for the upstream model. One call can therefore run five searches, andmax_uses: Nallows up to5N.With
max_uses: 2and a model that asks for eight searches over three tool rounds:maint1t2t3t4t5The budget now counts searches:
max_usestool_resultand 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 themax_useserror, never the output of a shortened call.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 nomax_usestest; it has one now.messages_stream.rsloses three production lines and stays under its file-size cap. The README andARCHITECTURE.mdstate 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 atmainwith only the test files applied and the workspace crates rebuilt from that worktree.native_web_search_max_uses_counts_every_batched_queryandmessages_stream_max_uses_counts_every_batched_queryrun the scenario in the table through the JSON and SSE loops and assert the queries the search backend received and every fed-backtool_result. Onmainfour searches reach the backend.native_web_search_malformed_calls_do_not_use_the_budgetand its streaming twin put an emptyquerieslist and a non-object input ahead of a valid search undermax_uses: 1. Onmainthe malformed call uses up the budget and the valid search never runs.messages_web_search_budget_test.rsdrives the table scenario through the HTTP gateway withstream: falseandstream: true, against an inference and a search backend on a real listener. Onmainboth fail with four searches.mainand here: a batch the budget covers runs in full, a request withoutmax_usesis not limited, and one search per call is limited as before on both transports.requested_searchesagainst the handler's parser and the admission rule of the budget.agentic-serverbinary with a stdlib inference and search backend, over JSON and SSE: the upstream model is offered the batchedqueriesparameter, the binary built frommainruns four searches undermax_uses: 2, and the one built from this commit runs exactly two and returns200with the final answer and no gateway call.pre-commit run --all-files(includingrust-file-sizeswithRUST_FILE_SIZE_BASE=origin/main),cargo fmt -- --check,cargo clippy --all-targets -- -D warnings, andcargo test --no-fail-fastacross the workspace pass on the exact commit from a clean worktree.