Skip to content

feat(server): MiniMax-M3 tool-call parser (namespaced XML format) - #793

Merged
inureyes merged 1 commit into
mainfrom
feature/issue-770-minimax-m3-tool-parser
Jul 13, 2026
Merged

inureyes merged 1 commit into
mainfrom
feature/issue-770-minimax-m3-tool-parser

Conversation

@inureyes

Copy link
Copy Markdown
Member

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 (#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

  • 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, $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 #770

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
@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:low Low priority status:review Under review status:done Completed and removed status:review Under review labels Jul 13, 2026
@inureyes
inureyes merged commit 4d36e85 into main Jul 13, 2026
4 checks passed
@inureyes
inureyes deleted the feature/issue-770-minimax-m3-tool-parser branch July 13, 2026 11:53
@inureyes inureyes self-assigned this Aug 31, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:low Low priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(server): MiniMax-M3 tool-call parser (namespaced XML format)

1 participant