The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(codex): alias the tool_search bridge on OpenAI Responses so Codex requests are not rejected
teknium11f4fbd5145d6
diff --git a/agent/transports/codex.py b/agent/transports/codex.pyindex 556aa6c133b..82bf55106a6 100644--- a/agent/transports/codex.py+++ b/agent/transports/codex.py@@ -80,7 +80,11 @@ _PERPLEXITY_RESERVED_TOOL_NAMES = ("people_search","finance_search",)+# xAI and OpenAI Responses (api.openai.com and the ChatGPT Codex backend) reserve ``tool_search``+# for their native Tool Search ("Function 'tool_search.tool_search' not allowed in reserved+# namespace 'tool_search'", #83122 / #95003)._XAI_RESERVED_TOOL_NAMES = ("tool_search",)+_OPENAI_RESPONSES_HOSTS = frozenset({"api.openai.com", "chatgpt.com"})_RESERVED_TOOL_ALIAS_PREFIX = "hermes_"# Reverse map used ONLY when normalize_response runs on a transport that never@@ -171,6 +175,18 @@ def _xai_prefers_native_web_search() -> bool:return True+def _reserves_tool_search(params: dict[str, Any], is_xai_responses: bool) -> bool:+ """True when the Responses endpoint owns the ``tool_search`` namespace (xAI, OpenAI, ChatGPT Codex)."""+ if is_xai_responses or params.get("is_codex_backend") is True:+ return True+ try:+ from utils import base_url_hostname++ return base_url_hostname(str(params.get("base_url") or "")).lower() in _OPENAI_RESPONSES_HOSTS+ except Exception:+ return False++def _alias_wire_tools(response_tools: Any, params: dict[str, Any], is_xai_responses: bool) -> tuple[Any, dict[str, str]]:"""Apply provider-reserved tool-name aliasing; returns ``(tools, {alias: original})`` for THIS request.@@ -214,7 +230,7 @@ def _alias_wire_tools(response_tools: Any, params: dict[str, Any], is_xai_respon# request emits is recorded here and stashed on the transport, so the reverse rewrite in# ``normalize_response`` applies only to aliases that were actually sent (never to a real tool that# merely shares an alias-shaped name).- if is_xai_responses and response_tools:+ if response_tools and _reserves_tool_search(params, is_xai_responses):response_tools, _xai_aliases = _alias_reserved_tools(response_tools, _XAI_RESERVED_TOOL_NAMES)wire_aliases.update(_xai_aliases)return response_tools, wire_aliasesdiff --git a/tests/agent/transports/test_codex_transport.py b/tests/agent/transports/test_codex_transport.pyindex bfc3bc50d0d..ebad312bdc7 100644--- a/tests/agent/transports/test_codex_transport.py+++ b/tests/agent/transports/test_codex_transport.py@@ -1302,13 +1302,23 @@ class TestXaiReservedToolSearchAlias:assert "tool_describe" in namesassert "read_file" in names- def test_non_xai_backend_keeps_tool_search_name(self, transport):+ def test_openai_responses_aliases_reserved_tool_search(self, transport):+ """OpenAI Responses reserves the ``tool_search`` namespace for its native Tool Search (#83122):+ both the ChatGPT Codex backend and api.openai.com get the bridge under ``hermes_tool_search``."""+ for extra in ({"is_codex_backend": True}, {"base_url": "https://api.openai.com/v1"}):+ kw = transport.build_kwargs(+ model="gpt-5.4", messages=[{"role": "user", "content": "hi"}], tools=list(self._TOOLS), **extra,+ )+ names = self._names(kw)+ assert "hermes_tool_search" in names and "tool_search" not in names, extra+ assert transport._last_wire_aliases == {"hermes_tool_search": "tool_search"}++ def test_other_responses_backend_keeps_tool_search_name(self, transport):kw = transport.build_kwargs(model="gpt-5.4",messages=[{"role": "user", "content": "hi"}],tools=list(self._TOOLS),- is_codex_backend=True,- base_url="https://api.openai.com/v1",+ base_url="https://responses-proxy.example.invalid/v1",)names = self._names(kw)assert "tool_search" in names