[Bugfix][Tool Parser] Use LongCat tags in the LongCat structural tag (#60747)

Signed-off-by: hpdkhoa <hpdkhoa2311@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
Kai Hoang
2026-10-08 21:20:54 -07:00
committed by GitHub
co-authored by Claude Opus 5.5 Flora Feng
parent 9824159d94
commit e31b823bf5
3 changed files with 94 additions and 27 deletions
+2
View File
@@ -9,6 +9,8 @@ from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser
class LongcatFlashToolParser(Hermes2ProToolParser):
structural_tag_model = "longcat"
def __init__(self, tokenizer: TokenizerLike, tools: list[Tool] | None = None):
super().__init__(tokenizer, tools)
+53 -27
View File
@@ -79,7 +79,7 @@ XGRAMMAR_BUILTIN_STRUCTURAL_TAG_MODELS = frozenset(
}
)
VLLM_BUILTIN_STRUCTURAL_TAG_MODELS = frozenset(
{"glm_4_7", "hermes", "hy_v4", "kimi_k3", "plamo3"}
{"glm_4_7", "hermes", "hy_v4", "kimi_k3", "longcat", "plamo3"}
)
SUPPORTED_STRUCTURAL_TAG_MODELS = (
XGRAMMAR_BUILTIN_STRUCTURAL_TAG_MODELS | VLLM_BUILTIN_STRUCTURAL_TAG_MODELS
@@ -346,15 +346,19 @@ def get_function_parameters(function) -> dict[str, Any] | bool:
return function.parameters if function.parameters is not None else True
def _hermes_tool_tags(tools: list[FunctionToolParam]) -> list[TagFormat]:
def _hermes_tool_tags(
tools: list[FunctionToolParam],
start_tag: str,
end_tag: str,
) -> list[TagFormat]:
arguments_field_prefix = '", "arguments": '
formats = [
# <tool_call>
# {"name": "t1", "arguments": {"q": "v"}}
# </tool_call>
('<tool_call>\n{"name": "', "}\n</tool_call>"),
(start_tag + '\n{"name": "', "}\n" + end_tag),
# <tool_call>{"name": "t1", "arguments": {"q": "v"}}</tool_call>
('<tool_call>{"name": "', "}</tool_call>"),
(start_tag + '{"name": "', "}" + end_tag),
]
return [
@@ -370,6 +374,36 @@ def _hermes_tool_tags(tools: list[FunctionToolParam]) -> list[TagFormat]:
]
def _hermes_style_structural_tag(
tools: list[FunctionToolParam],
tool_choice: SimplifiedToolChoice,
start_tag: str,
end_tag: str,
) -> StructuralTag:
tags = _hermes_tool_tags(tools, start_tag, end_tag)
if tool_choice == "auto":
suffix_tag = (
TriggeredTagsFormat(triggers=[start_tag], tags=tags)
if tags
else AnyTextFormat()
)
elif tool_choice == "forced":
suffix_tag = TagsWithSeparatorFormat(
tags=tags,
separator="",
at_least_one=True,
stop_after_first=True,
)
else:
suffix_tag = TagsWithSeparatorFormat(
tags=tags,
separator="",
at_least_one=True,
)
return StructuralTag(format=suffix_tag)
@register_vllm_structural_tag("hermes")
def get_hermes_structural_tag(
tools: list[FunctionToolParam],
@@ -379,31 +413,23 @@ def get_hermes_structural_tag(
token_suffix: str = "",
) -> StructuralTag:
del builtin_tools, reasoning, token_suffix
return _hermes_style_structural_tag(
tools, tool_choice, "<tool_call>", "</tool_call>"
)
tool_call_trigger = "<tool_call>"
if tool_choice == "auto":
tags = _hermes_tool_tags(tools)
suffix_tag = (
TriggeredTagsFormat(triggers=[tool_call_trigger], tags=tags)
if tags
else AnyTextFormat()
)
elif tool_choice == "forced":
suffix_tag = TagsWithSeparatorFormat(
tags=_hermes_tool_tags(tools),
separator="",
at_least_one=True,
stop_after_first=True,
)
else:
suffix_tag = TagsWithSeparatorFormat(
tags=_hermes_tool_tags(tools),
separator="",
at_least_one=True,
)
return StructuralTag(format=suffix_tag)
@register_vllm_structural_tag("longcat")
def get_longcat_structural_tag(
tools: list[FunctionToolParam],
builtin_tools: list[BuiltinToolParam],
tool_choice: SimplifiedToolChoice,
reasoning: bool,
token_suffix: str = "",
) -> StructuralTag:
del builtin_tools, reasoning, token_suffix
return _hermes_style_structural_tag(
tools, tool_choice, "<longcat_tool_call>", "</longcat_tool_call>"
)
def _minimax_tool_tags(tools: list[FunctionToolParam]) -> list[TagFormat]: