Repository navigation
feat(server): MiniMax-M3 tool-call parser (namespaced XML format) - #793
Merged
Merged
Conversation
MiniMax-M3 emits tool calls in a namespaced XML dialect none of the existing parsers handle: every tag is prefixed with the literal token `]<]minimax[>[`, a block is `]<]minimax[>[<tool_call>` ... `]<]minimax[>[</tool_call>`, and each `]<]minimax[>[<invoke name="NAME">` may carry nested namespaced parameter elements. The parser is model-independent and fully testable standalone (the MiniMax-M3 model itself is a separate issue). Adds `try_minimax_m3` in tool_calls/formats.rs as a small recursive-descent scan over the namespaced tags (nesting matters, so it is not regex-based). Parameter structure follows the format rules: repeated same-name tags fold into an array, explicit `item` tags form an array, and mixed text plus child elements route the text to a `$text` field. Leaf values are coerced schema-aware from the request tool JSON schema (`int`/`uint`/`long` to integer, `num`/`float` to number, `dict` to object, `list` to array, with `anyOf`/`oneOf`/`enum`); a value whose declared-type parse fails, or that has no schema, falls back to a JSON parse, then a loose literal parse, then the raw string. Malformed markup yields None rather than panicking, and defensive caps bound call/child count and recursion depth. Registers `ToolCallFormat::MinimaxM3` in types.rs and wires the parser into parser.rs ahead of the generic marker loop: it is the only parser that needs the tool schema, and its embedded `<invoke name=` / `<tool_call>` substrings would otherwise be claimed by try_minimax_m2 / try_hermes. The distinctive namespace token makes it decline cleanly on non-M3 output, and this placement keeps it before try_llama3 / try_generic_json. Streaming: adds enter/exit rows for `]<]minimax[>[<tool_call>` / `]<]minimax[>[</tool_call>` to CHAT_DELIMITERS. These sit under the existing longest delimiter, so max_delim_len is unchanged and safe_emit_length still holds back any partial `]<]minimax[>[` prefix at a token boundary; earliest-position selection lets the full M3 marker beat the `<tool_call>` substring it contains at offset 13. Tests: single call, parallel invokes, nested object and item/repeated-tag arrays, `$text` mixed content, schema coercion for each declared kind (int/uint/long/num/float/dict/list, anyOf/oneOf/enum, string-not-numified), no-schema loose coercion, malformed/unterminated input returns None with no panic, end-to-end format detection winning over MiniMax-M2, an unchanged-Hermes/JSON regression guard, and streaming suppression split at every byte boundary of the namespace token. Existing parser-ordering tests stay green. Closes #770
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…blup#793) ## Summary Adds a dedicated tool-call parser for MiniMax-M3's namespaced XML dialect, which none of the existing parsers in `src/server/tool_calls/formats.rs` handle. Every tag is prefixed with the literal namespace token `]<]minimax[>[`; a tool block is `]<]minimax[>[<tool_call>` ... `]<]minimax[>[</tool_call>` and each `]<]minimax[>[<invoke name="NAME">` carries nested namespaced parameter elements. The parser is model-independent and fully testable standalone; the MiniMax-M3 model itself is a separate issue (lablup#763). ## What changed - `src/server/tool_calls/types.rs`: new `ToolCallFormat::MinimaxM3` variant. - `src/server/tool_calls/formats.rs`: `try_minimax_m3(text, tools)`, a recursive-descent scan over the namespaced tags (not regex, because parameter nesting matters). Structure rules: repeated same-name tags fold into an array, explicit `item` tags form an array, and mixed text plus child elements route the text to a `$text` field. Leaf values are coerced schema-aware from the request tool JSON schema (`int`/`uint`/`long` to integer, `num`/`float` to number, `dict` to object, `list` to array, with `anyOf`/`oneOf`/`enum`); on a failed typed parse or missing schema, coercion falls back to a JSON parse, then a loose literal parse (numbers and booleans), then the raw string. Malformed markup returns `None` (never panics); defensive caps bound call/child count and recursion depth. - `src/server/tool_calls/parser.rs`: wires `try_minimax_m3` in ahead of the generic marker loop. It is the only parser that needs the tool schema, and its embedded `<invoke name=` / `<tool_call>` substrings would otherwise be claimed by `try_minimax_m2` / `try_hermes`. The distinctive namespace token makes it decline cleanly on non-M3 output, and this placement keeps it before `try_llama3` / `try_generic_json`. - `src/server/tool_calls/stream_filter.rs`: adds enter/exit rows for `]<]minimax[>[<tool_call>` / `]<]minimax[>[</tool_call>` to `CHAT_DELIMITERS`. They stay under the existing longest delimiter, so `max_delim_len` is unchanged and `safe_emit_length` still holds back a partial `]<]minimax[>[` prefix at a token boundary; earliest-position selection lets the full M3 marker beat the `<tool_call>` substring it contains at offset 13. ## Why MiniMax-M3 tool calls otherwise land in `content` as raw markup instead of structured `tool_calls`, and the embedded `<invoke name=` substring would be mis-parsed by the MiniMax-M2 parser into a call with empty arguments. Schema-aware coercion is required because the format carries no JSON types inline; the declared kinds (`int`, `dict`, `list`, ...) come from the request tool schema. ## Test plan - [x] `cargo test --release --lib server::tool_calls --features cuda` (268 passed, 0 failed; 26 new MiniMax-M3 tests) - [x] `cargo clippy --release -p mlxcel --lib --tests --features cuda --no-deps -- -D warnings` (clean) - [x] `cargo fmt --all -- --check` (clean) New unit tests: single call, parallel invokes, nested object param, `item`-tag arrays, nested typed item arrays, repeated-tag arrays, `$text` mixed content, schema coercion for int/uint/long/num/float, dict/list, string-not-numified, anyOf, oneOf, enum, no-schema loose coercion, content-before-block, malformed-returns-None, unterminated-body-keeps-call; end-to-end format detection winning over MiniMax-M2 and parallel invokes; unknown-tool filtering; unchanged-Hermes/JSON regression guard; and streaming: single-feed suppression, content-before-block emitted, split at every byte boundary of the namespace token, and partial-prefix release. Existing parser-ordering tests (hermes, generic_json) stay green. Closes lablup#770
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
Adds a dedicated tool-call parser for MiniMax-M3's namespaced XML dialect, which none of the existing parsers in
src/server/tool_calls/formats.rshandle. Every tag is prefixed with the literal namespace token]<]minimax[>[; a tool block is]<]minimax[>[<tool_call>...]<]minimax[>[</tool_call>and each]<]minimax[>[<invoke name="NAME">carries nested namespaced parameter elements. The parser is model-independent and fully testable standalone; the MiniMax-M3 model itself is a separate issue (#763).What changed
src/server/tool_calls/types.rs: newToolCallFormat::MinimaxM3variant.src/server/tool_calls/formats.rs:try_minimax_m3(text, tools), a recursive-descent scan over the namespaced tags (not regex, because parameter nesting matters). Structure rules: repeated same-name tags fold into an array, explicititemtags form an array, and mixed text plus child elements route the text to a$textfield. Leaf values are coerced schema-aware from the request tool JSON schema (int/uint/longto integer,num/floatto number,dictto object,listto array, withanyOf/oneOf/enum); on a failed typed parse or missing schema, coercion falls back to a JSON parse, then a loose literal parse (numbers and booleans), then the raw string. Malformed markup returnsNone(never panics); defensive caps bound call/child count and recursion depth.src/server/tool_calls/parser.rs: wirestry_minimax_m3in ahead of the generic marker loop. It is the only parser that needs the tool schema, and its embedded<invoke name=/<tool_call>substrings would otherwise be claimed bytry_minimax_m2/try_hermes. The distinctive namespace token makes it decline cleanly on non-M3 output, and this placement keeps it beforetry_llama3/try_generic_json.src/server/tool_calls/stream_filter.rs: adds enter/exit rows for]<]minimax[>[<tool_call>/]<]minimax[>[</tool_call>toCHAT_DELIMITERS. They stay under the existing longest delimiter, somax_delim_lenis unchanged andsafe_emit_lengthstill holds back a partial]<]minimax[>[prefix at a token boundary; earliest-position selection lets the full M3 marker beat the<tool_call>substring it contains at offset 13.Why
MiniMax-M3 tool calls otherwise land in
contentas raw markup instead of structuredtool_calls, and the embedded<invoke name=substring would be mis-parsed by the MiniMax-M2 parser into a call with empty arguments. Schema-aware coercion is required because the format carries no JSON types inline; the declared kinds (int,dict,list, ...) come from the request tool schema.Test plan
cargo test --release --lib server::tool_calls --features cuda(268 passed, 0 failed; 26 new MiniMax-M3 tests)cargo clippy --release -p mlxcel --lib --tests --features cuda --no-deps -- -D warnings(clean)cargo fmt --all -- --check(clean)New unit tests: single call, parallel invokes, nested object param,
item-tag arrays, nested typed item arrays, repeated-tag arrays,$textmixed content, schema coercion for int/uint/long/num/float, dict/list, string-not-numified, anyOf, oneOf, enum, no-schema loose coercion, content-before-block, malformed-returns-None, unterminated-body-keeps-call; end-to-end format detection winning over MiniMax-M2 and parallel invokes; unknown-tool filtering; unchanged-Hermes/JSON regression guard; and streaming: single-feed suppression, content-before-block emitted, split at every byte boundary of the namespace token, and partial-prefix release. Existing parser-ordering tests (hermes, generic_json) stay green.Closes #770