Clark Farming CompanySoftware Foundry

Agent Stack · Infrastructure

Hermes Agent SQLite Memory Infrastructure

Hermes Agent implements a hybrid persistence architecture combining JSONL session transcripts with SQLite databases for structured indexing, full-text search, and task tracking. This infrastructure emerged organically during the Clark Farming Company Quad buildout (April–May 2026) and is maintained as the primary memory and session-recall system for all agent profiles. The active system consists of two SQLite databas…

needs-reviewinferred-with-source-trail1 source links4 resolved links
wiki/wiki/entities/hermes-agent-sqlite-memory-infrastructure.md

Answer

Hermes Agent implements a hybrid persistence architecture combining JSONL session transcripts with SQLite databases for structured indexing, full-text search, and task tracking. This infrastructure emerged organically during the Clark Farming Company Quad buildout (April–May 2026) and is maintained as the primary memory and session-recall system for all agent profiles. The active system consists of two SQLite databas…

Auto-generated neutral summary from the source page — needs human review before trusted use.

Evidence & Source Cards

Externalhttps://www.sqlite.org/fts5.htmlexternal/unverified

Source Excerpt

Overview

Hermes Agent implements a hybrid persistence architecture combining JSONL session transcripts with SQLite databases for structured indexing, full-text search, and task tracking. This infrastructure emerged organically during the Clark Farming Company Quad buildout (April–May 2026) and is maintained as the primary memory and session-recall system for all agent profiles.

The active system consists of two SQLite databases and a Markdown-based memory layer, managing session history, cross-session search, and per-agent persistent memory across 5 agent profiles (Hermes/CEO, Julius, Cypher, Reacher, Octavius).


Origin Story

Where the Idea Came From

The SQLite memory infrastructure was not designed upfront — it evolved from three converging pressures:

  1. The previous platform's memory failure: The team's previous agent platform promised "learning and growing" agent personas but delivered no persistent memory. Sessions reset, context was lost, and agents had no continuity between conversations. This was the primary motivator for building something better.
  1. Letta's architectural pattern: Research into AI memory architectures (May 2026) revealed Letta's 3-tier memory model: Core memory (RAM), Recall memory (SQLite/PostgreSQL log for episodic history), and Archival memory (cold storage). This demonstrated that lightweight SQL databases could serve as effective episodic memory backends for agents.
  1. Practical necessity at scale: As the Quad grew from 1 to 4 agents (plus CEO), the team needed a way to:

The Hermes Agent framework's hermes_state.py module implements the SessionDB class — a SQLite-backed session store with FTS5 full-text search. This was the foundational piece that made the rest possible.

What Made Our Implementation Unique

While Letta and others use SQLite for episodic recall, the Hermes implementation adds several distinctive layers:


Active Architecture

Database Inventory

DatabasePathPurposeSize
state.db~/.hermes/state.dbCentral session store + message index + FTS search~416 MB
kanban.db~/.hermes/kanban.dbMulti-Agent Orchestration task tracking and workflow state~164 KB

Markdown Memory Files

FilePath PatternPurposeChar Limit
MEMORY.md~/.hermes/memories/MEMORY.md (default) or ~/.hermes/profiles/{name}/memories/MEMORY.mdAgent's own notes — environment facts, conventions, lessons learned2,200 chars
USER.md~/.hermes/memories/USER.md (default) or ~/.hermes/profiles/{name}/memories/USER.mdUser profile — name, role, preferences, communication style1,375 chars

Each agent profile (Julius, Cypher, Reacher, Octavius) has its own memories/ directory under ~/.hermes/profiles/{name}/. The default profile uses ~/.hermes/memories/. These files are injected into the agent's system prompt at session start via the memory tool configuration.

Dual-Storage Pattern

The system uses a write-through dual storage pattern:

User Message → [Agent Loop]
                    ├─→ JSONL append (~/.hermes/sessions/*.jsonl)  [Raw transcript]
                    └─→ SQLite INSERT (state.db)                   [Queryable index]
                              ├─→ messages table (structured data)
                              ├─→ messages_fts (auto-trigger)
                              └─→ messages_fts_trigram (auto-trigger)

Message counts match exactly between JSONL line counts and messages table rows — the system maintains consistency.


Schema Details

State Database (state.db)

#### Sessions Table

Tracks session lifecycle, token usage, costs, and delegation chains:

CREATE TABLE sessions (
    id TEXT PRIMARY KEY,
    source TEXT NOT NULL,              -- 'cli', 'cron', 'discord', 'telegram', 'tui'
    user_id TEXT,
    model TEXT,
    model_config TEXT,
    system_prompt TEXT,
    parent_session_id TEXT,            -- Delegation chain (self-referencing FK)
    started_at REAL NOT NULL,
    ended_at REAL,
    end_reason TEXT,
    message_count INTEGER DEFAULT 0,
    tool_call_count INTEGER DEFAULT 0,
    input_tokens INTEGER DEFAULT 0,
    output_tokens INTEGER DEFAULT 0,
    cache_read_tokens INTEGER DEFAULT 0,
    cache_write_tokens INTEGER DEFAULT 0,
    reasoning_tokens INTEGER DEFAULT 0,
    billing_provider TEXT,
    billing_base_url TEXT,
    billing_mode TEXT,
    estimated_cost_usd REAL,
    actual_cost_usd REAL,
    cost_status TEXT,
    cost_source TEXT,
    pricing_version TEXT,
    title TEXT,
    api_call_count INTEGER DEFAULT 0,
    handoff_state TEXT,
    handoff_platform TEXT,
    handoff_error TEXT,
    FOREIGN KEY (parent_session_id) REFERENCES sessions(id)
);

Indexes:

Current data: 671 sessions, 30,647 messages (as of May 20, 2026). First session: April 2, 2026.

Session sources breakdown:

SourceSessions
Discord380
Cron233
Telegram33
CLI23
TUI2

#### Messages Table

Stores every message in structured form:

CREATE TABLE messages (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    session_id TEXT NOT NULL REFERENCES sessions(id),
    role TEXT NOT NULL,                -- 'system', 'user', 'assistant', 'tool'
    content TEXT,
    tool_call_id TEXT,
    tool_calls TEXT,                   -- JSON
    tool_name TEXT,
    timestamp REAL NOT NULL,
    token_count INTEGER,
    finish_reason TEXT,
    reasoning TEXT,
    reasoning_details TEXT,
    codex_reasoning_items TEXT,
    reasoning_content TEXT,
    codex_message_items TEXT
);

Index: idx_messages_session(session_id, timestamp) — fast per-session retrieval.

#### FTS5 Virtual Tables

Two full-text search indexes with automatic trigger-based updates:

-- Standard tokenization (exact match, boolean operators)
CREATE VIRTUAL TABLE messages_fts USING fts5(content);

-- Trigram indexing (fuzzy/prefix matching)
CREATE VIRTUAL TABLE messages_fts_trigram USING fts5(
    content,
    tokenize='trigram'
);

Triggers (AFTER INSERT/UPDATE/DELETE on messages):

Search examples:

#### State Meta Table

Simple key-value store for global state flags:

CREATE TABLE state_meta (
    key TEXT PRIMARY KEY,
    value TEXT
);

Current entries track completed migration operations (e.g., ghost_session_prune_v1, orphaned_compression_finalize_v1).

Kanban Database (kanban.db)

Built-in Hermes Agent Kanban system for Multi-Agent Orchestration task tracking:

CREATE TABLE tasks (
    -- Task definition, assignment, status
);
CREATE TABLE task_runs (
    -- Execution history per task
);
CREATE TABLE task_events (
    -- Lifecycle events (created, assigned, completed, etc.)
);
CREATE TABLE task_comments (
    -- Agent and user comments on tasks
);

Source excerpt truncated at 220 of 393 lines. Open the canonical wiki path above for the full page.

Relationships

Outbound links

Referenced by

Tags

hermes-agentsqlitememory-managementfts5session-storageagent-architecture