[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
@@ -6,7 +6,9 @@ from copy import deepcopy
import pytest
import regex as re
from openai.types.responses import (
CustomTool,
FunctionTool,
ToolChoiceCustom,
ToolChoiceFunction,
WebSearchTool,
)
@@ -21,8 +23,10 @@ from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
from vllm.exceptions import VLLMValidationError
from vllm.tool_parsers.streaming import extract_required_tool_call_streaming
from vllm.tool_parsers.utils import (
custom_tool_parameters,
find_tool_properties,
get_json_schema_from_tools,
iter_response_function_tool_dicts,
)
pytestmark = pytest.mark.cpu_test
@@ -483,6 +487,37 @@ class TestNonFunctionToolsSkipped:
get_json_schema_from_tools(tools=[WEB_SEARCH_TOOL], tool_choice="required")
class TestCustomToolShim:
"""``custom`` tools are shown to the model as a single-string function."""
def test_rendered_as_single_string_function(self):
tool = CustomTool(
type="custom", name="emit_command", description="Emit a command."
)
[tool_dict] = iter_response_function_tool_dicts([tool])
assert tool_dict["type"] == "function"
assert tool_dict["name"] == "emit_command"
assert tool_dict["description"] == "Emit a command."
assert tool_dict["parameters"] == custom_tool_parameters()
assert tool_dict["parameters"]["required"] == ["input"]
def test_forced_tool_choice_sees_custom_tool(self):
tools = [CustomTool(type="custom", name="emit_command"), FUNCTION_TOOL]
schema = get_json_schema_from_tools(tools=tools, tool_choice="required")
assert isinstance(schema, dict)
names = [e["properties"]["name"]["enum"] for e in schema["items"]["anyOf"]]
assert names == [["emit_command"], ["get_weather"]]
named = get_json_schema_from_tools(
tools=tools,
tool_choice=ToolChoiceCustom(type="custom", name="emit_command"),
)
assert named == custom_tool_parameters()
assert (
find_tool_properties(tools, "emit_command")
== custom_tool_parameters()["properties"]
)
class TestMalformedToolSchemaDefs:
"""Malformed `$defs` in caller-supplied tool parameters is a 400, not a 500."""