Skip to content

The agent that grows with you

fix: restore TestBridgeDispatch, trim #39797 tests, drop dead execution_guidance_text param

teknium1ef44c1b73ff7
diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py
index 4a1be632308..b460532916b 100644
--- a/agent/prompt_builder.py
+++ b/agent/prompt_builder.py
@@ -466,11 +466,11 @@ OPENAI_MODEL_EXECUTION_GUIDANCE = (
)
-def execution_guidance_text(valid_tool_names=None) -> str:
- """OPENAI_MODEL_EXECUTION_GUIDANCE for the session's toolset (cache-safe: the toolset is fixed per session).
+def execution_guidance_text() -> str:
+ """OPENAI_MODEL_EXECUTION_GUIDANCE as injected into the system prompt.
The guidance names no web tool (#39797: a hard "use web_search" overrode SOUL.md and dangled in Blank Slate),
- so the text is the same for every toolset; the seam stays so a future toolset-dependent line has a home.
+ so the text is toolset-neutral and needs no per-session filtering.
"""
return OPENAI_MODEL_EXECUTION_GUIDANCE
diff --git a/agent/system_prompt.py b/agent/system_prompt.py
index de0a7743197..f660e3b7de1 100644
--- a/agent/system_prompt.py
+++ b/agent/system_prompt.py
@@ -546,7 +546,7 @@ def _guidance_parts(agent: Any) -> List[str]:
parts.append(GOOGLE_MODEL_OPERATIONAL_GUIDANCE)
if _model_gate(getattr(agent, "_execution_guidance", "auto"), agent.model, EXECUTION_GUIDANCE_MODELS):
from agent.prompt_builder import execution_guidance_text
- parts.append(execution_guidance_text(agent.valid_tool_names))
+ parts.append(execution_guidance_text())
return parts
diff --git a/tests/agent/test_phantom_tool_references.py b/tests/agent/test_phantom_tool_references.py
index 6e5a5530520..3128e20dc7f 100644
--- a/tests/agent/test_phantom_tool_references.py
+++ b/tests/agent/test_phantom_tool_references.py
@@ -26,25 +26,11 @@ class TestHermesAgentHelpGuidance:
class TestExecutionGuidanceText:
- def test_full_text_when_web_search_available(self):
- from agent.prompt_builder import (
- OPENAI_MODEL_EXECUTION_GUIDANCE,
- execution_guidance_text,
- )
- assert execution_guidance_text({"web_search", "terminal"}) == (
- OPENAI_MODEL_EXECUTION_GUIDANCE
- )
-
- def test_full_text_when_toolset_unknown(self):
- from agent.prompt_builder import (
- OPENAI_MODEL_EXECUTION_GUIDANCE,
- execution_guidance_text,
- )
- assert execution_guidance_text(None) == OPENAI_MODEL_EXECUTION_GUIDANCE
-
def test_no_web_tool_named_without_web_tools(self):
- from agent.prompt_builder import execution_guidance_text
- text = execution_guidance_text({"terminal", "read_file"})
+ # #39797: naming web_search here overrode SOUL.md and dangled when the web toolset was off.
+ from agent.prompt_builder import OPENAI_MODEL_EXECUTION_GUIDANCE, execution_guidance_text
+ text = execution_guidance_text()
+ assert text == OPENAI_MODEL_EXECUTION_GUIDANCE
assert "web_search" not in text and "web_extract" not in text
# The surrounding structure survives.
assert "<mandatory_tool_use>" in text
diff --git a/tests/agent/test_prompt_builder.py b/tests/agent/test_prompt_builder.py
index 935ab50295c..af573630926 100644
--- a/tests/agent/test_prompt_builder.py
+++ b/tests/agent/test_prompt_builder.py
@@ -1092,10 +1092,6 @@ class TestOpenAIModelExecutionGuidance:
assert "correctness" in text
- def test_guidance_does_not_mandate_specific_web_tool(self):
- # #39797: naming web_search here overrode SOUL.md and dangled when the web toolset was off.
- assert "web_search" not in OPENAI_MODEL_EXECUTION_GUIDANCE
- assert "web_extract" not in OPENAI_MODEL_EXECUTION_GUIDANCE
def test_guidance_is_string(self):
assert isinstance(OPENAI_MODEL_EXECUTION_GUIDANCE, str)
diff --git a/tests/tools/test_browser_cdp_tool.py b/tests/tools/test_browser_cdp_tool.py
index 94fa1ea2b0a..fed1b9c6f5b 100644
--- a/tests/tools/test_browser_cdp_tool.py
+++ b/tests/tools/test_browser_cdp_tool.py
@@ -467,13 +467,6 @@ def test_nested_unflagged_binary_path_passes_through(cdp_server):
# ---------------------------------------------------------------------------
-def test_schema_description_is_toolset_neutral():
- """#39797: the static schema must not name web_extract — model_tools adds it only when the session has it."""
- desc = browser_cdp_tool.BROWSER_CDP_SCHEMA["description"]
- assert browser_cdp_tool.CDP_DOCS_URL in desc
- assert "web_extract" not in desc
-
-
# ---------------------------------------------------------------------------
# Private-network guard
# ---------------------------------------------------------------------------
diff --git a/tests/tools/test_browser_hardening.py b/tests/tools/test_browser_hardening.py
index 0c68118677f..3361b56f8ca 100644
--- a/tests/tools/test_browser_hardening.py
+++ b/tests/tools/test_browser_hardening.py
@@ -50,17 +50,6 @@ class TestDeadCodeRemoval:
assert "browser_close" not in names
-class TestBrowserNavigateSchemaToolReferences:
- def test_static_description_is_toolset_neutral(self):
- from tools.browser_tool import BROWSER_TOOL_SCHEMAS
-
- schema = next(item for item in BROWSER_TOOL_SCHEMAS if item["name"] == "browser_navigate")
- description = schema["description"]
-
- assert "web_search" not in description
- assert "web_extract" not in description
-
-
# ---------------------------------------------------------------------------
# Caching: _find_agent_browser
# ---------------------------------------------------------------------------
diff --git a/tests/tools/test_model_tools.py b/tests/tools/test_model_tools.py
index ffb3e393ebf..0d933576793 100644
--- a/tests/tools/test_model_tools.py
+++ b/tests/tools/test_model_tools.py
@@ -532,9 +532,48 @@ class TestDisabledToolsetsPostureToolset:
assert "write_file" not in no_file
-# ==================================================================
+# =========================================================================
+# Tool Search bridge dispatch
+# =========================================================================
+
+class TestBridgeDispatch:
+ """handle_function_call routes tool_search/tool_describe inline, unwraps tool_call,
+ and refuses tool_call targets outside the session-scoped deferrable catalog."""
+
+ def test_tool_search_and_describe_return_json_strings(self):
+ with patch("model_tools.get_tool_definitions", return_value=[]):
+ out = handle_function_call("tool_search", {"queries": ["anything"]})
+ assert isinstance(out, str) and json.loads(out) is not None
+ out = handle_function_call("tool_describe", {"names": ["nope"]})
+ assert isinstance(out, str) and json.loads(out) is not None
+
+ def test_tool_call_bad_args_error(self):
+ with patch("model_tools.get_tool_definitions", return_value=[]):
+ result = json.loads(handle_function_call("tool_call", {}))
+ assert "requires 'calls'" in result["error"]
+
+ def test_tool_call_rejects_out_of_scope_and_unwraps_in_scope(self):
+ import tools.tool_search as ts
+ with patch("model_tools.get_tool_definitions", return_value=[]), \
+ patch.object(ts, "resolve_underlying_call", return_value=("mcp_x", {"a": 1}, None)), \
+ patch.object(ts, "scoped_deferrable_names", return_value=frozenset()):
+ result = json.loads(handle_function_call("tool_call", {"name": "mcp_x"}))
+ assert "not available in this session" in result["error"]
+
+ with patch("model_tools.get_tool_definitions", return_value=[]), \
+ patch.object(ts, "resolve_underlying_call", return_value=("mcp_x", {"a": 1}, None)), \
+ patch.object(ts, "scoped_deferrable_names", return_value=frozenset({"mcp_x"})), \
+ patch.object(ts, "validate_deferred_call_args", return_value=None), \
+ patch("model_tools.registry.dispatch", return_value='{"ok": true}') as disp:
+ out = handle_function_call("tool_call", {"name": "mcp_x"}, task_id="t")
+ assert json.loads(out) == {"ok": True}
+ assert disp.call_args.args[0] == "mcp_x" and disp.call_args.args[1] == {"a": 1}
+# =========================================================================
+# Browser schema retrieval hints
+# =========================================================================
+
class TestBrowserRetrievalHints:
"""Browser schemas name web_search/web_extract only when the session actually has them (#39797)."""
@@ -551,9 +590,13 @@ class TestBrowserRetrievalHints:
assert "web_extract" in out["browser_cdp"]
def test_silent_without_web_tools(self):
+ # Real static schemas + rewriters: the rewritten browser descriptions must not mention absent web tools.
from model_tools import _apply_dynamic_schemas
+ from tools.browser_cdp_tool import BROWSER_CDP_SCHEMA
+ from tools.browser_tool import BROWSER_TOOL_SCHEMAS
- rendered = " ".join(d["function"]["description"]
- for d in _apply_dynamic_schemas(self._defs("browser_navigate", "browser_cdp", "terminal")))
+ navigate = next(s for s in BROWSER_TOOL_SCHEMAS if s["name"] == "browser_navigate")
+ defs = [{"type": "function", "function": navigate}, {"type": "function", "function": BROWSER_CDP_SCHEMA}]
+ rendered = " ".join(d["function"]["description"] for d in _apply_dynamic_schemas(defs + self._defs("terminal")))
assert "web_search" not in rendered
assert "web_extract" not in rendered