Agent Memory Architecture
AI agents forget everything between sessions. Context windows are finite. RAG retrieves documents but doesn’t capture decisions, preferences, or evolving relationships. This is the core problem of agent memory, and several mature approaches now exist to solve it.
This post synthesizes patterns from five memory-focused systems I’ve built or studied: SGR Agents spec (the cognitive foundation), Moltis, OpenClaw Workspace Memory, MemPalace, and Solograph. Each takes a different approach. Together they map the full design space.
The Four Types of Memory
Every agent memory system worth studying converges on the same cognitive taxonomy, mirroring how human cognition organizes knowledge (Generative Agents, Stanford 2023). Names vary, but functions stay consistent:
1. Working Memory (short-term)
The agent’s scratchpad during a task: messages, intermediate results, current plan. Cleared or archived when the task completes.
- SGR: The NextStep schema itself.
reasoning+planningfields are the working memory, visible on every step. Structured JSON makes thought process inspectable. - MemPalace: L0 + L1 layers (~170 tokens always loaded). Identity + critical facts, the minimum context the agent always has.
- Moltis: Current session transcript, auto-exported to
memory/sessions/on close. - Solograph: Active Claude Code session context (task state, tool results, conversation). Becomes episodic memory when session ends.
Key insight: Working memory should be structured, not a raw conversation log. The SGR approach (reasoning/planning/function as explicit JSON fields) makes the agent’s thought process inspectable and debuggable. This aligns with harness engineering: agent logic should be transparent.
2. Semantic Memory (long-term facts)
Durable knowledge about the world, the user, the domain. Timeless or slowly changing. Retrieved by similarity or entity lookup.
- SGR: Dict-based, no external DB.
memory["semantic"] = { ... }loaded into system prompt at init. Summarize, don’t dump. - OpenClaw:
bank/world.mdfor objective facts,bank/entities/*.mdfor entity pages. Markdown source of truth + derived SQLite/FTS5 index. Inspired by Hindsight and MemGPT/Letta. - MemPalace:
hall_factscorridor within each wing. Verbatim storage (96.6% on LongMemEval) beats compression (84.2%). - Moltis: Hybrid search (vector + FTS5 keyword), with optional LLM reranking (70% LLM score + 30% original).
- Solograph:
kb_searchover the knowledge base: SQLite FTS5, BM25, Russian and English stemming. Facts, principles, patterns stored as markdown files.
Key insight: Structure beats embeddings for retrieval. MemPalace’s spatial hierarchy (wing > room > hall) improves recall by 34% over flat vector search. Solograph dropped embeddings for plain FTS5 (measured below). But a simple dict in the system prompt works fine to start (SGR v1 approach).
3. Episodic Memory (experience log)
What happened, when, in what order. Decision history, interaction logs, past results. Time-bound and growing. Context graphs call these “decision traces.”
- OpenClaw: Daily logs (
memory/YYYY-MM-DD.md) +bank/experience.mdcurated by reflection. The## Retainsection extracts 2-5 narrative, self-contained facts from each day, tagged with type (Wworld,Bexperience,Oopinion) and entities (@Peter). - MemPalace:
hall_events+hall_discoveriescorridors. Specialist agent diaries capture domain-specific history. - Solograph:
session_searchmakes every past Claude Code session searchable. Each session = a decision trajectory. “What did I do last time I set up auth?” returns the full trace with reasoning, even after Claude Code deletes the transcript. - Generative Agents: Memory stream of timestamped observations, with retrieval scored by recency x relevance x importance.
Key insight: Episodic ≠ semantic. Episodic is time-ordered (event sequence), semantic is timeless (generalized fact). The OpenClaw ## Retain pattern extracts narrative facts from the raw log, tags with type + entities + confidence. Decision traces compound: each captured trajectory improves future retrieval.
4. Procedural Memory (how-to)
Methods, templates, algorithms, workflows. “How to do X” rather than “what X is.”
- SGR:
memory["procedural"]stores story structure templates (3-act method), writing instructions. Loaded as recommendations in system prompt. - MemPalace:
hall_advicecorridor with accumulated recommendations and patterns. - Solograph:
symbol_searchindexes tree-sitter definitions across all projects by their words: “auth middleware” lists every implementation already written.project_infosummarizes one project’s stack and layers. - YAML workflow templates: Predefined agent sequences (video trailers, marketing campaigns). Codified procedural memory. The agent follows a proven template instead of reasoning from scratch.
Key insight: Procedural memory is the most undervalued type. A well-defined workflow template multiplies consistency. CLI-first design makes procedural knowledge testable. Schemas first, logic second applies here too: define the procedure schema before implementing.
Three Operational Loops
Capture → Retrieve → Apply (Context Graphs pattern)
From Foundation Capital’s context graphs thesis:
- Capture — record agent decisions into a graph (what + why)
- Retrieve — before new task, search for similar precedents
- Apply — adapt found patterns to current situation
Each successful action improves future ones, creating a compound learning flywheel. Implemented in Solograph: session_search for precedent retrieval, kb_search for pattern matching, symbol_search for code that already exists.
Retain → Recall → Reflect (OpenClaw/Hindsight pattern)
Blending Letta/MemGPT control loop with Hindsight memory substrate:
- Retain — normalize raw logs into narrative, self-contained facts with type tags (
Wworld,Bexperience,Oopinion) and entity mentions (@Peter,@ProjectX) - Recall — queries over derived index: lexical (FTS5), entity-centric, temporal, opinion-with-confidence
- Reflect — scheduled job that updates entity pages, adjusts opinion confidence based on reinforcement/contradiction, proposes edits to core memory
Opinion evolution: each belief has statement + confidence c ∈ [0,1] + evidence links. New facts update confidence by small deltas; big jumps require strong repeated contradiction.
Retrieve → Reflect → Plan (Generative Agents pattern)
Stanford’s Generative Agents introduced the three-layer cognitive architecture:
- Retrieve — score memories by recency × relevance × importance
- Reflect — periodically synthesize observations into higher-level insights (“What are the top 3 things I’ve learned about X?”)
- Plan — create day/hour plans grounded in reflections and current goals
This is the most research-validated loop. The paper showed it produces believable long-term agent behavior across 25 interacting agents.
Our own write path is new and still being broken in (November 2026): agents write decisions, findings and handoffs back through solograph’s capture tool, one append-only inbox note each, and a nightly job reads the usage logs for repeated and empty searches. See company-brain.
Forgetting: The Half-Life Problem
Not all memories should persist forever. Decisions expire as policies change, teams change, and context shifts. Context graphs call this the “half-life of decisions.”
Approaches to Forgetting
| System | Mechanism |
|---|---|
| MemPalace | Knowledge graph with valid_from / ended dates. kg.invalidate() marks facts as expired |
| OpenClaw | Opinion confidence decay. Contradicting evidence reduces c score. Reflect job proposes removal |
| Moltis | Session auto-cleanup by age/count limits. Embedding cache LRU eviction |
| Generative Agents | Recency score decays exponentially. Old memories naturally rank lower in retrieval |
| SuCo | Summarize-Condense-Distill: compress old memories into summaries, discard originals |
Key insight: Active forgetting > passive accumulation. Without decay, memory becomes noise. The simplest implementation: valid_from/ended timestamps on every fact, with periodic cleanup. Agent self-discipline applies here. Thresholds and limits prevent memory bloat.
Trust Hierarchy: Not All Memory is Equal
A common failure mode: the agent “remembers something” but you can’t tell if it’s trustworthy. Memory systems that treat everything as equal (recent chat, old decisions, daily notes, canonical specs) produce agents that confidently cite stale or wrong information.
The Zero Harness approach introduces an explicit trust hierarchy for memory:
| Layer | Trust Level | Example | Update Frequency |
|---|---|---|---|
| Source of truth | Canonical | source_of_truth.md, schemas, configs |
Rarely, deliberately |
| Handoff | High | handoff.md (current state, decisions, blockers) |
Every session end |
| Daily notes | Medium | Daily log, task notes, runtime snapshots | Daily |
| Memory entries | Variable | Structured facts, observations | Ongoing |
| Chat history | Low | Raw conversation, ephemeral context | Per session |
Source of truth > volume. The agent knowing which file is canonical matters more than remembering everything. When memory contradicts source of truth, source of truth wins.
Handoff as save game. Not abstract “long-term memory” but a short, living file that captures: what’s happening now, what decisions were made, what’s broken, what’s left to do, which files are load-bearing. Like a game save point. OpenClaw’s ## Retain section, GSD-2’s .gsd/STATE.md, and Claude Code’s session summaries all implement this pattern.
Memory should help act, not just recall. Useful memory units aren’t just facts but actionable artifacts: task notes, daily plans, fixed decisions, integration statuses, runtime snapshots, environment self-maps. Good agent memory is an operational surface you act from, not a museum of recollections.
This connects to harness engineering: the harness defines which artifacts are source of truth (CLAUDE.md, schemas, tests), and the memory system respects that hierarchy.
Lexical-First Retrieval
Most agent memory systems default to vector/semantic search. In practice, engineering queries are exact and operational: “what did we decide about heartbeat?”, “where is the runtime snapshot?”, “which cron is failing?”, “what file is canonical?”
For these, lexical search (BM25/FTS5) outperforms embeddings:
- Exact file names, identifiers, integration names: lexical wins
- Specific formulations, decisions, promises: lexical wins
- “Find something conceptually similar”: embeddings win
- “What does X relate to?”: graph queries win
Practical stack as systems commonly layer it, ordered by reliability (the author’s own measured choice is only the first layer, see below):
- Lexical first (BM25 / FTS5): exact names, identifiers, operational queries
- Graph queries (Cypher / FalkorDB; others use it, the author dropped it): relationships, dependencies, cross-references
- Vector search (embeddings; others use it, the author dropped it): conceptual similarity, fuzzy matching
- LLM reranking: optional final pass for relevance scoring
The author’s own Solograph dropped its graph (Oct 2026) and its vectors (26 Oct 2026; measured: 0/39 session recall, 14 s cold) for SQLite FTS5 plus files. For this use, lexical search is the measured choice.
Multiple systems converge on this independently: Moltis uses hybrid (FTS5 + vector + optional LLM reranking), MemPalace found structural filtering beats raw embeddings by 34%, and most code-graph MCP servers now run on SQLite FTS5, embeddings optional.
Measured: what Solograph removed
Solograph began with three of these layers: FTS5, a FalkorDB graph queried in Cypher, MLX embeddings. In October 2026 each was tested against known answers.
- Vectors. The vector index found 0 of 39 known sessions in its top 5; FTS5 found 32. Claude Code deletes transcripts after 30 days and nothing re-read the disk, so the index and the disk shared no session. Cold KB search: 14 s against 66 ms.
- The graph. 781k call edges, five queries in four months, every one “list the projects” or stats. On a 1,100-file repo, a dedicated code-graph MCP and plain Grep/Read gave the same accuracy in all 8 runs.
Both went, and the install shrank from 862 MB to 89 MB. What stayed is what Grep cannot do: symbol and package search across 70 repositories, the knowledge base, the session archive.
Key insight: don’t start with “semantic magic.” Start with the simplest retrieval that handles your actual queries, and measure each layer you add against it. A stale index fails silently.
Minimal memory holds up (Nov 2026)
Three November 2026 sources point the same way: the simple layer carries most of the load. Each one has a limit, and the limits matter as much as the headlines.
- BRIDGE (arXiv 2611.22179, 17 Nov 2026) is a deliberately plain RAG memory: one observation note per block, chained to the previous notes, hybrid BM25 plus cosine retrieval, results shown in chronological order. By the abstract, it matches the prior best system within bootstrap confidence intervals on LongMemEval-S and BEAM, and beats the best memory baseline on EverMemBench by 5.7-6.3 points at the same reader. It sends about 5-7K tokens to the reader per query, with one LLM call per ingestion and one per query. The authors read the parity as a flaw of the benchmarks, which score what memory retrieves, not what it lets the agent do. On their five probes (a rule said once in passing, a pattern never stated) no design wins everywhere: the fact extractor LangMem wins rule application, BRIDGE wins pattern induction. BRIDGE retrieved the rule but the reader did not act on it, and showing the rule more prominently closed most of that gap. I read the abstract and the introduction; the per-probe tables did not survive the HTML extraction, so I quote no probe scores.
- LEDGER (arXiv 2611.20927, 16 Nov 2026) takes the opposite route: a model proposes facts, and fixed rules decide which value is current, which source wins and what a deletion erases. Each fact keeps its source and the period it held. On a synthetic coding-agent workload the authors wrote themselves, it answers 94.3% of questions on the five seeds they developed on and 91.1% on five held-out seeds, against 82.1% and 83.3% for replaying the whole history. Full replay’s evidence was clean in only 21.9% of probes, so the model hides the mess until the history grows. On LongMemEval it ties full replay at 74.8% with 1,087 tokens against 108,447, but the paired interval still allows a difference of several points either way. Mem0 as configured there kept a deleted value in 18 probes.
- OmniMem (omnimem.org, vendor page) reports 26% fewer tokens for Claude Code with its memory: median 833k to 616k per run, fewer in 8 of 10 pairs. It is Haiku 4.5, one scenario, 10 pairs, p = 0.05 by a sign test, and the vendor itself calls it “promising rather than proven”. The firmer number is that 0 of 10 runs walked into the planted dead end, against 8 of 10 without it. This one is not minimal: it uses local ONNX embeddings and a lifecycle with four states.
MIRIX-2.0 (arXiv 2611.12068, 9 Nov 2026) is the counterweight: six typed memory agents, a provenance hypergraph and a background consolidation pass. Its abstract claims the top score on four of five QA benchmarks, 91.4% on LoCoMo and 72.6% on LongMemEval-S, 14.3 points above the strongest baseline. BRIDGE’s argument is that benchmarks like these cannot tell such designs apart, so I read that lead as unproven for agent work.
Where we sit. The brain is files plus SQLite FTS5 BM25 (see company-brain and project-solograph), with no extraction layer. It is not BRIDGE: BRIDGE adds cosine, which we removed on measurement, and writes a note per block with an LLM, which we do not. What carries over is the argument that retrieval is not the bottleneck, and BRIDGE’s finding that a retrieved rule goes unused unless it is put in front of the reader. That is why brain_start and the session-start hint put the map in context instead of waiting for a search. LEDGER is the comparison for our weak spot, notes going stale. We keep the source of each note and check notes against reality weekly with /solo:dream, but a person applies the fix. LEDGER does that mechanically: source and validity period are stored, and a rule picks the current value. We have no such rule, and its own 4 stale answers all came from updates the extractor missed, which is the same failure we would have.
Progressive Context Loading
All five systems converge on the same context engineering pattern: don’t load everything, load progressively.
| Layer | What | When | Size |
|---|---|---|---|
| L0 | Identity / role | Always | ~50 tokens |
| L1 | Core facts / preferences | Always | ~100-200 tokens |
| L2 | Topic-relevant facts | On demand | Variable |
| L3 | Deep search results | Explicit query | Variable |
- MemPalace: Explicit L0-L3 layers
- SGR: Dict memory loaded into system prompt (L1), retrieval via tools later (L2-L3)
- OpenClaw:
memory.mdas always-loaded core (L1), derived index for recall (L2-L3) - Moltis: File watching + auto-sync as L1, hybrid search as L2-L3
- Solograph: CLAUDE.md as L0-L1 (table of contents, ~100 lines per harness engineering),
kb_search/session_searchas L2-L3
This is context engineering in practice: treating the context window as a memory budget. Harness keeps L0-L1 stable and tested; L2-L3 are dynamic.
Storage Architecture Comparison
| System | Storage | Search | Embeddings | Scale |
|---|---|---|---|---|
| SGR v1 | Python dict (in-memory) | None | None | <100 facts |
| Moltis | SQLite + FTS5 | Hybrid (vector + keyword) + LLM reranking | Local GGUF / OpenAI / Ollama | <5K chunks |
| OpenClaw | Markdown + SQLite index | FTS5 + optional embeddings | Optional | <10K facts |
| MemPalace | ChromaDB + SQLite KG | Spatial filtering + vector | Local | 22K+ memories |
| Solograph | SQLite FTS5 + markdown files | BM25 over KB, sessions, symbols | None (removed Oct 2026) | 68 projects, ~85,900 symbols (18 Nov 2026) |
Solograph as a Full Memory System
Solograph covers all four types above with SQLite files and no embeddings, over git-backed markdown the index can rebuild from anytime (local-first). What separates it from standard RAG patterns is freshness, not structure: every index checks its source files before answering, so there is no reindex step to forget. Five read tools provide the interface, plus brain_start and capture when the KB is run as a brain.
Practical Recommendations
Starting Simple (SGR v1 approach)
If you’re building your first agent, start with dict-based memory in the system prompt. No database, no embeddings. Three categories: semantic, procedural, rules. Load at init, don’t mutate during session. This alone gets you far. Schemas first: define the memory structure before adding persistence.
Adding Persistence (Moltis/OpenClaw approach)
When you need cross-session recall: Markdown files as source of truth + SQLite/FTS5 derived index. Rebuild index from Markdown anytime. Add vector search when FTS5 isn’t enough. Keep the ## Retain discipline for extracting structured facts. Local-first, offline-first.
Scaling Up (MemPalace approach; Solograph stays lexical)
For multi-agent systems with rich history: ChromaDB with a spatial hierarchy (MemPalace), or FTS5 across every store (what Solograph does). A knowledge graph for entity relationships is an option others use, not one the author kept. Session search for full audit trail. Progressive context loading (L0-L3). Active forgetting with temporal validity. Small bets: try one memory type first, add others incrementally.
The Compound Learning Goal
The ultimate goal isn’t remembering but compounding. Every decision trace should make the next decision better. This requires:
- Capturing why, not just what
- Precedent retrieval before new tasks
- Active decay of stale knowledge
- Structured reflection (not just accumulation)
Research & References
Papers
- MemGPT / Letta — MemGPT: Towards LLMs as Operating Systems (Oct 2023). Virtual context management: paging facts in/out of LLM context like an OS manages memory. Core > archival > recall architecture.
- Generative Agents — Generative Agents: Interactive Simulacra of Human Behavior (Apr 2023, Stanford). 25 agents with memory streams, reflection, and planning. Introduced retrieve-reflect-plan.
- Hindsight — Hindsight: Posterization for LLM Conversations (Apr 2024). Separates observed vs believed vs summarized. Confidence-bearing opinions that evolve with evidence.
- LongMemEval — LongMemEval: Benchmarking Long-Term Memory (Oct 2024). Benchmark where MemPalace scored 96.6%. Tests multi-session reasoning, temporal reasoning, knowledge updates.
- SuCo — Summarize, Condense, and Distill (Nov 2024). Memory compaction for long-running agents. Formalizes the forgetting problem.
- RAISE — Retrieval-Augmented In-Context Learning (Jan 2024). Entity-centric retrieval from semi-structured sources.
- Cognitive Architectures for Language Agents — CoALA (Sep 2023). Survey of memory, action, and decision-making in language agents. Proposes the working/episodic/semantic/procedural taxonomy used here.
Industry
- Foundation Capital: Context Graphs (Dec 2025). “System of record for decisions” thesis
- Anthropic: Effective Context Engineering. Context window as working memory budget
- Manus: Context Engineering Lessons. KV-cache locality, filesystem memory
- OpenHands: Context Condensation. Bounded conversation memory
- Anthropic: Harness Design for Long-Running Apps. Task state and evaluator design
Tools & Systems
- MemPalace: GitHub. Spatial memory, 96.6% LongMemEval, MIT (27K stars)
- Solograph: GitHub. Portfolio, KB and session search, 5 MCP tools, SQLite FTS5, Rust server, no embeddings
- QMD. Mini CLI search engine for docs and knowledge bases (20K stars). BM25 + vector + LLM reranking, all local. Optional Moltis backend
- Moltis. Rust-based memory with hybrid search + LLM reranking
- OpenClaw. Markdown source-of-truth + derived index, Retain/Recall/Reflect
- Letta. MemGPT implementation, core/archival/recall memory management
- LangGraph. Graph-based agent execution framework
Knowledge Patterns
- Karpathy LLM Wiki. The pattern our wiki builds on. Three-layer architecture: raw sources (immutable) > wiki (LLM-maintained, interlinked) > schema (conventions). Key insight: “The knowledge is compiled once and kept current, not re-derived on every query.” Memory as a persistent, compounding artifact where synthesis accumulates rather than being rediscovered. The LLM handles bookkeeping humans abandon: cross-references, consistency, contradiction detection. This is how our knowledge base works: raw sources in
0-principles/and1-methodology/> wiki pages synthesized by LLM > Solograph indexes everything for retrieval
Related Wiki Pages
- context-graphs-summary — agent trajectories and organizational memory
- decision-traces-compound — why capturing decision rationale compounds
- context-engineering — progressive disclosure and context budgeting
- inline-agent-memory — 5th memory location: grep-friendly comments at the call site (AI-NOTE / AI-TODO / AI-ASK)
- rag-patterns — 7 RAG approaches, spatial filtering as additional pattern
- harness-engineering-summary — agent mistake → fix the harness
- agent-mistake-fix-harness — the core harness loop
- agent-self-discipline — drift detection and complexity thresholds
- schema-guided-reasoning — schemas first, logic second
- sgr-deep-dive — complete SGR guide with code examples
- privacy-as-architecture — local-first memory design
- codegraph-guide — Solograph’s symbol and package index across projects
Synthesized from: SGR Agents Spec v1 (Sep 2025), OpenClaw Workspace Memory Research (Feb 2026), Moltis Memory System (Mar 2026), MemPalace (Apr 2026), Solograph (measured review, Oct 2026), Foundation Capital Context Graphs (Jan 2026), and 7 research papers.