Skip to content

fix: let Messages answer after forced tool use - #296

Merged
franciscojavierarceo merged 5 commits into
vllm-project:mainfrom
StevenWang-CY:fix-messages-forced-tool-choice
Sep 14, 2026
Merged

franciscojavierarceo merged 5 commits into
vllm-project:mainfrom
StevenWang-CY:fix-messages-forced-tool-choice

Conversation

@StevenWang-CY

@StevenWang-CY StevenWang-CY commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Let a Messages request that forces a gateway tool finish with an answer from its result. Previously, any remained forced on every inference round, causing repeated searches and eventual round exhaustion. vLLM 0.29.0 also labels complete named calls end_turn, which could prevent gateway execution or make clients skip their own tool calls.

  • Preserve the first selector, then relax a fulfilled any or matching tool to auto after appending the full assistant turn and paired tool results. Preserve parallel-use settings and extensions; remove name only for a named selector.
  • Accept the provider's end_turn internally for a matching, explicitly selected gateway call. Surface completed client-executed function calls with stop_reason: tool_use in JSON and the terminal SSE message_delta. Hide gateway calls in mixed rounds. Streaming normalization requires message_stop; token limits, other stop reasons and unfinished streams keep their terminal semantics.
  • Model Messages tool_choice as a tagged enum with variant-specific fields, the existing non-empty tool-name type and flattened extensions. Use exhaustive matches for fulfillment and transition, while keeping raw JSON for lossless forwarding. Invalid gateway-tool requests return HTTP 400 with invalid_request_error before inference instead of escaping through the proxy fallback. Requests without gateway tools retain transparent proxying and upstream validation.
  • Add recorded gateway and client conversations, negative controls and OpenAPI validation. No new wire fields, runtime dependencies, configuration or storage migration.

Anthropic clients distinguish completed turns from requests for client tool execution. The provider compatibility case is visible in vLLM's named-call finish reason and Messages conversion.

Test Plan

  • Live, unmodified vLLM 0.29.0 and pinned Qwen/Qwen3-4B: four gateway recordings cover any/named selection × JSON/SSE. Each completes with one local search and two provider requests; retaining the forced selector causes another call in all four live controls.
  • Two additional live recordings use Anthropic SDK 1.5.0. The SDK receives tool_use, submits the client output with the returned call ID, and receives the complete verification string. Both raw provider recordings contain end_turn. Replay checks the complete requests, response metadata and streaming lifecycle, repeats conversations on one gateway, and verifies no gateway search or Messages persistence. All six captures are unmodified recorder output.
  • Identical tests in a separate build of prior head 1e422c3: both new recorded client conversations and the client-stop/invalid-selector regressions fail as intended; all four gateway recordings still pass. The corrected commit passes all six. Earlier unchanged-main validation established failure of all four gateway scenarios before the original fix.
  • 1,402 Rust tests pass with nine existing default ignores. This includes malformed selectors, configured aliases, extension preservation, mixed ownership, truncation/unfinished-stream controls and OpenAPI schema conformance.
  • Locked Clippy across the workspace, all targets and features; formatting; all repository hooks; strict docs; gateway binaries; 13 recorder tests plus three subtests; and validation of all 139 cassettes / 308 turns pass.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A moderate test expectation issue remains unresolved and should be corrected before approval.

Pull request overview

Fixes repeated forced gateway-tool calls in Messages requests by relaxing fulfilled selectors to auto, allowing the model to answer from tool results.

Changes:

  • Updates shared selector handling for blocking and streaming flows.
  • Adds regression and integration coverage.
  • Updates Messages and architecture documentation.
File summaries
File Summary
docs/design/claude-code-integration.md Documents forced selector relaxation.
crates/agentic-server/tests/messages_tool_choice_test.rs Adds selector coverage; moderate issue: restrict name removal to type == "tool" (1 vote).
crates/agentic-server-core/src/executor/messages_loop.rs Clarifies shared loop behavior.
crates/agentic-server-core/src/executor/messages_context.rs Implements selector fulfillment and mutation.
ARCHITECTURE.md Documents selector behavior; nit: use “client-executed function tool” terminology (1 vote).
Review details

Suppressed comments (2)

ARCHITECTURE.md:764

  • Please use the repository's normative term client-executed function tool here instead of the newly introduced ambiguous Client-tool. TERMINOLOGY.md:16 and TERMINOLOGY.md:27-29 define the execution-location terminology and distinguish it from gateway-executed built-in tools.
tool. Parallel-use settings and extension fields remain intact. Client-tool and
mixed rounds return before this mutation, and Messages does not persist this state.

crates/agentic-server/tests/messages_tool_choice_test.rs:183

  • The expected transition removes name for any as well as tool. That contradicts the contract described by this change (extension fields survive; only a fulfilled named selector loses name) and would make this helper reject a valid any request carrying an extra name field. Restrict name removal to type == "tool" while still changing both forced types to auto.
        if choice["type"] == "any" || choice["type"] == "tool" {
            choice["type"] = json!("auto");
            choice.as_object_mut().unwrap().remove("name");
        }
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@StevenWang-CY

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @maralbahari. Both points are addressed in 970bcb1: completed client tool calls now report tool_use in JSON and streaming, and tool_choice is typed and validated. The regression tests and real vLLM recordings pass, and CI is green. Could you take another look when you have a chance?

@franciscojavierarceo
franciscojavierarceo merged commit 6727658 into vllm-project:main Sep 14, 2026
14 checks passed
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.

4 participants