From cae9f38ddae2c7c6f583910d0ff0f5c819c5c12a Mon Sep 17 00:00:00 2001 From: fstandhartinger Date: Mon, 22 Sep 2025 17:55:40 +0200 Subject: [PATCH] Fix LongCat tool call parsing for tool_choice='auto' LongCat models were not properly constrained for tool calls when tool_choice='auto' (default), only working with tool_choice='required'. This caused tool calls to be generated but not parsed correctly. The fix ensures LongCat models get EBNF constraints even for 'auto' mode, eliminating the need to manually set tool_choice='required'. --- python/sglang/srt/function_call/function_call_parser.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/function_call/function_call_parser.py b/python/sglang/srt/function_call/function_call_parser.py index 9f84a6d9cb29..fc7c89706b7a 100644 --- a/python/sglang/srt/function_call/function_call_parser.py +++ b/python/sglang/srt/function_call/function_call_parser.py @@ -59,6 +59,7 @@ def __init__(self, tools: List[Tool], tool_call_parser: str): self.detector = detector self.tools = tools + self.tool_call_parser = tool_call_parser def has_tool_call(self, text: str) -> bool: """ @@ -179,12 +180,14 @@ def get_structure_constraint( ): strict_tag = self.get_structure_tag() return ("structural_tag", strict_tag) - elif tool_choice == "required" or isinstance(tool_choice, ToolChoice): + elif (tool_choice == "required" + or isinstance(tool_choice, ToolChoice) + or (tool_choice == "auto" and self.tool_call_parser == "longcat")): ebnf = self.get_ebnf(tool_choice) return ("ebnf", ebnf) if ebnf is not None else None def get_ebnf( - self, tool_choice: Union[ToolChoice, Literal["required"]] + self, tool_choice: Union[ToolChoice, Literal["required", "auto"]] ) -> Optional[str]: """ Get the EBNF grammar for the specified tool choice.