Initial structural_tag support for tool calling#32202
Initial structural_tag support for tool calling#32202mgoin wants to merge 5 commits intovllm-project:mainfrom
Conversation
Signed-off-by: mgoin <mgoin64@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request introduces support for structural tags in tool calling, which is a great enhancement. It allows for more flexible and native tool call generation by constraining only the JSON arguments instead of the entire model output. The implementation adds a new abstraction in ToolParser and provides a concrete implementation for the Hermes tool format. A new utility module structural_tag_utils.py is added to build the configuration for the backend.
The overall approach is solid, but I've found a critical issue in the new structural_tag_utils.py file that could lead to a runtime crash due to a missing None check. I've provided comments with suggestions to fix this. Please address this to make the implementation more robust.
Signed-off-by: mgoin <mgoin64@gmail.com>
Signed-off-by: mgoin <mgoin64@gmail.com>
| return request | ||
|
|
||
| # Try structural tags first | ||
| # TODO(mgoin): Add support for "auto" tool_choice. It should work with |
There was a problem hiding this comment.
Yesterday I tried testing structural_tag on minimax_m2 and found that structural_tag doesn’t support its minimax:tool_call very well.
The minimax:tool_call format is quite special, and it seems that xgrammar doesn’t support it yet.
#32232
There was a problem hiding this comment.
Do you know if this might work with the guidance backend?
|
Hi @mgoin, what is the current state of this PR? Is this the intended way forward for tool calling using structural tags? There are already PRs that propose constrained auto tool choice with structural tags (e.g. #36891). A consolidated approach would be beneficial because adoption in other tool parsers would be straightforward with the I can contribute to this effort and would be willing to invest some time. @chaunceyjiang : In the Kimi K2 PR (#36891) you mentioned that there are still foundational work for the structural tag integration. Do you have any pointers in that direction as well? |
Purpose
My initial start to attempt progress on #32142
Adds structural tag support for tool calling so that
tool_choice="required"constrains only the JSON arguments region, not the entire output. This allows models to generate their native tool tokens (e.g.,<tool_call>) and any reasoning before the constrained region. Implemented for Hermes parser as reference; other parsers can overrideget_structure_info(). Currently disabled fortool_choice="auto"due to test regressions - needs further investigation into xgrammar trigger behavior.Test Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.