[Frontend] Parse tool calls and reasoning from checkpoint response templates (#58604)

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Bugen Zhao <i@bugenzhao.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yoni Gozlan <yonigozlan@users.noreply.github.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
This commit is contained in:
Yoni Gozlan
2026-10-02 02:33:00 +00:00
committed by GitHub
co-authored by Cursor Bugen Zhao Claude Opus 5.5
parent 5a661487e2
commit 9bd993564f
18 changed files with 2298 additions and 21 deletions
+40
View File
@@ -11,10 +11,13 @@ from vllm.tool_parsers.tool_strict_level import ToolStrictLevel
if TYPE_CHECKING:
from vllm.parser.abstract_parser import Parser
from vllm.reasoning import ReasoningParser
from vllm.tokenizers import TokenizerLike
from vllm.tool_parsers import ToolParser
logger = init_logger(__name__)
HF_PARSER = "hf"
class ParserManager:
"""Provides a unified Parser by composing reasoning and tool parser adapters."""
@@ -79,6 +82,7 @@ class ParserManager:
model_name: str | None = None,
is_harmony: bool = False,
tool_strict_level: str = "auto",
tokenizer: TokenizerLike | None = None,
) -> type[Parser] | None:
"""Get a Parser that handles both reasoning and tool parsing.
@@ -93,6 +97,8 @@ class ParserManager:
If True, HarmonyParser is always returned.
tool_strict_level: Server-side floor for tool-call structural
tags (``--tool-strict-level``).
tokenizer: Tokenizer whose `response_template` metadata is
validated when the `hf` parser is selected.
Returns:
A Parser class, or None if neither parser is specified.
@@ -119,6 +125,40 @@ class ParserManager:
HarmonyParser.tool_strict_level = strict_level
return HarmonyParser
if HF_PARSER in (reasoning_parser_name, tool_parser_name):
if {reasoning_parser_name, tool_parser_name} - {
HF_PARSER,
None,
"",
}:
raise TypeError(
"The hf parser cannot be combined with other "
"reasoning or tool call parsers"
)
from vllm.parser.response_template import (
ResponseTemplateParser,
validate_tokenizer_response_template,
)
if tokenizer is not None:
validate_tokenizer_response_template(
tokenizer,
reasoning=reasoning_parser_cls is not None,
tools=tool_parser_cls is not None,
)
r_cls = reasoning_parser_cls
t_cls = tool_parser_cls
auto_tools = enable_auto_tools
class _ResponseTemplateParser(ResponseTemplateParser):
reasoning_parser_cls = r_cls
tool_parser_cls = t_cls
tool_strict_level = strict_level
_enable_auto_tools = auto_tools
return _ResponseTemplateParser
if reasoning_parser_name == "kimi_k3" or tool_parser_name == "kimi_k3":
from vllm.parser.kimi_k3 import KimiK3Parser