From e867040fc6624445ffa4b567c157b598d9aed2c8 Mon Sep 17 00:00:00 2001 From: Hudson Xing <1277646412@qq.com> Date: Tue, 3 Feb 2026 12:46:01 -0800 Subject: [PATCH] add streaming parallel tool call test case (#18097) --- python/sglang/test/tool_call_test_runner.py | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/python/sglang/test/tool_call_test_runner.py b/python/sglang/test/tool_call_test_runner.py index fbff56424..1344fce9c 100644 --- a/python/sglang/test/tool_call_test_runner.py +++ b/python/sglang/test/tool_call_test_runner.py @@ -25,6 +25,7 @@ class ToolCallTestParams: test_thinking: bool = False # model-specific, e.g. DeepSeek test_reasoning_usage: bool = False # verify usage.reasoning_tokens > 0 test_parallel: bool = True + test_streaming_parallel: bool = True @dataclass @@ -261,6 +262,36 @@ def _test_parallel(client, model): assert tc and len(tc) >= 2, f"expected >= 2 tool calls, got {len(tc) if tc else 0}" +def _test_streaming_parallel(client, model): + """Streaming with tool_choice=auto should return multiple tool calls.""" + response = _call( + client, + model, + "What is 3+5 and what is the weather in Tokyo?", + tools=[ADD_TOOL, WEATHER_TOOL], + tool_choice="auto", + stream=True, + ) + # collect tool calls from streaming chunks + tool_calls = {} + for chunk in response: + if not chunk.choices[0].delta.tool_calls: + continue + for tc in chunk.choices[0].delta.tool_calls: + idx = tc.index + if idx not in tool_calls: + tool_calls[idx] = {"name": "", "arguments": ""} + if tc.function.name: + tool_calls[idx]["name"] = tc.function.name + if tc.function.arguments: + tool_calls[idx]["arguments"] += tc.function.arguments + assert len(tool_calls) >= 2, f"expected >= 2 tool calls, got {len(tool_calls)}" + for idx, tc in tool_calls.items(): + assert tc["name"], f"tool call {idx} missing function name" + args = json.loads(tc["arguments"]) + assert isinstance(args, dict), f"tool call {idx} arguments not a dict" + + _TESTS = [ ("basic_format", _test_basic_format, "test_basic"), ("streaming", _test_streaming, "test_streaming"), @@ -272,6 +303,7 @@ _TESTS = [ ("thinking", _test_thinking, "test_thinking"), ("reasoning_usage", _test_reasoning_usage, "test_reasoning_usage"), ("parallel", _test_parallel, "test_parallel"), + ("streaming_parallel", _test_streaming_parallel, "test_streaming_parallel"), ]