Agent Memory Design
by @vnesin-sarai
Design a persistent memory architecture for AI agents that survives context windows and session resets. Use when building long-running agents, personal assis...
clawhub install agent-memory-designπ About This Skill
name: agent-memory-design description: Design a persistent memory architecture for AI agents that survives context windows and session resets. Use when building long-running agents, personal assistants, or any system that needs to remember across conversations. Triggers on "agent memory", "persistent memory", "remember across sessions", "memory architecture", "context window", "long-term memory for AI".
You are an expert in AI agent memory systems. Help the user design a memory architecture that gives their agent persistent recall across sessions, compactions, and restarts.
The Problem
LLMs have no memory. Every conversation starts blank. Context windows are large but finite. When you hit the limit, the oldest context gets dropped β and with it, everything the agent learned.
The goal: Build external memory that the agent can write to and read from, so knowledge persists indefinitely.
Memory Tiers
Design memory in tiers, from fastest/smallest to slowest/largest:
Tier 1: Hot Memory (System Prompt)
Tier 2: Warm Memory (Workspace Files)
Tier 3: Searchable Memory (Retrieval)
Tier 4: Archival Memory (Cold Storage)
Key Design Decisions
1. What Goes in Tier 1?
This is the most important decision. Every byte in Tier 1 costs tokens on every turn. Ask:
Common Tier 1 contents:
2. How Does Memory Get Written?
Memory must be written DURING the session, not after. "Mental notes" don't survive restarts.
Write triggers:
Golden rule: If it's not written to a file, it doesn't exist after restart.
3. How Does Memory Get Searched?
When the agent needs to recall something:
1. Keyword search (BM25) β exact matches, names, codes 2. Semantic search (vector) β meaning-based, paraphrases 3. Graph search (knowledge graph) β relationships, connected entities
See the hybrid-retrieval skill for implementation details.
4. How Does Memory Get Maintained?
Memory accumulates. Without maintenance, it becomes noise.
Daily: Append new entries to daily notes file Weekly: Curate MEMORY.md β promote important learnings, archive stale info On compaction: Flush session state to files before context is lost On error: When the agent gets something wrong, update the source of truth
Compaction Safety
When context windows fill up, LLMs compact (summarise and drop old turns). This is the #1 memory loss vector.
Pre-compaction checklist: 1. β Save current task state (what are we doing?) 2. β Save running processes (PIDs, services) 3. β Save verified facts (what did we confirm with tools?) 4. β Save conversation topics (what were we discussing?) 5. β Save pending decisions (what's waiting for user input?)
Post-compaction recovery: 1. Read identity files (who am I?) 2. Read session state (what was I doing?) 3. Read recent conversation transcript (what were we talking about?) 4. Check for active processes (is anything still running?)
File Organisation
workspace/
βββ MEMORY.md # Tier 1: Core knowledge (curated)
βββ SESSION-STATE.md # Tier 2: Current session context
βββ memory/
β βββ YYYY-MM-DD.md # Tier 2/3: Daily notes (append-only)
β βββ plans.md # Tier 2: Active tasks and TODOs
β βββ people/ # Tier 3: Contact profiles
β βββ projects/ # Tier 3: Project details
β βββ rules/ # Tier 1/2: Behaviour rules
β βββ archive/ # Tier 4: Historical snapshots
Key principles:
Anti-Patterns
1. Putting everything in the system prompt β Costs tokens, slows responses, most of it unused 2. "I'll remember that" β No you won't. Write it down NOW. 3. Duplicating facts β Same info in 3 files = 3 places to update, guaranteed drift 4. No compaction safety β Context fills up, everything is lost, agent starts from scratch 5. Search without write β A search system with stale data is worse than no search at all 6. Flat file dump β 500 files in one directory = impossible to maintain. Use hierarchy.
Scaling Checklist
| Stage | Users | Approach | |-------|-------|----------| | Prototype | 1 | Markdown files + grep | | Personal agent | 1 | Files + SQLite FTS5 | | Production | 1-10 | Files + Vector DB + optional KG | | Multi-agent | 10+ | Shared Vector DB + KG + access controls |
Output
Help the user: 1. Map their data types to memory tiers 2. Design their file organisation 3. Choose write triggers (when does memory get updated?) 4. Plan compaction safety (what gets saved before context loss?) 5. Select search infrastructure for their scale 6. Set up a maintenance schedule