Repository navigation
tools: SparkQwen 0.4.0 tool/grammar follow-ups: the tool-call-or-JSON union, required/named tool deferral, literal-XML fixes (ported from Enntity) - #283
Merged
Conversation
GLM's chat template renders a string argument raw and any other value as
JSON, so `<arg_value>true</arg_value>` is the string "true" or the boolean
true depending only on the parameter's declared type. The parser JSON-parsed
every value before the schema was consulted, and coerce_all has no string
arm, so string parameters came back as booleans, numbers, lists and objects:
Java/JavaScript literals in BFCL (`"true"`, `"[60, 30]"`), zip codes and
version strings ("1.10" -> 1.1). Keep the text as written, as qwen3_coder
does; coerce_all (wants_typed_arguments) types it from the schema, and
resolve_schema_type now also reads type arrays (`["integer", "null"]`).
On the MLPerf edge-agentic BFCL leg (official harness, SparkGLM), 63 of 995
samples failed on exactly this; rescoring those outputs with the values kept
as strings estimates 83.7 -> 88.6 overall.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 9913d54)
When the same tool call returned the same result three times, the loop detector hard-masked <tool_call> for a turn (and the soft bias already pushed against it at three repeats). A model that still wants to act then narrates the action it cannot take: omp on GLM-5.3-Flash repeated one paragraph for 756 tokens after its third identical grep. From the second identical round (same calls and arguments, same non-error result), append a <REPEAT NOTICE> to the latest tool result, give that turn the xhigh thinking rung unless the client set an explicit budget, and keep <tool_call> open and unbiased. Error repeats keep their existing hints; requests without identical repeats are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 236beb9)
compile_tool_or_json_grammar unions a parser's own structural-tag tool grammar with the response_format JSON (json_schema with the strict options and limits of compile_json_schema, or the builtin JSON grammar for json_object). The tool branch is the parser's auto-mode tags made required from the first output token, with parallel calls after it, so the first token picks a call or the bare JSON: fenced JSON and prose are refused. Generic over every structural-tag parser; the JSON branch is scoped to the one compile. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 66218e8)
…mmar With both set, Atlas enforced only the tool-call grammar (sampling_setup.rs: "response_format + tools both set; enforcing tool-call grammar"), so on the turn the model answered instead of calling a tool the content was free and GLM wrapped correct JSON in ```json fences that strict clients reject (ToolEvalBench TC-65..69). grammar_choice is the request -> grammar matrix: auto/unset with a response_format now gets GrammarSpec::ToolCallOrJson, the union of the parser's tool grammar and the schema, a strict (response_format) grammar; "required"/named keeps the tool grammar alone, "none" the schema alone, and every request without a response_format is unchanged. OpenAI and vLLM enforce the schema on the final answer the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 98a3fa2)
Masked token by token, the union let the model's runner-up decide: when
GLM means to answer with a ```json fence (its top token, masked), the
tool opener outranks `{` and every answer becomes a tool call. At the
union's first output token the branch is now chosen by mass: the tool
branch when the model puts more probability on tool-branch tokens than
on everything else (an answer in any shape), else the answer; that
position's mask is then the chosen branch's alone (grammar::branch).
The answer branch's first-token mask comes from the response_format
JSON compiled alone (GrammarEngine::json_start_mask). The choice runs
wherever host logits meet the mask: the logits pipeline
(GrammarBitmaskApply) and sample_token_with_grammar, whose greedy fast
path no longer takes the top token alone at the branch.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit aaa09c2)
Grammar::union ports upstream's Grammar::Union over the existing GrammarUnion functor. compile_schema_grammar compiles a grammar that embeds a client JSON schema under the same max_schema_grammar_bytes bound compile_json_schema enforces, so a union with a schema cannot dodge it. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 1921b33)
…0.4.0's shape) + gate on !verbatim_prompt
…efore-bias ordering
…l_lt_bytes_with_state
… has filters_bare_role_literals)
…) — required tool grammars defer to after reasoning
AzeezIsh
marked this pull request as ready for review
October 31, 2026 15:12
This was referenced Oct 31, 2026
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
Next part of bringing SparkQwen 0.4.0's tool calling onto main, stacked on #279 (merged). Ported from Enntity
spark-shared(AGPL-3.0, data-angel), credited per commit.9913d54f4) and the tool-loop repeat notice (236beb904), including 0.4.0's repeat-turn thinking-budget escalation.response_formatundertool_choice: autocompile one grammar that picks the tool branch or the JSON branch by mass. Commits:66218e884,98a3fa218,aaa09c293,5db3b6156,9f075c468,8f812bd57, plus its xgrammar prerequisite1921b33f7(Grammar::union, schema-bounded compile).0ce591b63,19bfc90bd,baa93620b,4bcbc9671,17e5c92b0,318569b87,ba0b7bd08,095ff2237.tool_choicedefer the tool grammar until reasoning ends (ed381734d). A hunk audit against 0.4.0 also restored thedefer_first_tokenmachinery, the union-awaretool_call_biasandrole_literal_leaks.tool_choice: "required"or a named tool, main ends withfinish_reason=lengthand no tool call. 0.4.0 emits the call. Measured on the pair with main48f73b27c.Test plan (reiner + spark2, TP=EP=2; receipts in reiner's
~/code/night1027/out/stack-c3d64fea4/,stackt-64a9e1a71/)--tests) and fmt are clean.union_check.py, 8 cases × block/stream):api_parity.py: 26/26 identical. It covers auto single and parallel tools,tool_choicenone, json_object, stop, n=2, unset max_tokens, effort high, a tool-result round, and/v1/messagesand/v1/responses(both block and stream).Generated with Devin