Memory & Continuity System

Code of the West Agent Architecture — How an agent remembers, learns, and grows

Storage Layer

Continuity Database SQLite-vec
The core memory store. Every conversation exchange is paired (user + agent), embedded as a 384-dimensional vector, and indexed for both semantic and keyword search.
  • exchanges — paired user/agent turns with timestamps, topics, thread_id
  • vec_exchanges — 384-dim embeddings (Xenova/all-MiniLM-L6-v2)
  • fts_exchanges — FTS5 full-text with porter stemmer
  • knowledge_entries — extracted workspace facts with supersession tracking
  • summaries — DAG-structured compression (daily → weekly → monthly), thread-scoped
  • topic_hierarchy — co-occurrence tracking across sessions
  • sessions — conversation sessions with auto-generated titles
Graph Database SQLite
Entity-relationship knowledge graph with temporal sourcing.
  • triples — subject/predicate/object with confidence + source exchange
  • entities — canonical names, types, aliases, mention counts
  • cooccurrences — entity co-occurrence cache for pattern discovery
  • meta_patterns — discovered traversal patterns with yield scores
Daily Archives JSON
Raw verbatim conversation records, one file per day. The ground truth that indexes are built from. Never modified after write. Deduplicated on archive.
Session Handoff Markdown
Written on every agent_end. Consumed on next session_start. The bridge between sessions. Contains key topics, temporal markers, and an Open Threads section — regex-extracted commitments, TODOs, and investigations from conversation + scan of active project manifests (up to 7 threads).
Thread Handoffs Markdown
Persistent per-thread handoff files — overwritten on each write, never deleted after read (unlike session handoffs which are consumed). Each thread maintains its own handoff with compaction count in the header. On thread re-entry, an LLM warm start synthesizes the handoff into natural prose instead of raw template injection.

Processing Pipeline

Infinite Threads Scoping
Thread = persistent project scope (survives restarts). Session = ephemeral execution context (disposable). Threads and modes are orthogonal — a thread can span Chat, Code, and Booth.
  • Thread-scoped storage — thread_id flows from GUI → plugin → all storage layers (exchanges, summaries, archives, knowledge)
  • Thread-boosted retrieval — 80% RRF boost for same-thread results
  • LLM warm start — synthesizes thread handoff into natural prose on re-entry (not raw template)
  • Consolidation — after 5 compactions, force session restart to rebuild from crystallized state
Retrieval: 4-Way RRF Fusion Core
Every query retrieves through four parallel paths, fused with Reciprocal Rank Fusion:
  • Semantic — sqlite-vec MATCH on 384-dim embeddings (weight: 0.8)
  • Keyword — FTS5 BM25 with sanitized query terms (weight: 0.15)
  • Temporal — exponential decay, 14-day half-life (weight: 0.15)
  • Graph — multi-hop traversal with confidence decay per hop
  • Thread boost — 80% RRF score boost for results matching active thread
Adaptive thresholds: Sparse corpus adjustment relaxes distance threshold to 1.3 when < 2,000 exchanges. As corpus grows, natural embedding density makes this irrelevant.
Proper noun injection: If the user mentions a named entity and results contain it, inject regardless of distance score. Catches capitalized sequences, names with articles, mid-sentence proper nouns.
SEAL Metabolism Autonomous
The living pipeline. Conversation → extract → settle → crystallize. Not storage — growth.
Metabolism Monitors entropy at agent_end. High-entropy exchanges queued as candidates (~5ms).
Contemplate 3-pass reflection: immediate (clarify) → 4h (connect patterns) → 20h (synthesize growth vector).
Crystallize 3-gate system: time threshold met → principle alignment with SOUL.md → human review + approval.
Persist Approved traits written to identity files. The agent has changed.
Context Injection Per-Turn
Every turn, the agent's context is assembled from multiple sources via plugin hooks at before_agent_start:
  • Stability context (entropy, loop detection, principle anchors)
  • Continuity context (session info, handoff, archive bootstrap, temporal markers, thread warm start)
  • Graph context (entity relationships relevant to current exchange)
  • Truth plugin (current-state facts supersede stale memories)
  • Mode injection (Booth/Code/Robot posture overlays)
  • Code Evolution scaffold (tool hints, learned rules, workflow patterns — Code mode only)
Source-anchoring guardrails: Retrieved context is injected with explicit framing — "only state facts that appear explicitly" + "do not infer or extrapolate." Prevents hallucination when the agent weaves recalled memories into responses.
Code Evolution Autonomous
SEAL evolves who the agent is (identity/memory). Code Evolution evolves how it works (tools/workflows/params). Runs only in Code mode.
Record Passive session recording: tool calls, outcomes, satisfaction signals during Code mode.
Analyze Pattern detection across recorded sessions: what works, what fails, what's slow.
Mutate Generate scaffold mutations: tool hints, prompt rules, workflow sequences, parameter tuning.
Evaluate Test mutations against session data. Commit improvements, revert regressions.
Bleed Prevention Filter
Mode exchanges are tagged with injection markers. Filtered at two layers:
  • Archive bootstrap — cold-start skips mode-tagged user messages
  • Continuity queries — SQLite reads exclude mode markers
  • Chat ↔ Booth share context. Code is isolated from both.

Identity Layer

9-Layer Identity Hierarchy Stateless Rebuild
Rebuilt every turn from persistent files. No in-memory state survives restart. Everything meaningful lives in files.
  • SOUL.md — core principles, who the agent is beyond the prompt
  • AGENTS.md — operational playbook, behavioral rules
  • ANCHOR.md — who the user is (generated at onboarding)
  • TOOLS.md — discovered environment knowledge
  • Standing — Courage/Word/Brand growth dimensions
  • Memory files — daily journals, observations
  • Session handoff — bridge between sessions
  • Continuity context — retrieved exchange history
  • Graph context — entity relationships
Standing System Growth
Not metrics — developmental dimensions. The agent evaluates user growth and tracks trajectory.
  • Courage (grounding) — ability to stay present with discomfort
  • Courage (self) — self-awareness and advocacy
  • Word — honesty, follow-through, self-correction
  • Brand — consistency, the trail you leave
Evidence collected inline (22 regex patterns). Synthesis runs overnight via nightshift. Context injection includes why scores changed — recent evidence directions, pattern names, and a trailing evidence trail (last 5 patterns). Scores visible in sidebar.
Relational Postures Modes
Not separate agents — one agent, one identity, one memory. The same agent draws from the same continuity database, the same standing scores, the same lived history. What changes is the stance — a lightweight identity overlay that focuses the agent's attention and voice for the context at hand.
  • Chat — trail companion, natural conversation
  • Booth — Socratic, leadership-focused, draws from standing + journal
  • Code — Trail Ride protocol, narrated execution, choose-your-adventure
  • Robot — embodied presence, spatial knowledge, curiosity
Same agent. Same memory. Different lens. Like a person who listens differently as a mentor than as a collaborator — the knowledge doesn't change, the posture does.
Nightshift Off-Hours
Heavy LLM processing runs when the user is away. Standing synthesis, contemplation passes, metabolism candidate processing, knowledge graph backfill. Also triggers on idle (15 min inactivity, max 5 cycles/day).
Cognitive Dynamics Substrate
A learned observational layer running continuously alongside memory. Not what the agent remembers — the state it's in while remembering.
  • Encoder — per-turn features → 64-dim latent state vector
  • Predictor — one-step-ahead over latent space; surprise = prediction error
  • Online learner — weights update between turns from observed error
  • Consumers — Stability (entropy injection), Metabolism (candidate flagging), Telemetry (opt-in research stream)
Data written to cognitive-dynamics.jsonl. Research substrate behind the linked paper on agent latent-state dynamics.

How This Compares

Mem0 MemPalace Wiki-Memory COTW
Storage Extracted facts Verbatim + structure Compiled wiki Hybrid: archive + vectors + knowledge + identity
What decides to remember AI extraction Nothing (store all) Ingest pipeline Multi-layer: raw archive + selective indexes + metabolic flagging + human-gated crystallization
Retrieval Vector + graph Metadata filtering Wiki lookup 4-way RRF: semantic + keyword + temporal + graph
Identity None None None 9-layer hierarchy, stateless reconstruction
Autonomous processing None None None SEAL: metabolism → contemplation (3-pass/20h) → crystallization (3-gate + human review)
Thread scoping user_id / agent_id Wings / rooms Wiki pages Infinite threads: persistent project scopes with 80% RRF boost, LLM warm start, consolidation
Hallucination prevention None Verbatim storage None Source-anchoring guardrails + truth table + proper noun detection
Growth tracking None None None Standing dimensions (Courage/Word/Brand) with overnight synthesis
Cost $19-249/mo Local (no cloud) Local Local (no cloud costs)