mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-24 19:52:53 +08:00
fix(proxy): keep reserved openai tool names resident during tool search deferral
Pin OpenAI built-in tool names (file_search, web_search, code_interpreter, computer, image_generation) in _OPENAI_TOOL_SEARCH_RESIDENT_NAMES so client-defined tools matching reserved namespaces stay resident without defer_loading. Closes #4752
This commit is contained in:
@@ -4727,7 +4727,16 @@ def strip_unsupported_ccr_retrieve_blocks(messages: Any, tools: Any) -> tuple[An
|
||||
|
||||
_OPENAI_TOOL_SEARCH_TYPE = _RESPONSES_TOOL_SEARCH_TYPE
|
||||
_OPENAI_TOOL_SEARCH_MIN_TOOLS = 12
|
||||
_OPENAI_TOOL_SEARCH_RESIDENT_NAMES = frozenset({"terminal"})
|
||||
_OPENAI_TOOL_SEARCH_RESIDENT_NAMES = frozenset(
|
||||
{
|
||||
"terminal",
|
||||
"file_search",
|
||||
"web_search",
|
||||
"code_interpreter",
|
||||
"computer",
|
||||
"image_generation",
|
||||
}
|
||||
)
|
||||
_OPENAI_TOOL_SEARCH_UNSUPPORTED_CLIENTS = frozenset({"codex", "opencode"})
|
||||
# gpt-5.4 is the first model with Responses tool_search (OpenAI docs). Version-
|
||||
# gated by default; overridable per deployment via a regex in
|
||||
|
||||
@@ -166,6 +166,30 @@ def test_terminal_reserved_namespace_stays_resident():
|
||||
assert tools == snapshot
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tool_name",
|
||||
[
|
||||
"file_search",
|
||||
"web_search",
|
||||
"code_interpreter",
|
||||
"computer",
|
||||
"image_generation",
|
||||
],
|
||||
)
|
||||
def test_reserved_openai_tools_stay_resident(tool_name: str) -> None:
|
||||
tool = _fn(tool_name)
|
||||
tools = [tool] + [_fn(f"peer_{i}") for i in range(11)]
|
||||
snapshot = copy.deepcopy(tools)
|
||||
|
||||
out = inject_tool_search_deferral_openai(tools, "gpt-5.6-terra")
|
||||
|
||||
forwarded = next(t for t in out if t.get("name") == tool_name)
|
||||
assert forwarded == tool
|
||||
assert "defer_loading" not in forwarded
|
||||
assert next(t for t in out if t.get("name") == "peer_0").get("defer_loading") is True
|
||||
assert tools == snapshot
|
||||
|
||||
|
||||
def test_terminal_helper_remains_deferrable():
|
||||
tools = [_fn("terminal_helper")] + [_fn(f"peer_{i}") for i in range(11)]
|
||||
|
||||
@@ -175,9 +199,39 @@ def test_terminal_helper_remains_deferrable():
|
||||
assert helper.get("defer_loading") is True
|
||||
|
||||
|
||||
def test_reserved_helpers_remain_deferrable():
|
||||
tools = [_fn("file_search_helper"), _fn("web_search_client")] + [
|
||||
_fn(f"peer_{i}") for i in range(10)
|
||||
]
|
||||
|
||||
out = inject_tool_search_deferral_openai(tools, "gpt-5.6-terra")
|
||||
|
||||
for name in ("file_search_helper", "web_search_client"):
|
||||
tool = next(t for t in out if t.get("name") == name)
|
||||
assert tool.get("defer_loading") is True
|
||||
|
||||
|
||||
def test_prefixed_core_and_terminal_names_stay_resident():
|
||||
resident = ["_bash", "_read", "_write", "_edit", "_glob", "_grep", "_terminal"]
|
||||
noncore = ["_hub", "_todo", "_eval", "mcp__server__read", "terminal_helper"]
|
||||
resident = [
|
||||
"_bash",
|
||||
"_read",
|
||||
"_write",
|
||||
"_edit",
|
||||
"_glob",
|
||||
"_grep",
|
||||
"_terminal",
|
||||
"_file_search",
|
||||
"_web_search",
|
||||
"_code_interpreter",
|
||||
]
|
||||
noncore = [
|
||||
"_hub",
|
||||
"_todo",
|
||||
"_eval",
|
||||
"mcp__server__read",
|
||||
"terminal_helper",
|
||||
"file_search_helper",
|
||||
]
|
||||
tools = [_fn(name) for name in resident + noncore]
|
||||
|
||||
out = inject_tool_search_deferral_openai(tools, "gpt-5.6-terra")
|
||||
|
||||
Reference in New Issue
Block a user