LLMs & GenAI

Agent Memory & State

Architecting short-term working memory and long-term vector/graph memory for autonomous AI agents.

🔴 advanced5 min readagents
Agent Memory enables autonomous systems to maintain state, recall past user preferences, and learn from execution experiences across multi-turn sessions. Memory is structured into Short-Term Memory (in-context working memory of current session turns), Long-Term Semantic Memory (vector DB indexes of past facts and documents), and Long-Term Episodic Memory (vectorized execution logs of past actions and reflection critiques).

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:

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

Check yourself

Question 1 of 3

What is the architectural difference between Short-Term Memory and Long-Term Memory in an AI Agent system?

More in LLMs & GenAI

See all →
Pretraining → SFT → RLHF5 minFine-Tune vs RAG vs Prompt: Choosing5 minRetrieval-Augmented Generation5 min