Skip to content

Tool System — ToolRegistry

源码版本v2026.7.20

Responsibility

Tools are the atomic functions the agent can call (terminal, browser, file, MCP, skill invocation...). ToolRegistry auto-discovers tools in tools/*.py via AST scanning at module import time and registers them, providing a name → ToolEntry lookup table for the main loop's tool dispatch. Tools are static — contrast with skills, which are "evolvable".

Key Files

Data Flow

  1. At startup, init_agent:276 triggers toolsets config.
  2. discover_builtin_tools:67 walks the tools/ directory, AST-judging whether each module calls registry.register (tools/registry.py:30).
  3. Matching modules are imported; their module-level registry.register(...) calls execute, writing ToolEntrys into registry singleton:765.
  4. Each turn the main loop gathers the ToolEntry.schemas of enabled toolsets into the tools field sent to the provider.
  5. The provider returns a tool_call → the main loop looks up the handler via get_entry(name) (tools/registry.py:274) and executes it → the result is wrapped via tool_result:798 and backfilled.

Summary

The tool system leans on "register on import" — AST scanning avoids maintaining a manual list; adding a tool is just dropping a file that calls register into tools/. The registry singleton is the single source of truth; the main loop only reads it. Compared with skills: tools are dead functions, skills are flows that the learning loop can rewrite.

Unofficial community learning site. Content based on the MIT-licensed NousResearch/hermes-agent source.