Architecture & Philosophy

Architecture Overview & Narrow Waist Philosophy

How Hermes Agent achieves high extensibility and low latency through a narrow-waist core design
Hermes Agent Architecture Overview
πŸ“Š Figure 1-1: Hermes Agent Core System Architecture Topology

πŸ“ 1. The Hourglass Paradigm & The "Narrow Waist" Philosophy

When engineering industrial-grade Large Language Model (LLM) agents, developers often make the mistake of overcomplicating the system core by continuously adding specialized interfaces, ad-hoc rules, and custom tools. In an LLM-driven runtime, however, every API call requires sending all available tool schemas to the model. As the number of tools increases, context size grows, processing costs rise, inference speed degrades, and the probability of model hallucinations scales exponentially.

To solve this, Hermes implements a "Narrow Waist" design philosophy, mirroring the hourglass architecture of the Internet protocol suite (TCP/IP):

  • Minimal Core Toolset: Only infrastructural, irreplaceable operations (such as read_file, terminal, web_search, and browser_navigate) are allowed into the core layer. These are statically locked via the _HERMES_CORE_TOOLS list in toolsets.py.
  • Capability Offloading: Most high-level capabilities are dispatched to the edgesβ€”handled via independent sub-agents, external plugins, specialized Model Context Protocol (MCP) servers, or CLI utilities, keeping the core decision layer clean and efficient.

Similar to how IP (Internet Protocol) serves as the minimal, stable waist between diverse transport protocols and physical network mediums, the Hermes Agent core operates as a narrow, stable protocol waist. It coordinates LLM reasoning and routing while leaving domain-specific implementations to sandbox environments and pluggable services.

🧬 2. The Three-Layer Architecture Stack

As illustrated in the system topology diagram, Hermes is organized into three decoupled layers that balance runtime safety, execution performance, and ease of extension:

1. Gateway Layer (The Communication Interface)

The Gateway Layer manages incoming interactions across various protocols. It abstracts platform-specific protocols (such as Feishu/Lark cards, Telegram markdown, and WebSocket JSON-RPC events) into structured message arrays. The gateway handles multi-tenant channel routing, strict message de-duplication, state caching, and interface rendering (e.g. dynamically updating card structures to collapse progress spinners during multi-step runs).

2. Agent Core (The Decision & Execution Engine)

Acting as the "narrow waist," this layer runs the main conversation loop. It coordinates state transitions, session history management, budget tracking, and self-healing. Key components include:

  • SessionDB (in hermes_state.py): Tracks session state with transaction guarantees, WAL logs, and backoff retries.
  • Prompt Caching Protection: Enforces strict schema sorting and role alternation to keep prompt headers byte-identical, achieving optimal cache hit rates.
  • Context Compaction: Automatically summarizes older dialog turns to prevent context window overflows and reduce Token footprint.

3. Sandbox & Tool Layer (The Execution Boundaries)

The bottom layer is where commands are executed. Rather than running tasks directly on the host machine, Hermes enforces strict safety boundaries. Tools are executed inside isolated Unix PTYs (Pseudoterminals) or ephemeral Docker containers, trapping potential side effects and streaming real-time stdout/stderr pipelines back to the client.

Layer / Subsystem Core Modules & Files Primary Responsibility
🧠 Core Decision Loop run_agent.py -> AIAgent
agent/conversation_loop.py
Executes the main loop. Decides when to invoke tools, controls token budgets, and formats responses.
πŸ› οΈ Tool Sanitization model_tools.py
agent/message_sanitization.py
Uses introspection to parse Python functions into schemas, auto-repairs malformed JSON arguments, and enforces schema validity.
πŸ”Œ Communication Gateway gateway/run.py
gateway/platforms/
Deduplicates messages, routes payloads, and manages real-time updates for Feishu cards and Telegram callbacks.
πŸ’» Isolation Sandboxes tools/environments/local.py
tools/environments/docker.py
Spawns Unix PTY streams or controls ephemeral Docker sandboxes to isolate code execution.
🧩 Extension Plugins plugins/
agent/memory_manager.py
Dynamically loads memory providers, vector databases, and reasoning backends without altering the agent core.
⏰ Cron Scheduler cron/scheduler.py
cron/jobs.py
Runs a background daemon for scheduled triggers and implements crash-recovery states.
πŸ”Œ Interoperability acp_adapter/
tools/registry.py
Bridges Hermes with standard MCP (Model Context Protocol) and ACP editors (VSCode, Zed).
πŸ’Ύ State Storage hermes_state.py -> SessionDB Manages session states using SQLite with WAL, dealing with lock contentions via exponential retries.
⚑ Concurrency Engine batch_runner.py Handles high-concurrency batch tasks via a ThreadPoolExecutor, aggregating API rates and token usages.

🧩 3. The Pluggable Registry & Dynamic Discovery

To enable safe and rapid extensibility, Hermes provides a pluggable registry pattern using dynamic imports and Python decorators. Instead of modifying run_agent.py, new capabilities are loaded at boot time by registering custom endpoints:

# Tool Registration & Type Sanitization Example
from tools.registry import registry

@registry.register(
    name="query_knowledge_base",
    description="Queries the enterprise vector store for architecture constraints."
)
def query_knowledge_base(query: str, top_k: int = 5) -> str:
    # Under the hood, Hermes uses typing inspection to generate JSON Schema:
    # - "query" is inferred as type: string
    # - "top_k" is inferred as type: integer with a default of 5
    # Any incoming JSON arguments from LLMs are coerced automatically
    ...

During system boot, model_tools.py triggers `discover_builtin_tools()`, parsing annotations and verifying that no unregistered signatures leak into the LLM prompt. Since the interface rules remain fixed, developers can confidently push new tools or swap models without risking core regressions.

πŸ’‘ Why This Architecture Matters

By decoupling communication protocols at the top and execution sandboxes at the bottom, the Hermes Narrow Waist Core remains small and resilient. This design guarantees O(1) prompt complexity scaling, eliminates cache invalidations, and allows enterprises to securely govern agent execution in production environments.

πŸ›οΈ
Agent Governance & Compliance Notice

When deploying AI Agents at scale, permission isolation, data sanitization, token budget control, and full execution trajectory auditing are crucial for enterprise information security. Hermes Agent provides comprehensive security auditing hooks that integrate seamlessly with the OOMeta AI Governance Platform.

Explore OOMeta Enterprise Governance Solutions β†’

πŸ”— Detailed Sub-Articles

To explore specific configurations, implementations, and sub-systems, proceed to the following detailed topics: