Skip to content

The agent that grows with you

fix(tools): tool_call rejections restate the single-entry shape and stop misdirecting deferred names

teknium113fc2e1044ba
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..15ead58f930
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1 @@
+whyyagswhy
diff --git a/tests/tools/test_connector_bridge_wiring.py b/tests/tools/test_connector_bridge_wiring.py
index 2bd36a48122..de7237889ad 100644
--- a/tests/tools/test_connector_bridge_wiring.py
+++ b/tests/tools/test_connector_bridge_wiring.py
@@ -79,22 +79,34 @@ def test_resolve_single_connector_entry_returns_sentinel():
assert args["calls"][0]["arguments"] == {"to": "x"}
-def test_resolve_multi_local_batch_requires_separate_calls():
- name, args, err = resolve_underlying_call(
- {"calls": [
- {"name": "some_local_tool", "arguments": {}},
- {"name": "another_local", "arguments": {}},
- ]}
- )
+def test_resolve_multi_local_batch_echoes_first_entry_as_the_retry_shape():
+ # The correction restates the valid single-entry shape with the caller's OWN first
+ # entry (a 9B model re-sent the identical two-entry array when told only the rule).
+ first = {"name": "some_local_tool", "arguments": {"query": "alpha", "limit": 20}}
+ name, args, err = resolve_underlying_call({"calls": [first, {"name": "another_local", "arguments": {}}]})
assert name is None
- assert "one entry per tool_call" in err
+ assert "you sent 2" in err
+ retry = err.split("Retry with only: ", 1)[1].split(" then issue", 1)[0]
+ assert json.loads(retry) == {"calls": [first]}
-def test_resolve_legacy_single_shape_unchanged_for_local_names():
- # Non-deferrable local name keeps the historical rejection message.
+def test_resolve_unknown_name_points_at_tool_search_not_direct_call():
+ # An unregistered name (typically a deferred MCP tool cited by its bare suffix) must
+ # NOT be told "call it directly" — that is the opposite of the required correction.
+ from tools.registry import registry
+
name, args, err = resolve_underlying_call({"name": "not_a_real_tool", "arguments": {}})
assert name is None
- assert "not a deferrable tool" in (err or "")
+ assert "not a known tool name" in err and "call it directly" not in err.lower()
+ registry.register(name="mcp__mempalace__mempalace_search", toolset="mcp-mempalace",
+ handler=lambda a, **kw: "{}",
+ schema={"name": "mcp__mempalace__mempalace_search", "description": "x",
+ "parameters": {"type": "object", "properties": {}}})
+ _, _, err = resolve_underlying_call({"name": "mempalace_search", "arguments": {}})
+ registry.deregister("mcp__mempalace__mempalace_search")
+ assert "Did you mean 'mcp__mempalace__mempalace_search'?" in err
+ _, _, err = resolve_underlying_call({"name": "read_file", "arguments": {}})
+ assert "directly-listed tool" in err and "not a known tool" not in err
def test_resolve_legacy_connector_single_shape_routes_to_sentinel():
@@ -133,6 +145,7 @@ def test_normalize_parses_string_envelope_single_dict():
({"calls": [{"name": "x", "arguments": "not json {"}]}, "not valid JSON"),
({"calls": [{"name": "x", "arguments": 42}]}, "must be an object"),
({"calls": "nope"}, "not valid JSON"),
+ ({"calls": json.dumps({"query": "x"})}, "requires a 'name'"),
],
)
def test_normalize_rejects_malformed_batches(bad, expected_fragment):
diff --git a/tests/tools/test_connector_local_batches.py b/tests/tools/test_connector_local_batches.py
index e055d6eb333..9eb129a424b 100644
--- a/tests/tools/test_connector_local_batches.py
+++ b/tests/tools/test_connector_local_batches.py
@@ -22,13 +22,13 @@ def test_local_batches_rejected_before_any_entry_executes(monkeypatch, mixed):
{"name": "connectors__gmail__SEND_EMAIL" if mixed else "todo_list", "arguments": {}},
]
name, args, error = resolve_underlying_call({"calls": calls})
- assert name is None and "one entry per tool_call" in error
+ assert name is None and "exactly one entry" in error
invoked = []
monkeypatch.setattr(model_tools.registry, "dispatch", lambda *a, **kw: invoked.append(a))
monkeypatch.setattr(bridge, "_default_client_factory", lambda: invoked.append("gateway"))
result = json.loads(model_tools.handle_function_call(
"tool_call", {"calls": calls}, enabled_toolsets=["connections", "session_search", "todo"]))
- assert "one entry per tool_call" in result["error"]
+ assert "exactly one entry" in result["error"]
assert invoked == []
diff --git a/tests/tools/test_tool_search.py b/tests/tools/test_tool_search.py
index 4c6725659d3..cd77ed81496 100644
--- a/tests/tools/test_tool_search.py
+++ b/tests/tools/test_tool_search.py
@@ -581,7 +581,7 @@ class TestRegression_OpenClawCron84141:
"arguments": {"command": "echo hi"},
})
assert err is not None
- assert "not a deferrable" in err
+ assert "directly-listed tool" in err and "call it directly" in err.lower()
class TestRegression_ToolsetScoping:
diff --git a/tests/tools/test_tool_search_multiquery.py b/tests/tools/test_tool_search_multiquery.py
index 0f45c31e477..137658c46b0 100644
--- a/tests/tools/test_tool_search_multiquery.py
+++ b/tests/tools/test_tool_search_multiquery.py
@@ -470,8 +470,8 @@ class TestBatchedDescribe:
))
assert result["errors"][name] == (
- f"'{name}' is not a deferrable tool. If you see it in the tools list "
- "already, call it directly; otherwise check the spelling against tool_search."
+ f"'{name}' is a directly-listed tool, not a deferred one. "
+ "Call it directly instead of via tool_call."
)
assert name not in result.get("not_found", [])
diff --git a/tools/connectors/dispatch.py b/tools/connectors/dispatch.py
index cce9ac1fac4..b3d97aadb48 100644
--- a/tools/connectors/dispatch.py
+++ b/tools/connectors/dispatch.py
@@ -28,7 +28,8 @@ def dispatch_connector_batch(calls, ids, *, user_task, enabled_tools,
"Retry with fewer calls per batch.")
partition = partition_calls(calls)
if partition.local:
- return tool_error("Local tools require one entry per tool_call; mixed and multi-local batches are not supported.")
+ from tools.tool_search_validation import local_batch_error
+ return tool_error(local_batch_error(calls))
entries = list(partition.errors)
for offset, plan in enumerate(partition.remote):
if is_interrupted():
diff --git a/tools/tool_search.py b/tools/tool_search.py
index dedc93929d7..c51a1eb61a0 100644
--- a/tools/tool_search.py
+++ b/tools/tool_search.py
@@ -21,7 +21,8 @@ from tools.tool_search_catalog import (
BRIDGE_TOOL_NAMES, CHARS_PER_TOKEN, TOOL_CALL_NAME, TOOL_DESCRIBE_NAME, TOOL_SEARCH_NAME,
CatalogEntry, _fn, _listing_group_label, _registry_entry, _registry_toolset,
build_catalog, build_catalog_listing_with_form, search_catalog)
-from tools.tool_search_validation import normalize_tool_call_entries, validate_deferred_call_args
+from tools.tool_search_validation import (
+ local_batch_error, normalize_tool_call_entries, not_deferrable_error, 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, remote_schemas_for
@@ -507,9 +508,7 @@ def dispatch_tool_describe(args: Dict[str, Any], *, current_tool_defs: List[Dict
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] = (
- f"'{name}' is not a deferrable tool. If you see it in the tools list "
- "already, call it directly; otherwise check the spelling against tool_search.")
+ errors[name] = not_deferrable_error(name)
else:
not_found.append(name)
result: Dict[str, Any] = {"tools": tools}
@@ -551,19 +550,14 @@ def resolve_underlying_call(args: Dict[str, Any]) -> Tuple[Optional[str], Dict[s
return None, {}, err
if len(entries) > 1 and any(not is_connector_name(e["name"]) for e in entries):
- return None, {}, (
- "Local tools require one entry per tool_call; mixed and multi-local batches are not supported."
- )
+ return None, {}, local_batch_error(entries)
if is_connector_name(entries[0]["name"]):
return CONNECTOR_BATCH_SENTINEL, {"calls": entries}, None
name = entries[0]["name"]
raw_args = entries[0]["arguments"]
if not is_deferrable_tool_name(name, load_config_readonly().effective_defer_tools):
- return None, {}, (
- f"'{name}' is not a deferrable tool. If it appears in the model-facing tools "
- "list already, call it directly instead of via tool_call."
- )
+ return None, {}, not_deferrable_error(name)
return name, raw_args, None
diff --git a/tools/tool_search_validation.py b/tools/tool_search_validation.py
index b6fd04630ed..8ac593717b1 100644
--- a/tools/tool_search_validation.py
+++ b/tools/tool_search_validation.py
@@ -9,7 +9,7 @@ import re
from typing import Any, Dict, List, Optional, Tuple
from tools.registry import tool_error
-from tools.tool_search_catalog import BRIDGE_TOOL_NAMES
+from tools.tool_search_catalog import BRIDGE_TOOL_NAMES, _registry_entry
logger = logging.getLogger("tools.tool_search")
@@ -184,3 +184,49 @@ def normalize_tool_call_entries(args: Dict[str, Any]) -> Tuple[List[Dict[str, An
return [], f"tool_call calls[{position}].arguments must be an object"
entries.append({"name": name, "arguments": raw_args})
return entries, None
+
+
+_ECHO_ARGS_MAX_CHARS = 1500
+
+
+def local_batch_error(entries: List[Dict[str, Any]]) -> str:
+ """Rejection for a multi-entry batch that names a local tool. Restates the valid
+ shape with the caller's OWN first entry: small models re-send an identical batch
+ when told only the constraint, and the echoed payload is what gets them unstuck."""
+ first = entries[0]
+ args = json.dumps(first.get("arguments", {}), ensure_ascii=False, separators=(",", ":"))
+ if len(args) > _ECHO_ARGS_MAX_CHARS:
+ args = "{...}" # keep the correction readable; the model still has its own arguments
+ retry = '{"calls":[{"name":%s,"arguments":%s}]}' % (json.dumps(first["name"], ensure_ascii=False), args)
+ remaining = (f" then issue the remaining {len(entries) - 1} call(s) as separate tool_call invocations"
+ if len(entries) > 1 else "")
+ return (
+ f"tool_call takes exactly one entry for local tools; you sent {len(entries)}. "
+ f"Retry with only: {retry}{remaining}. Only connectors__ names may be batched together."
+ )
+
+
+def not_deferrable_error(name: str) -> 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
+ tool (call it without the bridge) vs. an unknown name — typically a deferred MCP tool
+ cited by its bare suffix instead of the full ``mcp__<server>__<tool>`` name. Telling
+ the second group 'call it directly' is the opposite of what they must do."""
+ try:
+ from toolsets import _HERMES_CORE_TOOLS
+ core = frozenset(_HERMES_CORE_TOOLS)
+ except Exception:
+ core = frozenset()
+ if name in core or _registry_entry(name) is not None:
+ return (f"'{name}' is a directly-listed tool, not a deferred one. "
+ "Call it directly instead of via tool_call.")
+ suffix = f"__{name}"
+ try:
+ from tools.registry import registry
+ candidates = sorted(n for n in registry.get_all_tool_names() if n.endswith(suffix))
+ except Exception:
+ candidates = []
+ hint = (f" Did you mean {', '.join(repr(c) for c in candidates)}?" if candidates
+ else " Use tool_search to find the exact name.")
+ return (f"'{name}' is not a known tool name. Deferred tools must be invoked through tool_call "
+ f"by the exact name tool_search returns (e.g. mcp__<server>__<tool>).{hint}")
diff --git a/website/docs/user-guide/features/tool-search.md b/website/docs/user-guide/features/tool-search.md
index 59dede88ced..bc73ecd601e 100644
--- a/website/docs/user-guide/features/tool-search.md
+++ b/website/docs/user-guide/features/tool-search.md
@@ -179,7 +179,10 @@ need the sign-in.
`tool_call` accepts a batch: `calls` is an array of `{name, arguments}`
entries (a single call is an array of one). Each connector entry in a batch
is dispatched as its own gateway request, one after another; local deferred
-tools stay one entry per `tool_call`. Approvals settle per entry before
+tools stay one entry per `tool_call`. A multi-entry batch that names a local
+tool is rejected with a correction that restates the valid shape using the
+caller's own first entry, and a `calls` value emitted as a JSON string is
+parsed like the array form. Approvals settle per entry before
dispatch, and a `/stop` between entries leaves the unstarted ones unsent
(their slots report `INTERRUPTED`).