# largebigbug/hermes-agent architecture

> Architecture diagram of the GitHub repository largebigbug/hermes-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/largebigbug/hermes-agent
- Repository: https://github.com/largebigbug/hermes-agent

## Overview

#### Purpose and principal workflow

Hermes is a multi-surface AI agent: people interact through the CLI, terminal UI, messaging gateway, desktop app, or ACP interface, and the agent runs model-driven turns that can invoke tools, preserve conversation context, and return results. In the main turn workflow, an external user’s message reaches the conversation orchestration, which prepares and sends a model request, handles tool rounds and retries, and can compact context. The README also documents persistent learning, cross-session search, and scheduled automations; the sampled excerpts do not establish all of their runtime wiring.

#### Components

##### User and application entry surfaces
- **Hermes users** — *null repository path*. Initiate conversations through the documented CLI, messaging platforms, desktop, or terminal UI; the README identifies these as product surfaces.
- **Terminal UI input** — `ui-tui/src/app/useInputHandlers.ts`. Handles keyboard and overlay actions and sends gateway RPC requests, including voice recording.
- **Terminal UI turn controller** — `ui-tui/src/app/turnController.ts`. Owns turn-facing UI state and coordination; its imports identify supporting stores and shared app code.
- **Gateway application** — `tui_gateway/server.py`. Implements the TUI gateway server; its source index references the conversation loop and local execution environment.
- **OpenAI-compatible gateway routes** — `gateway/platforms/api_server_openai_routes.py`. Provides API routes for callers that use the gateway’s OpenAI-compatible interface.
- **ACP server** — `acp_adapter/server.py`. Implements the Agent Client Protocol server and coordinates ACP session, command, event, permission, and tool modules.
- **Safe console command engine** — `hermes_cli/console_engine.py`. Registers and validates supported Hermes Console commands, rejecting interactive or otherwise blocked commands.

##### Agent turn and context
- **Conversation orchestration** — `agent/conversation_loop.py`. Drives a user turn through model calls, tool dispatch, retries, fallbacks, compression, and post-turn hooks.
- **Context lifecycle interface** — `agent/context_engine.py`. Defines the context-engine lifecycle, usage tracking, and compression decisions across sessions and turns.
- **Default context compressor** — `agent/context_compressor.py`. Reduces oversized conversation context, including pruning tool output and images while preserving selected turns.
- **Provider and transport subsystem** — `agent/provider_registry.py`. Organizes provider selection; provider-specific adapters and transports are separate modules in `agent/` (the sampled excerpts do not establish their complete call path).

##### Tool execution and persistence
- **Local execution environment** — `tools/environments/local.py`. Implements the local tool environment and references shared environment interfaces and gateway session context.
- **Tool-result spillover storage** — `tools/tool_result_storage.py`. Persists large tool outputs and replaces them with previews and paths, with sandbox-copy and readability handling for remote environments.
- **Runtime configuration** — `hermes_cli/config.py`. Loads, validates, and saves Hermes configuration, including provider and fallback settings.

##### Documented product capabilities
- **Cron scheduler worker** — `cron/scheduler_detached_worker.py`. The README documents unattended scheduled automations and platform delivery; sampled source does not show how this worker dispatches jobs.
- **Learning and memory subsystem** — `agent/memory_manager.py`. The README describes curated memory, skill creation and improvement, and cross-session search; the sampled material does not establish the subsystem’s complete boundaries or wiring.
- **Desktop main process** — `apps/desktop/electron/main.ts`. The repository includes an Electron desktop application; the sampled excerpts do not establish its complete startup or backend-connection flow.

#### Relationships

- **Hermes users -> Terminal UI input**: enter commands and interact with overlays; evidence: `ui-tui/src/app/useInputHandlers.ts`.
- **Terminal UI input -> Terminal UI turn controller**: invokes turn-related input actions; evidence: `ui-tui/src/app/useInputHandlers.ts` (the excerpt imports the controller, but does not show every action’s dispatch).
- **Terminal UI input -> Gateway application**: sends voice-recording RPC; evidence: `ui-tui/src/app/useInputHandlers.ts`.
- **Hermes users -> Gateway application**: initiate TUI gateway sessions; evidence: none (inferred from the product surface documented in the README).
- **Hermes users -> OpenAI-compatible gateway routes**: call the gateway API; evidence: none (inferred from the route component’s role).
- **Hermes users -> ACP server**: connect as ACP clients; evidence: `acp_adapter/server.py` (implements the protocol server; the specific external client is not in the repository).
- **Gateway application -> Conversation orchestration**: references the conversation loop; evidence: `tui_gateway/server.py` (SOURCE INDEX).
- **OpenAI-compatible gateway routes -> Gateway application**: share gateway API and session modules; evidence: `gateway/platforms/api_server_openai_routes.py` (SOURCE INDEX; specific runtime routing is not shown).
- **Conversation orchestration -> Context lifecycle interface**: uses context-engine functionality; evidence: `agent/conversation_loop.py` (SOURCE INDEX).
- **Context lifecycle interface -> Default context compressor**: identifies the compressor as the default implementation; evidence: `agent/context_engine.py` (excerpt).
- **Local execution environment -> Tool-result spillover storage**: the storage module uses environment execution and is designed for host and sandbox paths; evidence: `tools/tool_result_storage.py` (excerpt; caller-side invocation is not established).
- **Conversation orchestration -> Provider and transport subsystem**: prepares and issues model calls; evidence: `agent/conversation_loop.py` (excerpt describes the loop; exact provider-selection wiring is not shown).
- **Safe console command engine -> Runtime configuration**: registers and dispatches supported configuration commands; evidence: `hermes_cli/console_engine.py` (SOURCE INDEX).

#### Coverage limits

The inputs provide a broad tree but only selected excerpts and index references. They do not establish the full CLI startup chain, all gateway routes, provider-selection sequence, tool-dispatch call sites, desktop renderer/backend wiring, or detailed learning and scheduler flows; relationships in those areas are deliberately limited or marked inferred.

Main entry points: [`tui_gateway/server.py`](https://github.com/largebigbug/hermes-agent/blob/main/tui_gateway/server.py) (Gateway application), [`ui-tui/src/app/useInputHandlers.ts`](https://github.com/largebigbug/hermes-agent/blob/main/ui-tui/src/app/useInputHandlers.ts) (Terminal UI input), [`agent/conversation_loop.py`](https://github.com/largebigbug/hermes-agent/blob/main/agent/conversation_loop.py) (Conversation orchestration), [`gateway/platforms/api_server_openai_routes.py`](https://github.com/largebigbug/hermes-agent/blob/main/gateway/platforms/api_server_openai_routes.py) (OpenAI-compatible gateway routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_surfaces["User Surfaces"]
  node_users["Hermes users<br/>External users"]
  node_tui_input["Terminal UI input<br/>Input handlers"]
  node_tui_controller["Terminal UI turn controller<br/>[turnController.ts]"]
  node_gateway["Gateway application<br/>TUI gateway"]
  node_api_routes["OpenAI-compatible gateway routes<br/>API routes"]
  node_acp["ACP server<br/>Protocol server"]
  node_desktop["Desktop main process<br/>Electron process"]
end

subgraph group_turn["Agent Turn"]
  node_conversation["Conversation orchestration<br/>Turn orchestration"]
  node_context["Context lifecycle interface<br/>Context interface"]
  node_compressor["Default context compressor"]
  node_provider["Provider and transport subsystem<br/>Model providers"]
end

subgraph group_runtime["Runtime Services"]
  node_local_env["Local execution environment<br/>Tool environment"]
  node_spillover["Tool-result spillover storage<br/>Output storage"]
  node_config["Runtime configuration<br/>[config.py]"]
  node_console["Safe console command engine<br/>[console_engine.py]"]
end

subgraph group_capabilities["Product Capabilities"]
  node_cron["Cron scheduler worker<br/>Scheduled automation"]
  node_memory["Learning and memory subsystem<br/>Memory management"]
end

node_users -->|"Interact"| node_tui_input
node_tui_input -->|"Turn actions"| node_tui_controller
node_tui_input -->|"Voice RPC"| node_gateway
node_users -.->|"Initiate sessions"| node_gateway
node_users -.->|"Call API"| node_api_routes
node_users -->|"Connect as client"| node_acp
node_gateway -->|"References loop"| node_conversation
node_api_routes -->|"Shares gateway modules"| node_gateway
node_conversation -->|"Uses context engine"| node_context
node_context -->|"Default implementation"| node_compressor
node_local_env -->|"Uses environment execution"| node_spillover
node_conversation -->|"Issues model calls"| node_provider
node_console -->|"Dispatches commands"| node_config

click node_tui_input "https://github.com/largebigbug/hermes-agent/blob/main/ui-tui/src/app/useInputHandlers.ts"
click node_tui_controller "https://github.com/largebigbug/hermes-agent/blob/main/ui-tui/src/app/turnController.ts"
click node_gateway "https://github.com/largebigbug/hermes-agent/blob/main/tui_gateway/server.py"
click node_api_routes "https://github.com/largebigbug/hermes-agent/blob/main/gateway/platforms/api_server_openai_routes.py"
click node_acp "https://github.com/largebigbug/hermes-agent/blob/main/acp_adapter/server.py"
click node_desktop "https://github.com/largebigbug/hermes-agent/blob/main/apps/desktop/electron/main.ts"
click node_conversation "https://github.com/largebigbug/hermes-agent/blob/main/agent/conversation_loop.py"
click node_context "https://github.com/largebigbug/hermes-agent/blob/main/agent/context_engine.py"
click node_compressor "https://github.com/largebigbug/hermes-agent/blob/main/agent/context_compressor.py"
click node_provider "https://github.com/largebigbug/hermes-agent/blob/main/agent/provider_registry.py"
click node_local_env "https://github.com/largebigbug/hermes-agent/blob/main/tools/environments/local.py"
click node_spillover "https://github.com/largebigbug/hermes-agent/blob/main/tools/tool_result_storage.py"
click node_config "https://github.com/largebigbug/hermes-agent/blob/main/hermes_cli/config.py"
click node_console "https://github.com/largebigbug/hermes-agent/blob/main/hermes_cli/console_engine.py"
click node_cron "https://github.com/largebigbug/hermes-agent/blob/main/cron/scheduler_detached_worker.py"
click node_memory "https://github.com/largebigbug/hermes-agent/blob/main/agent/memory_manager.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_users,node_tui_input,node_tui_controller,node_gateway,node_api_routes,node_acp,node_desktop toneBlue
class node_conversation,node_context,node_compressor,node_provider toneAmber
class node_local_env,node_spillover,node_config,node_console toneMint
class node_cron,node_memory toneRose
```

## Components

### User Surfaces

External users and application entry points.

- **Hermes users**: External users
- [Terminal UI input](https://github.com/largebigbug/hermes-agent/blob/main/ui-tui/src/app/useInputHandlers.ts): Input handlers · `ui-tui/src/app/useInputHandlers.ts`
- [Terminal UI turn controller](https://github.com/largebigbug/hermes-agent/blob/main/ui-tui/src/app/turnController.ts): Turn controller · `ui-tui/src/app/turnController.ts`
- [Gateway application](https://github.com/largebigbug/hermes-agent/blob/main/tui_gateway/server.py): TUI gateway · `tui_gateway/server.py`
- [OpenAI-compatible gateway routes](https://github.com/largebigbug/hermes-agent/blob/main/gateway/platforms/api_server_openai_routes.py): API routes · `gateway/platforms/api_server_openai_routes.py`
- [ACP server](https://github.com/largebigbug/hermes-agent/blob/main/acp_adapter/server.py): Protocol server · `acp_adapter/server.py`
- [Desktop main process](https://github.com/largebigbug/hermes-agent/blob/main/apps/desktop/electron/main.ts): Electron process · `apps/desktop/electron/main.ts`

### Agent Turn

Conversation orchestration, context handling, and model transport.

- [Conversation orchestration](https://github.com/largebigbug/hermes-agent/blob/main/agent/conversation_loop.py): Turn orchestration · `agent/conversation_loop.py`
- [Context lifecycle interface](https://github.com/largebigbug/hermes-agent/blob/main/agent/context_engine.py): Context interface · `agent/context_engine.py`
- [Default context compressor](https://github.com/largebigbug/hermes-agent/blob/main/agent/context_compressor.py): Context compressor · `agent/context_compressor.py`
- [Provider and transport subsystem](https://github.com/largebigbug/hermes-agent/blob/main/agent/provider_registry.py): Model providers · `agent/provider_registry.py`

### Runtime Services

Tool execution, configuration, and console command handling.

- [Local execution environment](https://github.com/largebigbug/hermes-agent/blob/main/tools/environments/local.py): Tool environment · `tools/environments/local.py`
- [Tool-result spillover storage](https://github.com/largebigbug/hermes-agent/blob/main/tools/tool_result_storage.py): Output storage · `tools/tool_result_storage.py`
- [Runtime configuration](https://github.com/largebigbug/hermes-agent/blob/main/hermes_cli/config.py): Configuration · `hermes_cli/config.py`
- [Safe console command engine](https://github.com/largebigbug/hermes-agent/blob/main/hermes_cli/console_engine.py): Command engine · `hermes_cli/console_engine.py`

### Product Capabilities

Documented capabilities whose runtime wiring is not established.

- [Cron scheduler worker](https://github.com/largebigbug/hermes-agent/blob/main/cron/scheduler_detached_worker.py): Scheduled automation · `cron/scheduler_detached_worker.py`
- [Learning and memory subsystem](https://github.com/largebigbug/hermes-agent/blob/main/agent/memory_manager.py): Memory management · `agent/memory_manager.py`

## Connections

- Hermes users → Terminal UI input: Interact (evidence: `ui-tui/src/app/useInputHandlers.ts`)
- Terminal UI input → Terminal UI turn controller: Turn actions (evidence: `ui-tui/src/app/useInputHandlers.ts`)
- Terminal UI input → Gateway application: Voice RPC (evidence: `ui-tui/src/app/useInputHandlers.ts`)
- Hermes users → Gateway application: Initiate sessions · Inferred; not shown in the code that was read.
- Hermes users → OpenAI-compatible gateway routes: Call API · Inferred; not shown in the code that was read.
- Hermes users → ACP server: Connect as client (evidence: `acp_adapter/server.py`)
- Gateway application → Conversation orchestration: References loop (evidence: `tui_gateway/server.py`)
- OpenAI-compatible gateway routes → Gateway application: Shares gateway modules (evidence: `gateway/platforms/api_server_openai_routes.py`)
- Conversation orchestration → Context lifecycle interface: Uses context engine (evidence: `agent/conversation_loop.py`)
- Context lifecycle interface → Default context compressor: Default implementation (evidence: `agent/context_engine.py`)
- Local execution environment → Tool-result spillover storage: Uses environment execution (evidence: `tools/tool_result_storage.py`)
- Conversation orchestration → Provider and transport subsystem: Issues model calls (evidence: `agent/conversation_loop.py`)
- Safe console command engine → Runtime configuration: Dispatches commands (evidence: `hermes_cli/console_engine.py`)
