This document describes the high-level architecture of the Hermes Agent system, focusing on the three-tier architecture, major subsystems, and their technical interactions. Hermes Agent is an AI agent framework designed with self-improvement capabilities, orchestrating interactions between LLMs, a diverse tool registry, and multiple execution environments. run_agent.py1-21
The architecture is organized into three primary tiers:
AIAgent class orchestrates the conversation loop, manages context/memory, and handles tool invocation. run_agent.py17-21 agent/conversation_loop.py1-20Sources: run_agent.py17-21 cli.py5-13 gateway/run.py1-14 hermes_cli/config.py1-13 hermes_cli/auth.py1-20 hermes_cli/main.py1-44 agent/conversation_loop.py1-15 agent/context_compressor.py1-17
The AIAgent class in run_agent.py is the primary engine of the system. It encapsulates the logic for the "Think-Act-Observe" loop, managing the state of a single conversation session. run_agent.py5-21
IterationBudget is exhausted. run_agent.py10-14 run_agent.py116-117agent/conversation_loop.py, which handles model calls, tool dispatching, retries, and post-turn hooks. agent/conversation_loop.py1-15sanitize_context to manage message history and handles reasoning/thought blocks (e.g., <think> tags) to prevent leaking internal chain-of-thought into tool inputs. run_agent.py148 agent/conversation_loop.py124-140estimate_request_tokens_rough to monitor context window usage and ensure model limits are respected. run_agent.py151-153MemoryManager and manages persistent identity via load_soul_md. run_agent.py159-166 agent/memory_manager.py148-149ContextCompressor summarizes past turns to free up space while protecting the most recent messages (the "tail"). run_agent.py157 agent/context_compressor.py1-17AuxiliaryClient. This router resolves the best available secondary backend (OpenRouter, Nous Portal, or local endpoints) to avoid interrupting the main conversation flow. agent/auxiliary_client.py1-41Sources: run_agent.py5-21 run_agent.py148-166 agent/auxiliary_client.py1-41 agent/conversation_loop.py1-15 agent/context_compressor.py1-17
Hermes employs a modular tool dispatch system that bridges natural language requests to code execution across isolated environments.
model_tools.py provides the central registry where tools are defined via get_tool_definitions and executed via handle_function_call. run_agent.py136-141FailoverReason and classify_api_error to handle execution failures gracefully. agent/conversation_loop.py42-43 agent/error_classifier.py71-75cleanup_vm and cleanup_browser to ensure environment stability and resource management. run_agent.py142-144Sources: run_agent.py136-144 model_tools.py136-141 agent/conversation_loop.py42-43 agent/error_classifier.py71-75
The system uses a hierarchical configuration and a multi-provider authentication store.
--tui, --gateway, --model). cli.py8-13 hermes_cli/main.py5-44config.yaml: User-defined settings in ~/.hermes/config.yaml. hermes_cli/config.py5-6.env: Secrets and API keys in ~/.hermes/.env. hermes_cli/config.py6DEFAULT_CONFIG. hermes_cli/config.py139-140The authentication system in hermes_cli/auth.py manages credentials for various providers. It supports:
XAI_ACCESS_TOKEN_REFRESH_SKEW_SECONDS = 3600). hermes_cli/auth.py110-120~/.hermes/auth.json with cross-process file locking. hermes_cli/auth.py4-6Sources: hermes_cli/config.py1-13 hermes_cli/auth.py1-20 hermes_cli/auth.py69-183 hermes_cli/main.py5-44
The system supports multiple concurrent interfaces managed by specialized runners.
The GatewayRunner in gateway/run.py enables multi-platform support (Telegram, Discord, Slack, etc.).
AIAgent instances (_AGENT_CACHE_MAX_SIZE = 128) to prevent unbounded growth in long-lived gateways. gateway/run.py61-68BasePlatformAdapter interface. gateway/run.py2-6 gateway/platforms/base.py1-6/new, /model, /usage) shared across the CLI and Gateway. gateway/run.py56-57cli.py provides a rich interactive terminal interface using prompt_toolkit. cli.py5-13--tui flag, providing a more graphical terminal experience. hermes_cli/main.py5-44Sources: gateway/run.py1-14 gateway/run.py61-68 gateway/platforms/base.py1-6 hermes_cli/main.py5-44
Refresh this wiki
This wiki was recently refreshed. Please wait 3 days to refresh again.