feat: multi-agent architecture — named agents with routing, tool policies, and isolated workspaces#896
feat: multi-agent architecture — named agents with routing, tool policies, and isolated workspaces#896teknium1 wants to merge 3 commits into
Conversation
Allow users to configure a dedicated model for subagents spawned by
delegate_task, so narrowly-scoped subtasks can use a cheaper/faster
model while the parent agent runs on a more powerful one.
Config:
subagent:
model: google/gemini-3-flash-preview
Precedence: explicit model arg > config.subagent.model > parent model.
Cherry-picked from PR #751 by Bartok9, rebased onto current main
with conflict resolution and simplified to model-only override
(provider/base_url/api_key stay inherited from parent — covers the
common case of same-provider model swap via OpenRouter).
Closes #609
Co-authored-by: Bartok Moltbot <bartokmoltbot@users.noreply.github.com>
4 new tests verifying: - Subagent inherits parent model by default - Config model overrides parent model - Explicit model arg overrides config - Graceful fallback when CLI_CONFIG unavailable
…cies, and isolated workspaces
Implements the full multi-agent system for Hermes Agent, allowing a single
installation to host multiple named agents, each with its own model,
personality, toolset, workspace, and session history.
## New Files
- gateway/agent_registry.py: AgentConfig, ToolPolicy, SubagentPolicy,
AgentRegistry, TOOL_PROFILES (minimal/coding/messaging/full), and
normalize_tool_config() for shorthand YAML parsing
- gateway/router.py: BindingRouter with 7-tier deterministic routing
(chat_id > peer > guild+type > guild > platform+type > platform > default)
## Core Changes
- model_tools.py: get_tool_definitions() accepts agent_tool_policy for
per-agent tool filtering; handle_function_call() extended enabled_tools
check to gate ALL tool calls (defense-in-depth)
- gateway/session.py: build_session_key() now accepts agent_id and dm_scope
parameters, replacing hardcoded 'agent:main' with 'agent:{agent_id}'
- tools/memory_tool.py: MemoryStore accepts memory_dir parameter for
per-agent memory isolation
- agent/prompt_builder.py: build_context_files_prompt() accepts
agent_workspace for SOUL.md lookup; build_skills_system_prompt()
accepts agent_skills_dir for per-agent skill overlay
- run_agent.py: AIAgent accepts agent_tool_policy and agent_workspace,
passes policy through to get_tool_definitions()
- gateway/run.py: Initializes AgentRegistry + BindingRouter, resolves
agent per-message in _handle_message(), passes config to _run_agent(),
adds /agents command
- cli.py: --agent flag for selecting named agent profiles, /agents
slash command, agent config override for model/personality/tools
- hermes_cli/config.py: agents/bindings in DEFAULT_CONFIG, version 7
- tools/delegate_tool.py: Configurable max_depth per-agent, tool policy
inheritance from parent to child
## Config Format
agents:
main:
default: true
coder:
model: anthropic/claude-sonnet-4
personality: 'You are a coding assistant.'
tools: coding # or [tool1, tool2] or {profile: x, deny: [...]}
bindings:
- agent: coder
telegram: '-100123456'
## Tests
168 new tests across 3 test files (agent_registry, router, integration).
All 3106 tests pass.
|
excited for this |
|
Thorough read of the full diff, really clean architecture overall. A few things worth flagging before merge: 1.
|
|
Hi, i'm really interested by this feature, need some help ? |
This PR implements the full multi-agent architecture. It is opened for review and discussion, not immediate merge.
What This Does
A single Hermes installation can now host multiple named agents, each with its own model, personality, toolset, workspace, and session history. Messages are routed to specific agents via deterministic binding rules.
Quick Example
Architecture (2 new files, 15 modified, 2489 additions)
New:
gateway/agent_registry.py(~280 lines)apply(tools)pipeline: profile → also_allow → allow → deny (deny always wins)"coding"→ profile,[tools]→ allow-list,{profile: x, deny: [...]}→ full formNew:
gateway/router.py(~130 lines){agent: coder, telegram: "-100123"}normalizes automaticallyModified Files
model_tools.pyget_tool_definitions()acceptsagent_tool_policy;handle_function_call()extendsenabled_toolsto gate ALL callsgateway/session.pybuild_session_key()takesagent_id+dm_scope, replaces hardcoded"agent:main"tools/memory_tool.pyMemoryStoreacceptsmemory_dirfor per-agent memory isolationagent/prompt_builder.pyagent_workspacefor per-agent SOUL.md + skills lookuprun_agent.pyAIAgentacceptsagent_tool_policy+agent_workspacegateway/run.py/agentscommandcli.py--agentflag,/agentscommand, agent config overridehermes_cli/config.pyagents/bindingsin DEFAULT_CONFIG, config version 7hermes_cli/commands.py/agentscommand registeredhermes_cli/main.py--agentCLI argtools/delegate_tool.pymax_depth, tool policy inheritance to childrenDesign Principles
agentskey = single implicit "main" agent, everything works as beforetools: coding(profile),tools: [t1, t2](allow-list),tools: {profile: x, deny: [...]}(full)Common Recipes
Cheap model for Telegram, powerful for CLI (5 lines):
Family-safe WhatsApp bot (no code execution):
Tests
168 new tests across 3 test files:
test_agent_registry.py(86 tests): profiles, policies, normalization, registry, validation, inheritancetest_router.py(59 tests): normalization, tiers, resolution, AND semantics, edge casestest_multi_agent_integration.py(23 tests): session keys, tool filtering, memory isolation, configFull suite: 3106 passed, 0 failed.
Future Work (not in this PR)
hermes agents addwizard, per-agent MCP servers, agent handoffs, agent teamsFull Plan
See
~/.hermes/plans/multi-agent-plan.mdfor the complete 1778-line plan covering research (9 frameworks, 3 protocols, OpenClaw codebase analysis), codebase integration map, UX design, and future roadmap.