feat: Add MiniMax-M2 tool call parser#98
Open
janhilgard wants to merge 1 commit intowaybarrios:mainfrom
Open
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". |
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
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