[Frontend] Add the Beam reasoning and tool parsers (#62052)

Signed-off-by: Woosuk Kwon <woosuk@inferact.ai>
Co-authored-by: Bugen Zhao <i@bugenzhao.com>
Co-authored-by: Yoni Gozlan <74535834+yonigozlan@users.noreply.github.com>
Co-authored-by: neilkg <33635204+neilkg@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Woosuk Kwon
2026-10-16 14:08:29 -07:00
committed by GitHub
co-authored by Bugen Zhao Yoni Gozlan neilkg Cursor Claude Opus 5.5
parent 9731f30a03
commit 153a17166e
27 changed files with 4464 additions and 92 deletions
+33 -32
View File
@@ -16,8 +16,6 @@ if TYPE_CHECKING:
logger = init_logger(__name__)
HF_PARSER = "hf"
class ParserManager:
"""Provides a unified Parser by composing reasoning and tool parser adapters."""
@@ -122,8 +120,10 @@ class ParserManager:
tags (``--tool-strict-level``), or ``None`` for the tool
parser's default level.
tokenizer: Tokenizer the composed parser is validated against
at startup (see :meth:`validate_parser_tokenizer`). ``None``
skips the check (e.g. ``skip_tokenizer_init``).
at startup (see :meth:`validate_parser_tokenizer`), including
its `response_template` metadata when a response-template
parser is selected. ``None`` skips the check (e.g.
``skip_tokenizer_init``).
Returns:
A Parser class, or None if neither parser is specified.
@@ -184,39 +184,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,
)
from vllm.parser.response_template import (
response_template_parser_cls,
validate_tokenizer_response_template,
)
template_parsers = {
response_template_parser_cls(parser_cls)
for parser_cls in (reasoning_parser_cls, tool_parser_cls)
if parser_cls is not None
}
template_parser_cls = next(iter(template_parsers - {None}), None)
if template_parser_cls is not None:
if len(template_parsers) > 1:
raise TypeError(
f"--reasoning-parser {reasoning_parser_name} and "
f"--tool-call-parser {tool_parser_name} cannot be combined"
)
if tokenizer is not None:
validate_tokenizer_response_template(
tokenizer,
reasoning=reasoning_parser_cls is not None,
tools=tool_parser_cls is not None,
reasoning_parser=reasoning_parser_name,
# Without auto tool choice, no tool parser is selected.
tool_parser=tool_parser_name if tool_parser_cls else 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
return type(
template_parser_cls.__name__,
(template_parser_cls,),
{
"reasoning_parser_cls": reasoning_parser_cls,
"tool_parser_cls": tool_parser_cls,
"tool_strict_level": strict_level,
"_enable_auto_tools": enable_auto_tools,
},
)
if reasoning_parser_name == "kimi_k3" or tool_parser_name == "kimi_k3":
from vllm.parser.kimi_k3 import KimiK3Parser