[Frontend] Support strict MiMo-V2.6 tool calling (#58019)

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: yuchuan <yuchuan.7streams@gmail.com>
Co-authored-by: Bugen Zhao <i@bugenzhao.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ubospica <ubospica@gmail.com>
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
This commit is contained in:
Yixin Dong
2026-09-29 12:47:47 +00:00
committed by GitHub
co-authored by Codex yuchuan Bugen Zhao Claude Opus 5.5
parent 79a0307d74
commit dfc8e0f3e2
17 changed files with 243 additions and 15 deletions
+24
View File
@@ -1175,3 +1175,27 @@ class TestNestedSchemaCoercion:
assert questions[0]["question"] == "Pick a color"
assert questions[0]["multiSelect"] is False
assert questions[0]["answer"] is None
@pytest.mark.parametrize("value", ["\n北京 &amp;\n", "null", "42", "", "a\nb"])
@pytest.mark.parametrize("chunk_size", [1, 7, 1000])
def test_mimo_preserves_verbatim_parameter_values(
mock_tokenizer, mock_request, value, chunk_size
):
from vllm.parser.mimo import MiMoParser
text = (
f"<tool_call><function=run><parameter=text>{value}</parameter>"
"</function></tool_call>"
)
parser = MiMoParser(mock_tokenizer, chat_template_kwargs={"enable_thinking": False})
result = parser.extract_tool_calls(text, mock_request)
assert json.loads(result.tool_calls[0].function.arguments) == {"text": value}
parser = MiMoParser(mock_tokenizer, chat_template_kwargs={"enable_thinking": False})
results = simulate_tool_streaming(
parser,
mock_request,
[text[i : i + chunk_size] for i in range(0, len(text), chunk_size)],
)
assert collect_function_name(results) == "run"
assert json.loads(collect_tool_arguments(results)) == {"text": value}
+39 -3
View File
@@ -15,6 +15,7 @@ from __future__ import annotations
import functools
import json
from collections.abc import Callable
from dataclasses import dataclass, replace
from typing import Any
@@ -39,6 +40,7 @@ from vllm.parser.engine.registered_adapters import (
GraniteThinkingParser,
InklingParser,
KimiK2Parser,
MiMoParser,
MinimaxM2Parser,
NemotronV3Parser,
Plamo3Parser,
@@ -356,7 +358,12 @@ def _qwen3_tool_segments(tc: ToolCallSpec) -> list[tuple[str, bool]]:
]
def _qwen3_segments(scenario: Scenario) -> list[tuple[str, bool]]:
def _qwen3_segments(
scenario: Scenario,
tool_segments: Callable[[ToolCallSpec], list[tuple[str, bool]]] = (
_qwen3_tool_segments
),
) -> list[tuple[str, bool]]:
segs: list[tuple[str, bool]] = []
if scenario.reasoning is not None:
segs.append((scenario.reasoning, False))
@@ -369,7 +376,7 @@ def _qwen3_segments(scenario: Scenario) -> list[tuple[str, bool]]:
segs.append((scenario.content, False))
if scenario.tool_calls:
for tc in scenario.tool_calls:
segs.extend(_qwen3_tool_segments(tc))
segs.extend(tool_segments(tc))
return segs
@@ -389,6 +396,9 @@ def _build_qwen3(
parser_cls: type = Qwen3Parser,
strip_trailing_ws: bool = False,
validate: bool = True,
tool_segments: Callable[[ToolCallSpec], list[tuple[str, bool]]] = (
_qwen3_tool_segments
),
) -> Sample:
expected_reasoning: str | None
if scenario.reasoning is not None:
@@ -403,7 +413,7 @@ def _build_qwen3(
sample_id=f"{name}-{scenario.id}",
description=scenario.description,
vocab=_QWEN3_VOCAB,
segments=_qwen3_segments(scenario),
segments=_qwen3_segments(scenario, tool_segments),
expected_reasoning=expected_reasoning,
expected_content=_qwen3_expected_content(scenario),
expected_tool_calls=_expected_tc(scenario),
@@ -414,6 +424,31 @@ def _build_qwen3(
return sample
# ── MiMo (compact Qwen3 XML, no newlines between tags) ───────────────
def _mimo_tool_segments(tc: ToolCallSpec) -> list[tuple[str, bool]]:
parts = [f"<function={tc.name}>"]
for key, value in tc.arguments.items():
parts.append(f"<parameter={key}>{_qwen3_arg_value(value)}</parameter>")
parts.append("</function>")
return [
("<tool_call>", True),
("".join(parts), False),
("</tool_call>", True),
]
def _build_mimo(scenario: Scenario, validate: bool = True) -> Sample:
return _build_qwen3(
scenario,
name="mimo",
parser_cls=MiMoParser,
validate=validate,
tool_segments=_mimo_tool_segments,
)
# ── MiniMax M2 (XML invoke format, starts in REASONING) ──────────────
_MINIMAX_M2_VOCAB: dict[str, int] = {
@@ -1232,6 +1267,7 @@ _BUILDERS: dict[str, Any] = {
"glm47_moe": _build_glm47_moe,
"kimi_k2": _build_kimi_k2,
"qwen3": _build_qwen3,
"mimo": _build_mimo,
"inkling": _build_inkling,
"plamo3": _build_plamo3,
}