From 258f8de91f99b40a4dfb234e55a09e9493c6ece8 Mon Sep 17 00:00:00 2001 From: Joe Rowell Date: Thu, 2 Jul 2026 21:08:37 +0200 Subject: [PATCH] [Bugfix][Tool Parser] poolside_v1: accept tool calls without newline after function name (#47311) Signed-off-by: Joe Rowell --- .../test_poolside_v1_tool_parser.py | 102 ++++++++++++++++++ vllm/tool_parsers/poolside_v1_tool_parser.py | 2 +- 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/tests/tool_parsers/test_poolside_v1_tool_parser.py b/tests/tool_parsers/test_poolside_v1_tool_parser.py index 1f87888616..de6e751e5c 100644 --- a/tests/tool_parsers/test_poolside_v1_tool_parser.py +++ b/tests/tool_parsers/test_poolside_v1_tool_parser.py @@ -220,6 +220,108 @@ def test_responses_extract_tool_calls_with_flat_tools() -> None: assert args["content"] == content +def _weather_tool() -> dict[str, Any]: + return { + "type": "function", + "function": { + "name": "get_weather", + "description": "Get the weather for a city", + "parameters": { + "type": "object", + "properties": {"city": {"type": "string"}}, + "required": ["city"], + }, + }, + } + + +def _build_weather_request(*, tool_choice: str) -> ChatCompletionRequest: + return ChatCompletionRequest.model_validate( + { + "model": "poolside-test", + "messages": [{"role": "user", "content": "weather in Paris?"}], + "tools": [_weather_tool()], + "tool_choice": tool_choice, + } + ) + + +def test_no_newline_after_name_non_streaming() -> None: + request = _build_weather_request(tool_choice="auto") + parser = _make_parser(request) + + model_output = ( + "get_weather" + "cityParis" + "" + ) + + result = parser.extract_tool_calls(model_output, request) + + assert result.tools_called + assert len(result.tool_calls) == 1 + assert result.tool_calls[0].function.name == "get_weather" + args = json.loads(result.tool_calls[0].function.arguments) + assert args == {"city": "Paris"} + + +def test_newline_after_name_still_parses_non_streaming() -> None: + request = _build_weather_request(tool_choice="auto") + parser = _make_parser(request) + + model_output = ( + "get_weather\n" + "city\nParis\n" + "" + ) + + result = parser.extract_tool_calls(model_output, request) + + assert result.tools_called + assert result.tool_calls[0].function.name == "get_weather" + args = json.loads(result.tool_calls[0].function.arguments) + assert args == {"city": "Paris"} + + +def test_no_newline_after_name_streaming() -> None: + request = _build_weather_request(tool_choice="auto") + parser = _make_parser(request) + + model_output = ( + "get_weather" + "cityParis" + "" + ) + + name = "" + args = "" + prev = "" + for ch in model_output: + cur = prev + ch + delta = parser.extract_tool_calls_streaming( + previous_text=prev, + current_text=cur, + delta_text=ch, + previous_token_ids=[], + current_token_ids=[], + delta_token_ids=[], + request=request, + ) + prev = cur + if delta is None: + continue + for tc in delta.tool_calls or []: + if tc.function is None: + continue + if tc.function.name: + name += tc.function.name + if tc.function.arguments: + args += tc.function.arguments + + assert name == "get_weather" + assert json.loads(args) == {"city": "Paris"} + + def _stream_partial_start_token(request: ResponsesRequest): parser = _make_parser(request) delta = parser.tool_call_start_token[0] diff --git a/vllm/tool_parsers/poolside_v1_tool_parser.py b/vllm/tool_parsers/poolside_v1_tool_parser.py index b6b95aa068..1265bccb44 100644 --- a/vllm/tool_parsers/poolside_v1_tool_parser.py +++ b/vllm/tool_parsers/poolside_v1_tool_parser.py @@ -76,7 +76,7 @@ class PoolsideV1ToolParser(ToolParser): self.func_call_regex = re.compile(r".*?", re.DOTALL) self.func_detail_regex = re.compile( - r"([^\n]*)\n(.*)", re.DOTALL + r"\s*([^\n<]+?)\s*\n?\s*(.*?)?", re.DOTALL ) self.func_arg_regex = re.compile( r"(.*?)\s*(.*?)", re.DOTALL