Skip to content

fix(data): wrap MiniMax-M2 tool calls in <minimax:tool_call> tags#10586

Open
he-yufeng wants to merge 1 commit into
hiyouga:mainfrom
he-yufeng:fix/minimax-m2-tool-call-tags
Open

fix(data): wrap MiniMax-M2 tool calls in <minimax:tool_call> tags#10586
he-yufeng wants to merge 1 commit into
hiyouga:mainfrom
he-yufeng:fix/minimax-m2-tool-call-tags

Conversation

@he-yufeng

Copy link
Copy Markdown

What does this PR do?

MiniMaxM2ToolUtils.function_formatter emits the <invoke>...</invoke> blocks but never wraps them in the <minimax:tool_call>...</minimax:tool_call> tags. That is the wrapper the tool prompt (MINIMAX_M2_TOOL_PROMPT) tells the model to produce, and the same wrapper tool_extractor requires:

regex = re.compile(r"<minimax:tool_call>\s*(.+?)\s*</minimax:tool_call>", re.DOTALL)

So the assistant tool-call targets built during training don't match the format the model is taught to emit, and a round trip through function_formatter -> tool_extractor returns the raw string instead of the parsed calls.

Repro on current main:

tu = get_tool_utils("minimax2")
f = tu.function_formatter([FunctionCall("get_weather", json.dumps({"city": "NYC"}))])
# f has no <minimax:tool_call> wrapper
tu.tool_extractor(f)  # returns the raw string, extraction fails

The fix wraps the joined invoke blocks in the tags, matching both the prompt spec and the extractor:

return "<minimax:tool_call>\n" + "\n".join(function_texts) + "\n</minimax:tool_call>"

After the fix the round trip returns [FunctionCall(name='get_weather', arguments='{"city": "NYC"}')] for both single and parallel calls.

How I tested

Added regression tests in tests/data/test_formatter.py (single, parallel, extractor, round trip), mirroring the existing qwen/lfm2 cases.

python -m pytest tests/data/test_formatter.py -q   # 38 passed
ruff check                                          # clean

Before submitting

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the function_formatter in src/llamafactory/data/tool_utils.py to wrap tool calls with <minimax:tool_call> tags. It also adds comprehensive unit tests in tests/data/test_formatter.py to verify the formatting, extraction, and round-trip behavior for the minimax2 tool format. There are no review comments, and I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant