feat(tool-search): lazy-load core tools via defer_core/defer_always_core - #53193
feat(tool-search): lazy-load core tools via defer_core/defer_always_core#53193chrisribe wants to merge 10 commits into
Conversation
|
Overlaps with #40993 and #42551 — key differences: Ours wins: only working e2e implementation (both others miss config threading through Ours lacks: per-platform support (#42551), user-configurable list (#40993/#42551). Happy to port the invocation fix + tests to whichever PR maintainers prefer, or add a Measured on real install: 54% payload reduction, 8,199 tokens saved/call. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for threading the proposed core-deferral classification through the bridge gates. The underlying schema-overhead premise still exists on current main: tools/tool_search.py:150-174 protects every _HERMES_CORE_TOOLS member from deferral.
Problems
defer_coreis not represented inhermes_cli/config.py:2785-2804and is absent fromwebsite/docs/user-guide/features/tool-search.md:74-88; the same document currently states at:18-24that built-ins never defer. The public config contract must be updated with the implementation.- The added
TestDeferCoreTruetests cover helper classification/parsing, but not the runtime assembly plus bridge dispatch paths modified inmodel_tools.pyandagent/tool_executor.py. tools/voice_mode.pyaddspaplay, which is unrelated to this feature and is untested here.
Suggested changes
- Add the default, docs, and an end-to-end scoped bridge test using a temporary config and real registry dispatch.
- Split out the audio-player fallback change.
Automated hermes-sweeper review.
0add293 to
8d1c6f0
Compare
|
Thanks @teknium1 — didn't catch those missing items. Added |
|
Added |
|
Code review done (commit 3ecaa501). Logic correct, no security bypass. Fixed: |
|
@teknium1 please review |
|
This looks very promising, especially for those if us using local inference. Excited to see this released! |
|
release planned? |
|
Hello trying to get this PR more visibility... I know there are a lot of open PRs (over 17k!!) Thanks |
…hema reduction Split _HERMES_CORE_TOOLS into two tiers: - _HERMES_ALWAYS_CORE_TOOLS (8): memory, clarify, todo, session_search, web_search, web_extract, vision_analyze, delegate_task - _HERMES_DEFERRABLE_CORE_TOOLS (26+): terminal, file, browser_*, skills, execute_code, cronjob, tts, ha_*, kanban_*, computer_use Add defer_core: bool to ToolSearchConfig. When true (default with enabled=on), deferrable core tools enter the tool_search catalog and are fetched on demand via tool_search → tool_describe → tool_call bridge. Always-core tools never defer regardless of config. Result: 62,752 → 22,417 bytes per call (64% reduction) for conversational sessions. Full capability preserved — model discovers and calls any tool in one turn via the bridge. All 39 existing tool_search tests pass.
Usage data shows these 3 tools account for 77% of all tool calls: terminal: 175 calls (62%) search_files: 29 calls (10%) read_file: 14 calls ( 5%) Deferring them behind tool_search adds a 2-turn discovery overhead on nearly every non-trivial task, which outweighs the schema savings. They stay always-core; write_file, patch, and heavier tools remain deferrable.
…es + add tests - Remove terminal/read_file/search_files duplicates from DEFERRABLE list - Thread config through resolve_underlying_call so deferred core tools can actually be invoked via tool_call bridge when defer_core=True - Thread config through scoped_deferrable_names for the same reason - Update stale module docstring (core tools invariant is now conditional) - Add tests covering the defer_core=True code paths (was: zero coverage)
- Remove unrelated paplay addition from voice_mode.py - Add defer_core key to DEFAULTS in hermes_cli/config.py with comment - Fix stale 'core tools are NEVER deferred' comment in config - Update tool-search.md: revise info box, add defer_core to config table - Add e2e bridge dispatch test for defer_core=True path
…nly mode When defer_always_core: true is set (alongside defer_core: true), all built-in tools including terminal, memory, and delegate_task are deferred behind the bridge. Only tool_search / tool_describe / tool_call remain visible on every call (~1.6 KB vs ~15 KB with defer_core alone, ~94% reduction from stock Hermes). Changes: - Add defer_always_core field to ToolSearchConfig dataclass - _core_tool_names() returns frozenset() when defer_always_core=True - is_deferrable_tool_name(): None registry entry returns defer_always_core instead of hardcoded False (built-in tools not in registry are now correctly deferrable in fully-lazy mode) - 6 new tests in TestDeferAlwaysCoreTrue covering config parsing, always-core deferral, bridge tool protection, and classify_tools Tested: fresh hermes session with defer_always_core=true sees exactly 3 tools (tool_search, tool_describe, tool_call). All 51 tool_search tests pass.
…dd missing tests Fixes three issues raised in code review: 1. Comment said 'Requires defer_core=True' but it wasn't enforced — could confuse users. Now from_raw() auto-promotes defer_core=True whenever defer_always_core=True, so users only need one flag in config.yaml. 2. Added E2E test: assemble_tool_defs() with defer_always_core=True activates and leaves exactly the 3 bridge tools visible. 3. Added test: scoped_deferrable_names() with defer_always_core=True correctly includes always-core tools (the runtime security gate path). 4. Added test: defer_always_core=True alone (without defer_core=True) correctly auto-promotes defer_core and works as expected. All 54 tool_search tests pass.
f13410b to
b3c5c05
Compare
|
@alt-glitch @teknium1 friendly bump ;) |
|
@OutThisLife maybe ? Sorry expanding pokes, do not want to be a nuisance but. |
|
Quick technical refresh on current HEAD
If maintainers prefer |
Summary
Adds opt-in lazy loading for core tools through the existing
tool_search/tool_describe/tool_callbridge.New config flags:
defer_core: keeps an always-visible safety set and defers the rest of core tools.defer_always_core: defers even always-visible core tools (bridge-only visible set).false-> no behavior change for existing installs.Motivation
Reduce per-call tool schema payload for token and latency efficiency, while preserving access to full capability via the bridge.
Changes
toolsets.py_HERMES_CORE_TOOLSas combined list for compatibility_HERMES_DEFERRABLE_CORE_TOOLSdefinition (prevents NameError duringtoolsetsimport)tools/tool_search.pydefer_coreanddefer_always_coreconfig handlingdefer_always_coreauto-promotesdefer_coremodel_tools.py,agent/tool_executor.pyhermes_cli/config.pyValidation
python3 -m pytest tests/tools/test_tool_search.py -q56 passedhermes --versionstarts successfullyhermes chat -q "ping"returnspongMaintainer notes
_HERMES_CORE_TOOLSremains available as flat combined list).terminaland other tools still route through existing approval/middleware paths (no bypass).