[Frontend] Support CustomToolCall in the non-Harmony Responses API (#57322)

Signed-off-by: Shijin Zhang <75300765+Dovis01@users.noreply.github.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
Shijin Zhang
2026-10-12 17:22:55 +08:00
committed by GitHub
co-authored by Chauncey
parent a33d46b471
commit 83773ecdf3
22 changed files with 698 additions and 72 deletions
@@ -4,6 +4,7 @@
from unittest.mock import patch
import pytest
from openai.types.responses import CustomTool, FunctionTool, ResponseCustomToolCall
from openai.types.responses.response_function_tool_call import ResponseFunctionToolCall
from openai.types.responses.response_function_tool_call_output_item import (
ResponseFunctionToolCallOutputItem,
@@ -16,10 +17,14 @@ from openai.types.responses.response_reasoning_item import (
Summary,
)
from vllm.entrypoints.generate.base.protocol import FunctionCall
from vllm.entrypoints.openai.responses.utils import (
_construct_message_from_response_item,
build_response_output_items,
construct_chat_messages_with_tool_call,
construct_input_messages,
decode_custom_tool_input,
decode_custom_tool_input_prefix,
should_continue_final_message,
)
from vllm.exceptions import VLLMValidationError
@@ -248,6 +253,89 @@ class TestResponsesUtils:
assert formatted_item["content"] == "dongyi"
class TestCustomTools:
def test_custom_tool_call_output_item(self):
tools = [
CustomTool(type="custom", name="emit_command", format={"type": "text"}),
FunctionTool(
type="function", name="get_weather", parameters={}, strict=None
),
]
custom, function = build_response_output_items(
reasoning=None,
content=None,
tool_calls=[
FunctionCall(
id="call_1", name="emit_command", arguments='{"input": "pwd"}'
),
FunctionCall(
id="call_2", name="get_weather", arguments='{"city": "Paris"}'
),
],
tools=tools,
)
assert isinstance(custom, ResponseCustomToolCall)
assert (custom.call_id, custom.input) == ("call_1", "pwd")
assert custom.id.startswith("ctc_")
assert isinstance(function, ResponseFunctionToolCall)
assert function.arguments == '{"city": "Paris"}'
def test_custom_tool_history_replays_through_function_shim(self):
messages = construct_chat_messages_with_tool_call(
[
make_reasoning_item(content_text="Run pwd."),
ResponseCustomToolCall(
type="custom_tool_call",
id="ctc_1",
call_id="call_exec",
name="emit_command",
input='echo "hi"',
),
{
"type": "custom_tool_call_output",
"call_id": "call_exec",
"output": "hi",
},
{"role": "user", "content": "Continue"},
]
)
assert messages == [
{
"role": "assistant",
"reasoning": "Run pwd.",
"tool_calls": [
{
"id": "call_exec",
"type": "function",
"function": {
"name": "emit_command",
"arguments": '{"input": "echo \\"hi\\""}',
},
}
],
},
{"role": "tool", "content": "hi", "tool_call_id": "call_exec"},
{"role": "user", "content": "Continue"},
]
def test_decode_custom_tool_input(self):
assert decode_custom_tool_input('{"input": "pwd"}') == "pwd"
assert decode_custom_tool_input('{"cmd": "pwd"}') == '{"cmd": "pwd"}'
assert decode_custom_tool_input('{"file": "a.py"}') == '{"file": "a.py"}'
assert decode_custom_tool_input('{"input": 7}') == '{"input": 7}'
assert decode_custom_tool_input("pwd") == "pwd"
def test_decode_custom_tool_input_prefix(self):
assert decode_custom_tool_input_prefix('{"inp') == ""
assert decode_custom_tool_input_prefix('{"input": "ls \\"dir') == 'ls "dir'
assert decode_custom_tool_input_prefix('{"input": "a\\') == "a"
assert decode_custom_tool_input_prefix('{"input": "\\ud83d') == ""
assert (
decode_custom_tool_input_prefix('{"input": "\\ud83d\\ude00!"}')
== "\U0001f600!"
)
class TestReasoningItemContentPriority:
"""Tests that content is prioritized over summary for reasoning items."""