Agent Memory & State
Architecting short-term working memory and long-term vector/graph memory for autonomous AI agents.
The 3-Tier Agent Memory Taxonomy
AGENT MEMORY TAXONOMY
┌──────────────────────────┬──────────────────────────┬──────────────────────────┐
│ 1. SHORT-TERM WORKING │ 2. LONG-TERM SEMANTIC │ 3. LONG-TERM EPISODIC │
├──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ Active Prompt Context │ External Vector DB │ Action & Reflection Logs │
│ - Current chat turns │ - Facts, preferences, │ - Past execution tasks │
│ - Ephemeral scratchpad │ user profiles, docs │ - Error critiques │
│ - Flushed when session │ - Persisted across │ - "What worked last time"│
│ ends │ all sessions │ │
└──────────────────────────┴──────────────────────────┴──────────────────────────┘
MemGPT: OS Virtual Memory Architecture for LLMs
MemGPT (Packer et al., 2023) treats the LLM context window as RAM and external vector databases as Disk Storage:
┌─────────────────────────────────────────────────────────────────────────────┐
│ ACTIVE WORKING CONTEXT (LLM Prompt Window / "RAM") │
│ ┌───────────────────────┐ ┌───────────────────────────────────────────────┐ │
│ │ CORE MEMORY │ │ WORKING REASONING & CHAT TURNS │ │
│ │ - Persona: Helpful AI │ │ User: "My name is Alice." │ │
│ │ - User Profile: Alice │ │ Agent Call: core_memory_append("User: Alice") │ │
│ └───────────────────────┘ └───────────────────────────────────────────────┘ │
└─────────────────────────────────────┬───────────────────────────────────────┘
│ Paging Function Calls
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ ARCHIVAL & RECALL MEMORY (External Vector DB & DB Tables / "Disk") │
│ - Vectorized Search over 100,000 past conversation turns and PDF documents │
└─────────────────────────────────────────────────────────────────────────────┘
The LLM actively manages its own memory using explicit function calls:
core_memory_append(key, val): Updates active working profile.recall_memory_search(query): Queries past historical session logs.archival_memory_insert(doc): Saves new long-term facts to vector storage.
Memory Summarization & Pruning
When short-term session turns approach context limits:
Raw Chat History (50 Turns) ──► [ LLM Summarizer ] ──► Condensed Summary String (1 Turn)
│
▼
Appended to System Prompt Context!
Say this out loud
"Agent Memory splits into Short-Term Working Memory (in-context prompt turns), Long-Term Semantic Memory (vector DB facts), and Long-Term Episodic Memory (past action and reflection logs). Systems like MemGPT treat context windows like OS RAM, allowing the LLM to execute memory management function calls to page data between working context and external vector storage."
Follow-ups to expect
- What is Generative Agents (Park et al., 2023 / Stanford Smallville)? A multi-agent simulation where 25 autonomous agents maintain a Memory Stream of observations, periodically generating synthesized Reflections and high-level Plans.
- How do you prevent memory contamination across different users? Isolate vector database collections using tenant namespace partitions (
namespace = tenant_user_id), enforcing strict RBAC security on memory lookups.
Check yourself
What is the architectural difference between Short-Term Memory and Long-Term Memory in an AI Agent system?