fix(tool-describe): separate missing and direct names

This commit is contained in:
alt-glitch
2026-08-23 13:10:07 +05:30
committed by Teknium
parent 1e86a263ed
commit b09f617722
2 changed files with 108 additions and 12 deletions
+67 -6
View File
@@ -245,13 +245,39 @@ class TestBatchedDescribe:
schema = result["tools"]["mq_linear_create_issue"]
assert schema["description"] == "Create a new issue in a team."
assert schema["parameters"]["required"] == ["title", "team"]
# Deferrable-but-absent collects in not_found; found ones still resolve.
assert result["not_found"] == ["mq_out_of_scope_op"]
# Deferrable-but-absent and unknown names collect in not_found; found
# ones still resolve.
assert result["not_found"] == ["mq_out_of_scope_op", "mcp__bogus__missing"]
assert "tool_search" in result["hint"]
# A name unknown to the registry keeps the spelling-check error.
assert "not a deferrable tool" in result["errors"]["mcp__bogus__missing"]
assert "errors" not in result
def test_non_deferrable_name_keeps_per_name_error(self, issue_defs):
def test_real_schemas_and_unknown_name_are_classified_independently(self):
from tools.tool_search import ToolSearchConfig, dispatch_tool_describe
tool_defs = [
_register("mcp__linear__get_issue", "mcp-linear"),
_register("mcp__granola__list_meeting_folders", "mcp-granola"),
]
result = json.loads(dispatch_tool_describe(
{
"names": [
"mcp__linear__get_issue",
"mcp__granola__list_meeting_folders",
"mcp__linear__does_not_exist_zzz",
]
},
current_tool_defs=tool_defs,
config=ToolSearchConfig.from_raw({}),
))
assert set(result["tools"]) == {
"mcp__linear__get_issue",
"mcp__granola__list_meeting_folders",
}
assert result["not_found"] == ["mcp__linear__does_not_exist_zzz"]
assert "errors" not in result
def test_unregistered_core_name_is_not_found(self, issue_defs):
from tools.tool_search import ToolSearchConfig, dispatch_tool_describe
result = json.loads(dispatch_tool_describe(
@@ -260,7 +286,42 @@ class TestBatchedDescribe:
config=ToolSearchConfig.from_raw({}),
))
assert "mq_linear_create_issue" in result["tools"]
assert "not a deferrable tool" in result["errors"]["terminal"]
assert "terminal" in result["not_found"]
assert "errors" not in result
def test_registered_direct_surface_name_keeps_exact_error(self):
from tools.tool_search import ToolSearchConfig, dispatch_tool_describe
name = "mq_desktop_direct_action"
tool_def = _register(name, "desktop_ui")
result = json.loads(dispatch_tool_describe(
{"names": [name]},
current_tool_defs=[tool_def],
config=ToolSearchConfig.from_raw({}),
))
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."
)
assert name not in result.get("not_found", [])
def test_registry_lookup_failure_is_not_found(self, monkeypatch):
from tools.registry import registry
from tools.tool_search import ToolSearchConfig, dispatch_tool_describe
def fail_lookup(name):
raise RuntimeError("registry unavailable")
monkeypatch.setattr(registry, "get_entry", fail_lookup)
result = json.loads(dispatch_tool_describe(
{"names": ["mq_unknown_during_lookup"]},
current_tool_defs=[],
config=ToolSearchConfig.from_raw({}),
))
assert result["not_found"] == ["mq_unknown_during_lookup"]
assert "errors" not in result
def test_duplicates_deduped_silently(self, issue_defs):
from tools.tool_search import ToolSearchConfig, dispatch_tool_describe
+41 -6
View File
@@ -48,7 +48,7 @@ import math
import re
import threading
from dataclasses import dataclass, field
from typing import Any, Dict, Iterable, List, Optional, Tuple
from typing import Any, Dict, Iterable, List, Literal, Optional, Tuple
import snowballstemmer
@@ -204,6 +204,20 @@ def load_config() -> ToolSearchConfig:
return ToolSearchConfig.from_raw(None)
def load_config_readonly() -> ToolSearchConfig:
"""Load tool-search config without copying the cached full config."""
try:
from hermes_cli.config import load_config_readonly as _load
cfg = _load() or {}
tools_cfg = cfg.get("tools") if isinstance(cfg.get("tools"), dict) else {}
if not isinstance(tools_cfg, dict):
tools_cfg = {}
return ToolSearchConfig.from_raw(tools_cfg.get("tool_search"))
except Exception as e:
logger.debug("Failed to load tool-search config: %s", e)
return ToolSearchConfig.from_raw(None)
# ---------------------------------------------------------------------------
# Tool classification
# ---------------------------------------------------------------------------
@@ -256,6 +270,26 @@ def is_deferrable_tool_name(name: str) -> bool:
return False
def _describe_classification(
name: str,
) -> Literal["available", "not_found", "not_deferrable"]:
"""Classify a describe name without treating unknown names as errors."""
try:
from tools.registry import registry
entry = registry.get_entry(name)
except Exception:
return "not_found"
if entry is None:
return "not_found"
if (
name in BRIDGE_TOOL_NAMES
or name in _core_tool_names()
or entry.toolset in _DIRECT_SURFACE_TOOLSETS
):
return "not_deferrable"
return "available"
def classify_tools(tool_defs: List[Dict[str, Any]]) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]]:
"""Split a tool-defs list into (visible, deferrable).
@@ -1087,12 +1121,13 @@ def dispatch_tool_describe(args: Dict[str, Any],
"errors": {"<name>": "..."} # only for non-deferrable names
}
Unknown names land in ``not_found`` instead of failing the whole call;
non-deferrable names (core tools, typos of visible tools) keep their
per-name error message in ``errors``. Duplicates are deduped silently.
Unknown/unregistered names and registered deferrable names absent from the
current assembly land in ``not_found`` instead of failing the whole call.
Registered non-deferrable names keep their per-name message in ``errors``.
Duplicates are deduped silently.
"""
if config is None:
config = load_config()
config = load_config_readonly()
raw_names = args.get("names")
if isinstance(raw_names, str):
@@ -1130,7 +1165,7 @@ def dispatch_tool_describe(args: Dict[str, Any],
"description": fn.get("description", ""),
"parameters": fn.get("parameters", {}),
}
elif not is_deferrable_tool_name(name):
elif _describe_classification(name) == "not_deferrable":
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."