Fix parallel tool call parsing bug when tool parameters contain arrays (#16345)

This commit is contained in:
Leoyzen
2026-01-11 11:31:38 +08:00
committed by GitHub
parent 7c25687c9b
commit cf14feba4d
2 changed files with 175 additions and 5 deletions

View File

@@ -166,15 +166,22 @@ class BaseFormatDetector(ABC):
try:
try:
tool_call_pos = current_text.find(self.bot_token)
if tool_call_pos != -1:
start_idx = tool_call_pos + len(self.bot_token)
elif self.current_tool_id > 0 and current_text.startswith(
# Priority check: if we're processing a subsequent tool (current_tool_id > 0),
# first check if text starts with the tool separator. This is critical for
# parallel tool calls because the bot_token (e.g., '[') can also
# appear inside array parameters of the current tool, and we must not
# mistakenly identify that as the start of a new tool.
if self.current_tool_id > 0 and current_text.startswith(
self.tool_call_separator
):
start_idx = len(self.tool_call_separator)
else:
start_idx = 0
# Only search for bot_token if not processing subsequent tool
tool_call_pos = current_text.find(self.bot_token)
if tool_call_pos != -1:
start_idx = tool_call_pos + len(self.bot_token)
else:
start_idx = 0
if start_idx >= len(current_text):
return StreamingParseResult()