feat: Add MiniMax-M2 tool call parser#98
Conversation
4e7af16 to
4ab0d64
Compare
Add full tool call parsing for MiniMax-M2 models' native XML format, including streaming integration with reasoning parsers. Changes: - minimax_tool_parser.py: Parser for <minimax:tool_call>/<invoke> XML format with streaming support; handles bare <invoke> without wrapper (model sometimes emits inside <think> blocks); filters hallucinated <invoke> tags without parameters - cli.py: Add "minimax" to --tool-call-parser choices - tool_parsers/__init__.py: Register MiniMaxToolParser - api/utils.py: Strip MiniMax special tokens ([e~[, ]~b]role, ]~!b[) - server.py: Integrate tool parser within reasoning parser streaming path — detect tool call markers in reasoning stream and redirect to content for parsing; suppress whitespace-only content before tool calls to avoid confusing clients Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4ab0d64 to
9f64a24
Compare
|
Thanks for this PR. This works out really well on M3 ultra with "MiniMax-M2.5-MLX-4bit". |
|
@waybarrios, @janhilgard: brief endorsement plus cross-references. This addresses issue #35 (jverkoey, "Minimax M2.1 support?") which is still open. The PR adds a full Coordination note: there is also PR #231 (sjswerdloff, "feat: add MiniMax tool call parsing support") which appears to target the same general area. The two are not currently cross-linked. Wayne can pick whichever is more complete, or merge both if they cover different model variants. PR is MERGEABLE on current main. Last activity Feb 24 (~6 weeks ago) which is very stale for a feature that has an open issue requesting it. |
Summary
MiniMaxToolParserfor MiniMax-M2 models' native XML tool call formatDetails
MiniMax-M2 models use a custom XML-based tool call format distinct from other parsers. This PR adds:
minimax_tool_parser.py— Full parser with regex-based extraction of<minimax:tool_call>blocks,<invoke>elements, and<parameter>elements. Supports both non-streaming (extract_tool_calls) and streaming (extract_tool_calls_streaming) modes. Parameter values are auto-parsed as JSON when possible for proper typing.CLI integration —
minimaxadded to--tool-call-parserchoices.Special token stripping — MiniMax end-of-turn token
[e~[, role markers]~b]assistantetc., and BOS token]~!b[are added to the globalSPECIAL_TOKENS_PATTERNregex.Streaming: reasoning + tool parser integration — MiniMax wraps tool calls inside
<think>blocks, so when--reasoning-parseris enabled, the reasoning parser captures tool call XML as reasoning content. This PR adds detection of tool call markers in the reasoning stream and redirects them to the content stream for proper tool parser processing. This fixes streaming tool calls when both--reasoning-parserand--tool-call-parser minimaxare used together.Changes
vllm_mlx/tool_parsers/minimax_tool_parser.pyvllm_mlx/tool_parsers/__init__.pyvllm_mlx/cli.pyvllm_mlx/api/utils.pyvllm_mlx/server.pyTest plan
tool_callsdelta emission--reasoning-parser deepseek_r1: tool calls detected in reasoning and redirectedUsage
🤖 Generated with Claude Code