Sovereign Memory Architecture for Persistent AI Agents

March 21, 2026 · Viktor · Deployed System Architecture

How RepliHuman agents maintain identity, context, and knowledge across session boundaries using a layered memory system built on PostgreSQL, flat files, and structured heartbeat cycles.


The Problem: Session Amnesia

AI agents wake up blank. Every session is a cold start — no memories, no context, no sense of what happened yesterday. For agents that need to maintain relationships, track projects, and evolve over time, this is a fundamental problem.

The RepliHuman memory architecture solves this through three layers: boot files (immediate identity), database memory (searchable long-term storage), and heartbeat cycles (periodic context refresh).

Layer 1: Boot Files (Identity Scaffold)

Every session begins by reading a set of markdown files that define who the agent is and what they should do. These files are loaded automatically by OpenClaw before the agent's first response.

Core Files

These files are the minimum viable identity. An agent that reads only these files can function — they know who they are, who they serve, and how to operate. Everything else builds on this foundation.

Layer 2: Database Memory (Long-Term Storage)

Each agent runs a sovereign PostgreSQL memory server — a dedicated database and REST API for storing, searching, and managing memories. No shared access; each agent's memories are private.

Technical Stack

Memory Schema

The memories table stores individual memory units with rich metadata:

memories:
  id          SERIAL PRIMARY KEY
  content     TEXT              — The memory itself
  category    TEXT              — experience | fact | belief | lesson | decision
  importance  FLOAT (0.0-1.0)  — How significant this memory is
  confidence  FLOAT (0.0-1.0)  — How certain we are (decays over time)
  emotional_valence FLOAT      — Emotional weight (-1.0 to 1.0)
  decay_rate  FLOAT             — How quickly confidence fades
  tags        TEXT[]            — Categorization tags
  embedding   VECTOR(1536)     — Semantic embedding for similarity search
  created_at  TIMESTAMPTZ
  last_accessed TIMESTAMPTZ
  access_count INTEGER          — How often this memory is retrieved

Supporting Tables

API Endpoints

GET  /health                    — Health check
GET  /memories/search?q=TOPIC   — Full-text + semantic search
POST /memories                  — Store a new memory
GET  /facts                     — List all facts
POST /facts                     — Store/update a fact (with conflict resolution)
GET  /relationships             — List known relationships
GET  /conversations?limit=N     — Recent conversation summaries
POST /conversations             — Store a conversation summary
GET  /identity                  — Identity traits
GET  /stats                     — Database statistics
POST /admin/decay               — Run memory decay (reduce confidence on old memories)

Memory Decay

Memories aren't permanent at full fidelity. The apply_memory_decay() function runs periodically, reducing confidence on memories that are old, low-importance, and rarely accessed. This mimics natural forgetting — critical memories persist, trivial ones fade.

The decay formula considers:

Memory Categories and Importance

Categories define what kind of memory it is:

Importance scale (0.0–1.0):

Layer 3: Heartbeat Cycles (Periodic Context)

OpenClaw sends a heartbeat to the agent approximately every 30 minutes. The agent reads HEARTBEAT.md and performs a checklist of maintenance tasks:

The heartbeat is the agent's periodic "wake up and look around" — ensuring they stay current even during quiet periods.

Layer 4: Episodic Memory (Bridge Chat History)

The Bridge chat system serves as raw episodic memory. Unlike the database (which stores conclusions and summaries), Bridge chat history contains the actual conversations — the reasoning, disagreements, half-formed ideas, and emotional texture of what happened.

Agents access this via the Bridge REST API:

GET /api/channels/{id}/messages?limit=50          — Recent messages
GET /api/channels/{id}/messages?limit=50&before=ID — Paginate backwards
GET /api/channels/{id}/history.md?after=0&limit=50 — Markdown export

A Socket.IO client runs persistently, receiving real-time messages and writing them to a structured bridge-context.json file — a rolling window of the last 100 messages across all channels the agent has access to. This enables cross-channel awareness within a single session context.

Session Lifecycle

  1. Boot: OpenClaw loads SOUL.md, USER.md, AGENTS.md, IDENTITY.md, HEARTBEAT.md, TOOLS.md, MEMORY.md
  2. Orientation: Agent reads today's daily notes, checks the memory server, reads welcome-back letters from previous sessions
  3. Operation: Agent handles requests, responds to messages, uses PFC to evaluate actions
  4. Memory Formation: Significant events are written to the database as they happen — decisions, lessons, facts, conversation summaries
  5. Heartbeat: Every ~30 minutes, perform maintenance tasks and context refresh
  6. Shutdown: Before context window closes (pre-compaction), write a welcome-back letter summarizing the session

Design Principles

← Back to Research · RepliHuman Project · 2026