The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tool-search): keep batch caps internal
alt-glitch3b065745ca5e
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex 53a3e5c7bc2..fb3a12a2cb4 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -2848,11 +2848,6 @@ DEFAULT_CONFIG = {# Hard upper bound the model can request via ``limit`` (per# query). Range 1..50."max_search_limit": 25,- # Max queries per tool_search call / names per tool_describe- # call. Over-cap calls error and the model retries with fewer.- # Floor 1, no upper clamp.- "max_queries": 10,- "max_describe_names": 10,# Skills-style catalog listing embedded in the tool_search bridge# description: every deferred tool's name + first sentence of its# description (≤60 chars), grouped by MCP server / toolset. Keepsdiff --git a/tests/tools/test_tool_search.py b/tests/tools/test_tool_search.pyindex d0f24616450..3e2c80e8ad4 100644--- a/tests/tools/test_tool_search.py+++ b/tests/tools/test_tool_search.py@@ -293,14 +293,15 @@ class TestBridgeDispatch:assert "error" in json.loads(result)def test_tool_search_rejects_empty_and_overcap_queries(self):- from tools.tool_search import dispatch_tool_search, ToolSearchConfig- cfg = ToolSearchConfig.from_raw({})- assert "error" in json.loads(dispatch_tool_search(+ import tools.tool_search as tool_search++ cfg = tool_search.ToolSearchConfig.from_raw({})+ assert "error" in json.loads(tool_search.dispatch_tool_search({"queries": []}, current_tool_defs=[], config=cfg))- assert "error" in json.loads(dispatch_tool_search(+ assert "error" in json.loads(tool_search.dispatch_tool_search({"queries": [" ", ""]}, current_tool_defs=[], config=cfg))- over = ["q"] * (cfg.max_queries + 1)- parsed = json.loads(dispatch_tool_search(+ over = ["q"] * (tool_search._MAX_QUERIES_PER_CALL + 1)+ parsed = json.loads(tool_search.dispatch_tool_search({"queries": over}, current_tool_defs=[], config=cfg))assert "error" in parsedassert "too many queries" in parsed["error"]diff --git a/tests/tools/test_tool_search_multiquery.py b/tests/tools/test_tool_search_multiquery.pyindex 3f554dbdf8f..3ed5e735e1a 100644--- a/tests/tools/test_tool_search_multiquery.py+++ b/tests/tools/test_tool_search_multiquery.py@@ -316,14 +316,15 @@ class TestMultiQuerySearch:))assert result["queries"] == ["post slack message"]- def test_max_queries_config_respected(self, issue_defs):- from tools.tool_search import ToolSearchConfig, dispatch_tool_search+ def test_max_query_cap_respected(self, issue_defs, monkeypatch):+ import tools.tool_search as tool_search- cfg = ToolSearchConfig.from_raw({"max_queries": 2})- ok = json.loads(dispatch_tool_search(+ monkeypatch.setattr(tool_search, "_MAX_QUERIES_PER_CALL", 2)+ cfg = tool_search.ToolSearchConfig.from_raw({})+ ok = json.loads(tool_search.dispatch_tool_search({"queries": ["a b", "c d"]}, current_tool_defs=issue_defs, config=cfg))assert "error" not in ok- over = json.loads(dispatch_tool_search(+ over = json.loads(tool_search.dispatch_tool_search({"queries": ["a", "b", "c"]}, current_tool_defs=issue_defs, config=cfg))assert "too many queries" in over["error"]@@ -441,16 +442,17 @@ class TestBatchedDescribe:assert list(result["tools"]) == ["mq_linear_create_issue"]assert "not_found" not in result- def test_empty_and_overcap_names_error(self, issue_defs):- from tools.tool_search import ToolSearchConfig, dispatch_tool_describe+ def test_empty_and_overcap_names_error(self, issue_defs, monkeypatch):+ import tools.tool_search as tool_search- cfg = ToolSearchConfig.from_raw({})- assert "error" in json.loads(dispatch_tool_describe(+ monkeypatch.setattr(tool_search, "_MAX_DESCRIBE_NAMES_PER_CALL", 2)+ cfg = tool_search.ToolSearchConfig.from_raw({})+ assert "error" in json.loads(tool_search.dispatch_tool_describe({}, current_tool_defs=issue_defs, config=cfg))- assert "error" in json.loads(dispatch_tool_describe(+ assert "error" in json.loads(tool_search.dispatch_tool_describe({"names": []}, current_tool_defs=issue_defs, config=cfg))- over = ["n%d" % i for i in range(cfg.max_describe_names + 1)]- parsed = json.loads(dispatch_tool_describe(+ over = ["n%d" % i for i in range(3)]+ parsed = json.loads(tool_search.dispatch_tool_describe({"names": over}, current_tool_defs=issue_defs, config=cfg))assert "too many names" in parsed["error"]@@ -471,26 +473,13 @@ class TestBatchedDescribe:class TestConfigAndSchema:- def test_new_caps_default_and_parse(self):- from tools.tool_search import ToolSearchConfig-- cfg = ToolSearchConfig.from_raw(None)- assert cfg.max_queries >= 1- assert cfg.max_describe_names >= 1- # Operator-tunable with no upper clamp; floored at 1.- big = ToolSearchConfig.from_raw({"max_queries": 500,- "max_describe_names": 500})- assert big.max_queries == 500- assert big.max_describe_names == 500- floored = ToolSearchConfig.from_raw({"max_queries": 0,- "max_describe_names": -3})- assert floored.max_queries == 1- assert floored.max_describe_names == 1-def test_limit_default_within_cap(self):+ from hermes_cli.config_defaults import DEFAULT_CONFIGfrom tools.tool_search import ToolSearchConfig- cfg = ToolSearchConfig.from_raw({})+ cfg = ToolSearchConfig.from_raw(DEFAULT_CONFIG["tools"]["tool_search"])+ assert cfg.max_search_limit == 25+ assert cfg.search_default_limit == 5assert 1 <= cfg.search_default_limit <= cfg.max_search_limit <= 50def test_bridge_schema_declares_array_inputs(self):@@ -500,6 +489,15 @@ class TestConfigAndSchema:search_params = schemas["tool_search"]["parameters"]assert search_params["required"] == ["queries"]assert search_params["properties"]["queries"]["type"] == "array"+ query_description = search_params["properties"]["queries"]["description"]+ assert "single string is accepted" in query_description+ assert "one query" in query_description+ limit_description = search_params["properties"]["limit"]["description"]+ assert "per query" in limit_description+ assert "configured maximum (25 by default)" in limit_descriptiondescribe_params = schemas["tool_describe"]["parameters"]assert describe_params["required"] == ["names"]assert describe_params["properties"]["names"]["type"] == "array"+ name_description = describe_params["properties"]["names"]["description"]+ assert "single string is accepted" in name_description+ assert "one name" in name_descriptiondiff --git a/tools/tool_search.py b/tools/tool_search.pyindex ed7a861bb3a..66f1b198c57 100644--- a/tools/tool_search.py+++ b/tools/tool_search.py@@ -75,6 +75,11 @@ BRIDGE_TOOL_NAMES = frozenset({TOOL_SEARCH_NAME, TOOL_DESCRIBE_NAME, TOOL_CALL_N# underestimating, which is the safer default.CHARS_PER_TOKEN = 4.0+# Bound the work one tool_search bridge call can request.+_MAX_QUERIES_PER_CALL = 10+# Bound the work one tool_describe bridge call can request.+_MAX_DESCRIBE_NAMES_PER_CALL = 10+# ---------------------------------------------------------------------------# Configuration plumbing@@ -94,12 +99,6 @@ class ToolSearchConfig:threshold_pct: float # 0..100search_default_limit: intmax_search_limit: int- # Per-call caps on the model-facing array inputs. ``max_queries`` bounds- # ``tool_search``'s ``queries`` list; ``max_describe_names`` bounds- # ``tool_describe``'s ``names`` list. Over-cap calls error (the model- # repairs in one round-trip) rather than silently truncating.- max_queries: int = 10- max_describe_names: int = 10# Catalog listing ("skills-style" progressive disclosure): when active,# a grouped name + short-description manifest of every deferred tool is# embedded in the tool_search bridge description, so capabilities stay@@ -149,11 +148,6 @@ class ToolSearchConfig:search_default_limit = max(1, min(max_search_limit,_safe_int(raw.get("search_default_limit"), 5)))- # Per-call array caps. Floored at 1 (a non-positive cap would reject- # every call); no upper clamp — deliberately operator-tunable.- max_queries = max(1, _safe_int(raw.get("max_queries"), 10))- max_describe_names = max(1, _safe_int(raw.get("max_describe_names"), 10))-listing_raw = str(raw.get("listing", "auto")).strip().lower()if listing_raw in ("true", "1", "yes"):listing = "on"@@ -170,8 +164,6 @@ class ToolSearchConfig:threshold_pct=threshold_pct,search_default_limit=search_default_limit,max_search_limit=max_search_limit,- max_queries=max_queries,- max_describe_names=max_describe_names,listing=listing,listing_max_tokens=listing_max_tokens,)@@ -835,11 +827,11 @@ def bridge_tool_schemas("queries": {"type": "array","items": {"type": "string"},- "description": "Search queries, each a few keywords describing one capability (e.g. ['create github issue', 'send slack message']). Searched in parallel; results come back grouped per query.",+ "description": "Search queries, each a few keywords describing one capability (e.g. ['create github issue', 'send slack message']). Searched in parallel; results come back grouped per query. A single string is accepted and treated as one query.",},"limit": {"type": "integer",- "description": "Maximum number of matches PER QUERY. Default 5.",+ "description": "Maximum number of matches per query. Defaults to 5 and is clamped to the configured maximum (25 by default).",},},"required": ["queries"],@@ -857,7 +849,7 @@ def bridge_tool_schemas("names": {"type": "array","items": {"type": "string"},- "description": "Exact tool names (as returned by tool_search).",+ "description": "Exact tool names (as returned by tool_search). A single string is accepted and treated as one name.",},},"required": ["names"],@@ -1074,9 +1066,9 @@ def dispatch_tool_search(args: Dict[str, Any],queries = [str(q).strip() for q in raw_queries if str(q or "").strip()]if not queries:return tool_error("queries is required and must contain at least one non-empty string")- if len(queries) > config.max_queries:+ if len(queries) > _MAX_QUERIES_PER_CALL:return tool_error(- f"too many queries: {len(queries)} > max {config.max_queries}. "+ f"too many queries: {len(queries)} > max {_MAX_QUERIES_PER_CALL}. ""Retry with fewer, more targeted queries.")@@ -1153,9 +1145,9 @@ def dispatch_tool_describe(args: Dict[str, Any],names.append(n)if not names:return tool_error("names is required and must contain at least one non-empty string")- if len(names) > config.max_describe_names:+ if len(names) > _MAX_DESCRIBE_NAMES_PER_CALL:return tool_error(- f"too many names: {len(names)} > max {config.max_describe_names}. "+ f"too many names: {len(names)} > max {_MAX_DESCRIBE_NAMES_PER_CALL}. ""Retry with fewer names per call.")diff --git a/website/docs/user-guide/features/tool-search.md b/website/docs/user-guide/features/tool-search.mdindex eef14d25b71..8264594632c 100644--- a/website/docs/user-guide/features/tool-search.md+++ b/website/docs/user-guide/features/tool-search.md@@ -57,9 +57,9 @@ Each query in a `tool_search` call is searched independently against thesame catalog (`limit` applies per query); the per-query groups carry toolnames only, while the shared `tools` map holds each matched tool'sdescription and required parameter names once. Queries are stemmed, so-"issues" finds `create_issue`. When some queries return no matches, the-response includes a single `available_sources` summary of the connected-servers so a lexical miss is not mistaken for a missing capability.+"issues" finds `create_issue`. Each query group that returns no matches+includes an `available_sources` summary of the connected servers so a lexical+miss is not mistaken for a missing capability.`tool_describe` resolves every requested name in one call; unknown namesare reported in `not_found` without failing the rest of the batch.@@ -96,8 +96,6 @@ tools:threshold_pct: 5 # listing budget as a percentage of contextsearch_default_limit: 5max_search_limit: 25- max_queries: 10- max_describe_names: 10listing: auto # embed a grouped name+description catalog manifestlisting_max_tokens: 4000```@@ -108,11 +106,12 @@ tools:| `threshold_pct` | `5` | Listing budget as a percentage of the active model's context length. Range 0–100. || `search_default_limit` | `5` | Hits returned per query when the model calls `tool_search` without a `limit`. || `max_search_limit` | `25` | Hard upper bound the model can request via `limit` (per query). Range 1–50. |-| `max_queries` | `10` | Maximum queries per `tool_search` call. Over-cap calls return an error and the model retries with fewer. No upper clamp. |-| `max_describe_names` | `10` | Maximum names per `tool_describe` call. Same error-and-retry semantics. No upper clamp. || `listing` | `auto` | Embed a skills-style manifest of every deferred tool (name + first sentence of its description, ≤60 chars, grouped by MCP server) in the `tool_search` bridge description. `auto` includes it when it fits the budget (falling back to names-only, then to the tier-2 server summary); `on`/`off` force either way. || `listing_max_tokens` | `4000` | Absolute cap on the embedded listing, regardless of context size. Range 200–60000. Large catalogs degrade to names-only or per-server summaries, keeping full schemas available through search. |+Per-call array caps are internal safety bounds, not configuration. Over-cap+calls return an error so the model can retry with a smaller batch.+### Why the listing existsWithout it, deferred capabilities are *invisible* — live benchmarking showed