Repository navigation
[Bugfix][Tool Parser] Emit FunctionGemma tool calls that arrive in a single streaming delta - #59754
Conversation
…single streaming delta The streaming parser only opened a tool call when start_count exceeded end_count, so a complete <start_function_call>...<end_function_call> block delivered in one delta left current_tool_id at -1 and the call was dropped without any delta being emitted. Move the completion handling into _flush_completed_calls, which opens any completed call that was never started and emits its name and arguments, and call it both when a call ends and when a delta closes one call while opening the next. A delta that carries several calls now reports all of them in one update, as other parsers do for batched tokens. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Stanley Shen <sshen37@ucsc.edu>
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment Once the PR is approved or has the If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
|
This pull request has merge conflicts that must be resolved before it can be |
Purpose
FunctionGemmaToolParser.extract_tool_calls_streamingdropped a tool call entirely when the whole<start_function_call>call:name{...}<end_function_call>block arrived inside one streaming delta, which happens withspeculative decoding, multi-token prediction or
stream_interval > 1.A tool call was only opened in the branch guarded by
start_count > prev_start_count and start_count > end_count. When acomplete block lands in a single delta,
start_count == end_countfor that step, so the call was never opened andcurrent_tool_idstayed at-1. The "call just ended" branch did run, but it was guarded bycurrent_tool_id >= 0andso returned
None. The client got nothing: no name, no arguments, no error, even though non-streamingextract_tool_callsparses the same text correctly.This fix moves the completion handling into
_flush_completed_calls, which opens any completed call that was neverstarted (advancing
current_tool_idand thestreamed_args_for_tool/prev_tool_call_arrbookkeeping) before emittingits name and arguments. It is called both when a call ends and when a delta closes one call while opening the next, so
trailing arguments of an in-flight call are not lost when a new
<start_function_call>shows up in the same delta.A delta that carries several calls now reports all of them in one update. That is how other parsers behave when tokens
are batched (see the
assert_one_tool_per_delta=Falsetests for granite, olmo3, pythonic, kimi_k2 and others); thealternative would be to hold back all but the first call, which is exactly the silent loss this PR fixes.
Related to #48020 (the FunctionGemma case reported there).
Not a duplicate: the only other open PR touching this streaming path is #48705, which changes how argument diffs are
computed (
find_common_prefix, dropping the premature closing brace) and never touches the branches that open a call,so it does not fix this bug. #57768, #57120 and #57989 are unrelated (regex timeout, trailing content, hyphenated
names). #48636 is the same bug class in the DeepSeek V3/V3.1 parser, a different file. Whichever of #48705 and this PR
lands second needs a trivial rebase, since both touch the argument-diff lines and add a
TestExtractToolCallsStreamingclass; I am happy to rebase on top of #48705.
Test Plan
Streaming tests:
test_whole_tool_call_in_single_delta: the whole call in one delta reconstructs to the same name/arguments asextract_tool_calls.test_parallel_tool_calls_in_single_delta: two complete calls in one delta.test_second_tool_call_in_single_delta: one call streamed token by token, the second complete in its own delta.test_tool_call_closed_and_next_call_in_same_delta: one delta closes the first call's arguments and carries the wholesecond call.
test_tool_call_split_across_deltascovers the pre-existing token-by-token path and keeps the one-tool-call-per-deltainvariant.
Test Result
Before the parser change (tests only, on
main):After:
pre-commit run --files vllm/tool_parsers/functiongemma_tool_parser.py tests/tool_parsers/test_functiongemma_tool_parser.pypasses (ruff, mypy, SPDX, test tethering).
No model evaluation: this only changes how already-generated text is turned into streaming deltas, not sampling or
model output, and the added tests pin the streaming result to the non-streaming parse of the same text.
I used AI help on this. I went through every changed line, traced the state machine by hand, and ran the tests locally.