Skip to content

The agent that grows with you

chore: merge origin/main (resolve agent/transports/codex.py)

teknium1349f67778f66
diff --cc agent/transports/codex.py
index ad2d3bc86a3,82bf55106a6..2fceb7c5e25
--- a/agent/transports/codex.py
+++ b/agent/transports/codex.py
@@@ -171,33 -175,19 +175,45 @@@ def _xai_prefers_native_web_search() -
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]]:
+def _openai_prefers_native_web_search() -> bool:
+ """True when the active web-search backend selects OpenAI's server-side ``web_search``.
+
+ Same contract as :func:`_xai_prefers_native_web_search` with one deliberate
+ difference: it fails CLOSED (False). A resolution failure must leave the client-side
+ Hermes tool in place rather than swap in a built-in the endpoint might reject.
+
+ Only consulted for the Codex backend (``chatgpt.com/backend-api/codex``); a custom
+ OpenAI-compatible endpoint does not implement the server-side tool.
+ """
+ try:
+ from agent.web_search_registry import get_active_search_provider
+
+ provider = get_active_search_provider()
+ if provider is not None:
+ return getattr(provider, "name", None) == "openai-native"
+
+ from tools.web_tools import _get_search_backend
+
+ return (_get_search_backend() or "").strip().lower() == "openai-native"
+ except Exception: # noqa: BLE001 — a probe failure must not change the request shape
+ return False
+
+
+def _alias_wire_tools(
+ response_tools: Any, params: dict[str, Any], is_xai_responses: bool, is_codex_backend: bool = False,
+) -> tuple[Any, dict[str, str]]:
"""Apply provider-reserved tool-name aliasing; returns ``(tools, {alias: original})`` for THIS request.
xAI: a client ``web_search`` collides with Grok's native search — native mode