[PR #13582] model/parsers: add minimax-m2 tool call and thinking support #45527

Open
opened 2026-04-25 01:13:14 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/13582
Author: @Happyholic1203
Created: 12/29/2025
Status: 🔄 Open

Base: mainHead: add-minimax-m2-tool-use


📝 Commits (1)

  • a3bcb60 Add MiniMax-M2 tool call support (add PARSER minimaxm2 in Modelfile to enable)

📊 Changes

3 files changed (+1290 additions, -0 deletions)

View changed files

model/parsers/minimaxm2.go (+530 -0)
model/parsers/minimaxm2_test.go (+758 -0)
📝 model/parsers/parsers.go (+2 -0)

📄 Description

TL;DR: Add PARSER minimaxm2 to the Modelfile to get native tool call support out of MiniMax's M2 models

This PR adds parser support for MiniMax-M2/M2.1 models' XML-style tool calling format.

Why

Previously in #13049 , people tried to use the system prompt to "change" the way MiniMax M2 make tool calls in order for ollama to "get" and parse that tool call properly. (M2 uses XML-style tool call format, while ollama uses JSON-style)

According to my experiment using opencode, using that template didn't "work out of the box", at least for opencode.

Here's my opencode screenshot for using that template:

貼上的影像_2025_12_29_晚上9_31

Maybe I was doing it wrong... or maybe it was a bug in opencode, I didn't find out.

What's Implemented

So I added a parser specifically for MiniMax-M2, as the same pattern for lots of models: functiongemma, deepseek3, ministral, ....

Simply add PARSER minimaxm2 to the Modelfile to enable this parser.

With this commit and the following Modelfile, I could get opencode to make the tool call perfectly:

貼上的影像_2025_12_29_晚上9_26

The Modelfile:

FROM __SOURCE_MODEL__
PARSER minimaxm2

TEMPLATE """
{{- if or .System .Tools }}]~!b[]~b]system
{{- if .System }}
{{ .System }}
{{- else }}
You are a helpful assistant.
{{- end }}
{{- if .Tools }}

# Tools
You may call one or more tools to assist with the user query.
Here are the tools available in JSONSchema format:

<tools>
{{- range .Tools }}
<tool>{{ .Function | json }}</tool>
{{- end }}
</tools>

When making tool calls, use XML format to invoke tools and pass parameters:

<minimax:tool_call>
<invoke name="tool-name-1">
<parameter name="param-key-1">"param-value-1-which-is-a-string"</parameter>
<parameter name="param-key-2">{"param-value-2-key-1": 123}</parameter>
...
</invoke>
</minimax:tool_call>

**IMPORTANT Tool Calling Rules:**
- Do NOT wrap tool calls in <think> tags
- The parameter name is case SENSITIVE
- Be sure to add `<parameter>` for EVERY REQUIRED parameter per the tool's JSONSchema
- Parameter values can be strings, numbers, or JSON objects/arrays
- You can make multiple <invoke> calls within a single <minimax:tool_call> block
{{- end }}[e~[
{{- else }}]~!b[
{{- end }}
{{- range .Messages }}
{{- if eq .Role "user" }}]~b]user
{{ .Content }}[e~[
{{- else if eq .Role "assistant" }}]~b]ai
{{- if .ToolCalls }}
<minimax:tool_call>
{{- range .ToolCalls }}
<invoke name="{{ .Function.Name }}">
{{- range $key, $value := .Function.Arguments }}
<parameter name="{{ $key }}">{{ $value | json }}</parameter>
{{- end }}
</invoke>
{{- end }}
</minimax:tool_call>
{{- else }}
{{ .Content }}
{{- end }}[e~[
{{- else if eq .Role "tool" }}]~b]tool
{{ .Content }}[e~[
{{- end }}
{{- end }}]~b]ai
"""

According to MiniMax's Tool Calling Guide, MiniMax-M2 uses the following structured XML tag format to make tool calls.

<minimax:tool_call>
<invoke name="tool-name-1">
<parameter name="param-key-1">param-value-1</parameter>
<parameter name="param-key-2">param-value-2</parameter>
...
</invoke>

And that is exactly what got implemented in this commit, by adding PARSER minimaxm2, the above will get parsed into tool calls properly.

p.s. I only tested this with unsloth's MiniMax-M2.1-GGUF:UD-Q3_K_XL model.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/13582 **Author:** [@Happyholic1203](https://github.com/Happyholic1203) **Created:** 12/29/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `add-minimax-m2-tool-use` --- ### 📝 Commits (1) - [`a3bcb60`](https://github.com/ollama/ollama/commit/a3bcb607389e47e670553dab653beedb18604989) Add MiniMax-M2 tool call support (add `PARSER minimaxm2` in Modelfile to enable) ### 📊 Changes **3 files changed** (+1290 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `model/parsers/minimaxm2.go` (+530 -0) ➕ `model/parsers/minimaxm2_test.go` (+758 -0) 📝 `model/parsers/parsers.go` (+2 -0) </details> ### 📄 Description TL;DR: Add `PARSER minimaxm2` to the `Modelfile` to get native tool call support out of MiniMax's M2 models This PR adds parser support for MiniMax-M2/M2.1 models' XML-style tool calling format. # Why Previously in #13049 , people tried to use the system prompt to "change" the way MiniMax M2 make tool calls in order for ollama to "get" and parse that tool call properly. (M2 uses XML-style tool call format, while ollama uses JSON-style) According to my experiment using [opencode](https://github.com/sst/opencode), using that template didn't "work out of the box", at least for opencode. Here's my opencode screenshot for using that template: <img width="1883" height="398" alt="貼上的影像_2025_12_29_晚上9_31" src="https://github.com/user-attachments/assets/f02005ed-7e67-4287-af44-9cfa6054b3f8" /> Maybe I was doing it wrong... or maybe it was a bug in opencode, I didn't find out. # What's Implemented So I added a parser specifically for MiniMax-M2, as the same pattern for lots of models: `functiongemma, deepseek3, ministral, ...`. Simply add `PARSER minimaxm2` to the `Modelfile` to enable this parser. With this commit and the following Modelfile, I could get opencode to make the tool call perfectly: <img width="1884" height="447" alt="貼上的影像_2025_12_29_晚上9_26" src="https://github.com/user-attachments/assets/8f59a61f-bcca-400b-bdb9-d62de725b643" /> The Modelfile: ``` FROM __SOURCE_MODEL__ PARSER minimaxm2 TEMPLATE """ {{- if or .System .Tools }}]~!b[]~b]system {{- if .System }} {{ .System }} {{- else }} You are a helpful assistant. {{- end }} {{- if .Tools }} # Tools You may call one or more tools to assist with the user query. Here are the tools available in JSONSchema format: <tools> {{- range .Tools }} <tool>{{ .Function | json }}</tool> {{- end }} </tools> When making tool calls, use XML format to invoke tools and pass parameters: <minimax:tool_call> <invoke name="tool-name-1"> <parameter name="param-key-1">"param-value-1-which-is-a-string"</parameter> <parameter name="param-key-2">{"param-value-2-key-1": 123}</parameter> ... </invoke> </minimax:tool_call> **IMPORTANT Tool Calling Rules:** - Do NOT wrap tool calls in <think> tags - The parameter name is case SENSITIVE - Be sure to add `<parameter>` for EVERY REQUIRED parameter per the tool's JSONSchema - Parameter values can be strings, numbers, or JSON objects/arrays - You can make multiple <invoke> calls within a single <minimax:tool_call> block {{- end }}[e~[ {{- else }}]~!b[ {{- end }} {{- range .Messages }} {{- if eq .Role "user" }}]~b]user {{ .Content }}[e~[ {{- else if eq .Role "assistant" }}]~b]ai {{- if .ToolCalls }} <minimax:tool_call> {{- range .ToolCalls }} <invoke name="{{ .Function.Name }}"> {{- range $key, $value := .Function.Arguments }} <parameter name="{{ $key }}">{{ $value | json }}</parameter> {{- end }} </invoke> {{- end }} </minimax:tool_call> {{- else }} {{ .Content }} {{- end }}[e~[ {{- else if eq .Role "tool" }}]~b]tool {{ .Content }}[e~[ {{- end }} {{- end }}]~b]ai """ ``` According to MiniMax's [Tool Calling Guide](https://huggingface.co/MiniMaxAI/MiniMax-M2/blob/main/docs/tool_calling_guide.md), MiniMax-M2 uses the following structured XML tag format to make tool calls. ``` <minimax:tool_call> <invoke name="tool-name-1"> <parameter name="param-key-1">param-value-1</parameter> <parameter name="param-key-2">param-value-2</parameter> ... </invoke> ``` And that is exactly what got implemented in this commit, by adding `PARSER minimaxm2`, the above will get parsed into tool calls properly. p.s. I only tested this with unsloth's [MiniMax-M2.1-GGUF:UD-Q3_K_XL](https://huggingface.co/unsloth/MiniMax-M2.1-GGUF/tree/main/UD-Q3_K_XL) model. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 01:13:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#45527