Skip to content

The agent that grows with you

fix(tool_search): a core tool absent from the session never says "use tool_search"

Teknium4388913e20f8
diff --git a/agent/tool_executor.py b/agent/tool_executor.py
index e462df0b19a..b454e593b5d 100644
--- a/agent/tool_executor.py
+++ b/agent/tool_executor.py
@@ -423,10 +423,7 @@ def _unwrap_tool_search_call(
if underlying not in _tool_search_scoped_names(agent):
# Session-gated GUI tools name their missing surface (#120413);
# anything else keeps the generic block.
- return function_name, function_args, (
- _ts.out_of_scope_reason(underlying)
- or f"'{underlying}' is not available in this session. Use tool_search to find tools you can call."
- )
+ return function_name, function_args, _ts.scope_block_reason(underlying)
# Validate before unwrapping: the generic bridge hides the concrete
# parameter schema from provider-native tool-call validation.
scope_block = _ts.validate_deferred_call_args(underlying, underlying_args)
diff --git a/model_tools.py b/model_tools.py
index 2d46e79d1d9..011d32dc90c 100644
--- a/model_tools.py
+++ b/model_tools.py
@@ -741,9 +741,7 @@ def _dispatch_bridge_tool(function_name: str, function_args: dict[str, Any],
# Session-gated GUI tools fail fast with their real reason (#120413):
# tool_search can never surface them in this session.
if underlying_name not in ts.scoped_deferrable_names(current_defs):
- return tool_error(ts.out_of_scope_reason(underlying_name)
- or f"'{underlying_name}' is not available in this session. "
- "Use tool_search to find tools you can call."), None
+ return tool_error(ts.scope_block_reason(underlying_name)), None
# Validate against the deferred tool's concrete schema — the generic
# ``arguments: object`` bridge schema can't enforce it.
probe_err = ts.validate_deferred_call_args(underlying_name, underlying_args)
diff --git a/tests/tools/test_managed_worker_tool_diagnostics.py b/tests/tools/test_managed_worker_tool_diagnostics.py
index de988ee0718..22209aec7d6 100644
--- a/tests/tools/test_managed_worker_tool_diagnostics.py
+++ b/tests/tools/test_managed_worker_tool_diagnostics.py
@@ -14,6 +14,7 @@ import model_tools
import tools.delegate_tool # registers delegate_task in the global registry
from agent import runtime_session_store
from agent.conversation_loop import _invalid_tool_name_error_content
+from tools import tool_search
from tools.tool_search import ToolSearchConfig, dispatch_tool_describe
@@ -42,3 +43,14 @@ def test_outside_a_worker_core_tool_guidance_follows_the_session(monkeypatch, to
monkeypatch.setattr(runtime_session_store, "_worker_process", False)
message = _bridge("clarify", toolsets)
assert expected in message and "managed worker" not in message, message
+
+
+def test_a_deferred_tool_absent_from_the_session_is_not_sent_to_tool_search(monkeypatch):
+ """Deferral is a property of the tool, availability one of the session (``defer: [delegate_task]``)."""
+ monkeypatch.setattr(runtime_session_store, "_worker_process", False)
+ deferred = ToolSearchConfig.from_raw({"defer": ["delegate_task"]})
+ monkeypatch.setattr(tool_search, "load_config_readonly", lambda: deferred)
+ described = json.loads(model_tools.handle_function_call(
+ "tool_describe", {"names": ["delegate_task"]}, enabled_toolsets=["file"]))
+ for message in (_bridge("delegate_task", ["file"]), described["errors"]["delegate_task"]):
+ assert "not available in this execution context" in message and "tool_search" not in message, message
diff --git a/tests/tools/test_preview_scope_gate.py b/tests/tools/test_preview_scope_gate.py
index 378dce603f0..6c09227df5f 100644
--- a/tests/tools/test_preview_scope_gate.py
+++ b/tests/tools/test_preview_scope_gate.py
@@ -63,6 +63,7 @@ def test_unwrap_desktop_scope_not_blocked():
assert block is None and name == "drive_preview"
-def test_non_surface_tool_keeps_generic_message():
+def test_absent_non_surface_core_tool_reports_unavailability():
+ # computer_use is a deferred core tool: absent here, tool_search cannot surface it either.
err = json.loads(_bridge("computer_use", TUI_SCOPE))["error"]
- assert "not available in this session" in err
+ assert "not available in this execution context" in err
diff --git a/tools/tool_search.py b/tools/tool_search.py
index 7d69569bf56..90631843bcf 100644
--- a/tools/tool_search.py
+++ b/tools/tool_search.py
@@ -24,7 +24,8 @@ from tools.tool_search_catalog import (
CatalogEntry, _fn, _listing_group_label, _registry_entry, _registry_toolset,
build_catalog, build_catalog_listing_with_form, search_catalog)
from tools.tool_search_validation import (
- local_batch_error, normalize_tool_call_entries, not_deferrable_error, validate_deferred_call_args)
+ local_batch_error, normalize_tool_call_entries, not_deferrable_error, session_unavailable_error,
+ unavailable_in_session_reason, validate_deferred_call_args)
from tools.connectors import CONNECTOR_BATCH_SENTINEL, is_connector_name
from tools.connectors.search import (
connections_in_scope, connector_entries_by_group, connectors_unavailable, remote_schemas_for)
@@ -508,6 +509,7 @@ def dispatch_tool_describe(args: dict[str, Any], *, current_tool_defs: list[dict
not_found: list[str] = []
undescribed: list[str] = []
errors: dict[str, str] = {}
+ session_names = session_tool_names(current_tool_defs)
for name in names:
fn = by_name.get(name)
remote_fn = remote_schemas.get(name)
@@ -519,10 +521,13 @@ def dispatch_tool_describe(args: dict[str, Any], *, current_tool_defs: list[dict
"parameters": remote_fn.get("parameters", {})}
elif is_connector_name(name):
(undescribed if hosted_failure else not_found).append(name)
+ elif unavailable := session_unavailable_error(name, session_names):
+ # A core tool absent here, deferred or not: tool_search cannot surface it.
+ errors[name] = unavailable
elif _registry_entry(name) is not None and not is_deferrable_tool_name(
name, load_config_readonly().effective_defer_tools):
# Registered but bridge/core/GUI-surface: a real name, wrong door.
- errors[name] = not_deferrable_error(name, session_tool_names(current_tool_defs))
+ errors[name] = not_deferrable_error(name, session_names)
else:
not_found.append(name)
result: dict[str, Any] = {"tools": tools}
@@ -560,6 +565,16 @@ def out_of_scope_reason(name: str) -> Optional[str]:
return None
+def scope_block_reason(name: str) -> str:
+ """Block message for a ``tool_call`` naming a tool outside the session's scope. A core tool
+ (deferred by ``defer:`` or not) names its real reason, since tool_search cannot surface it
+ here; anything else keeps the search hint."""
+ return (out_of_scope_reason(name)
+ or (unavailable_in_session_reason(name)
+ if name in _core_tool_names() and _registry_entry(name) is not None else None)
+ or f"'{name}' is not available in this session. Use tool_search to find tools you can call.")
+
+
def resolve_underlying_call(args: dict[str, Any], session_tool_names: Optional[Iterable[str]] = None,
) -> tuple[Optional[str], dict[str, Any], Optional[str]]:
"""Parse a ``tool_call`` invocation into (underlying_name, args, error_msg).
@@ -592,6 +607,9 @@ def resolve_underlying_call(args: dict[str, Any], session_tool_names: Optional[I
name = entries[0]["name"]
raw_args = entries[0]["arguments"]
+ unavailable = session_unavailable_error(name, session_tool_names)
+ if unavailable:
+ return None, {}, unavailable
if not is_deferrable_tool_name(name, load_config_readonly().effective_defer_tools):
return None, {}, not_deferrable_error(name, session_tool_names)
return name, raw_args, None
@@ -622,6 +640,7 @@ __all__ = [
"normalize_tool_call_entries",
"out_of_scope_reason",
"resolve_underlying_call",
+ "scope_block_reason",
"scoped_deferrable_names",
"search_catalog",
"should_activate",
diff --git a/tools/tool_search_validation.py b/tools/tool_search_validation.py
index 375c147a592..fb9e62f2201 100644
--- a/tools/tool_search_validation.py
+++ b/tools/tool_search_validation.py
@@ -231,6 +231,30 @@ def managed_worker_unavailable_reason(name: str) -> Optional[str]:
return f"'{name}' is not offered in a managed worker turn: {reason}" if reason else None
+def unavailable_in_session_reason(name: str) -> str:
+ """Why a registered tool absent from THIS session cannot be reached, whatever its door.
+
+ Deferral is a property of the tool, availability one of the session: a deferred tool the
+ session does not carry (``defer: [delegate_task]`` in a worker) is no more findable through
+ ``tool_search`` than a stripped core tool is callable directly."""
+ return managed_worker_unavailable_reason(name) or (
+ f"'{name}' is not available in this execution context. "
+ "Don't retry it — state the assumption and proceed with the work.")
+
+
+def session_unavailable_error(name: str, session_tool_names: Optional[Iterable[str]]) -> Optional[str]:
+ """The unavailability message when a core tool is missing from the session's own tool list,
+ whether or not ``defer:`` moved it behind the bridge; None without session context, when
+ the session carries it, or for MCP/plugin/unregistered names (an absent one may be a stale
+ catalog that ``tool_search`` can still refresh). A missing GUI surface keeps its own reason."""
+ if session_tool_names is None or name in set(session_tool_names):
+ return None
+ from tools.tool_search import _core_tool_names, out_of_scope_reason # late: imports this module
+ if name not in _core_tool_names() or _registry_entry(name) is None:
+ return None
+ return out_of_scope_reason(name) or unavailable_in_session_reason(name)
+
+
def not_deferrable_error(name: str, session_tool_names: Optional[Iterable[str]] = None) -> str:
"""Rejection for a ``tool_call`` naming something that is not a deferred tool.
Two different mistakes reach here and need opposite corrections: a directly-listed
@@ -248,9 +272,7 @@ def not_deferrable_error(name: str, session_tool_names: Optional[Iterable[str]]
from tools.tool_search import _core_tool_names # late: tool_search imports this module
if name in _core_tool_names() or _registry_entry(name) is not None:
if session_tool_names is not None and name not in set(session_tool_names):
- return managed_worker_unavailable_reason(name) or (
- f"'{name}' is not available in this execution context. "
- "Don't retry it — state the assumption and proceed with the work.")
+ return unavailable_in_session_reason(name)
return (f"'{name}' is a directly-listed tool, not a deferred one. "
"Call it directly instead of via tool_call.")
suffix = f"__{name}"