Agent Memory Architecture
Overview
Conversation history ≠ memory. Production agents need tiered stores: hot in-context, warm vector recall, cold archival, plus temporal knowledge graphs for facts that change over time. This skill picks the backend and tier layout.
When to use
- Agent needs to remember user preferences across sessions
- Multi-session task continuity (Ralph, long-running research)
- Personalization that survives restarts
- Multi-tenant agents with strict isolation
- Facts change over time (price, status, relationships) → temporal KG needed
Backend selection
| Backend |
Strength |
Pick when |
| mem0 |
Self-improving, fact extraction, OSS |
Personalization, conversational memory |
| Letta (MemGPT) |
OS-style tiered memory, persistence |
Agent-as-process, long-lived agents |
| Zep / Graphiti |
Temporal knowledge graph, bi-temporal |
Facts change over time, need history |
| LangMem |
LangGraph-native, simple |
Already on LangGraph, no extra service |
| Postgres + pgvector |
Roll your own, full control |
Compliance / on-prem requirements |
Tier design
┌─────────────────────────────────────────────┐
│ Core (in context) — identity, rules │ <2k tokens
├─────────────────────────────────────────────┤
│ Recall (vector search) — last N sessions │ 100k+ items
├─────────────────────────────────────────────┤
│ Archival (cold store) — full history │ unbounded
└─────────────────────────────────────────────┘
Promotion rule: archival → recall on retrieval; recall → core on repeated use.
Eviction rule: core → recall on token pressure; recall → archival on staleness.
Temporal vs snapshot
- Snapshot: latest value wins (mem0 default). Simple, loses history.
- Temporal (bi-temporal): every fact has
valid_from, valid_to, recorded_at. Required when "what did the agent believe yesterday?" matters.
Graphiti / Zep give you bi-temporal out of the box. Hand-rolled needs (entity, relation, value, t_valid_start, t_valid_end, t_recorded) tuples.
Privacy patterns
- Per-tenant memory namespace, never share embeddings across users
- PII detection (Presidio) before embedding
- TTL on recall tier (e.g. 90 days), explicit retention for archival
- User-initiated forget: hard-delete from all tiers + reindex
Quick start — mem0
from mem0 import Memory
m = Memory()
m.add("User prefers concise answers in Korean.", user_id="jeo")
results = m.search("language preference", user_id="jeo")
Quick start — Graphiti (temporal)
from graphiti_core import Graphiti
g = Graphiti(neo4j_uri, neo4j_user, neo4j_pwd)
await g.add_episode(name="session_1", episode_body="User joined Acme Corp 2026-03-01", reference_time=datetime.now())
nodes = await g.search("where does the user work?")
Further reading
- mem0 — fact extraction, semantic search
- Letta (MemGPT) — OS-style memory blocks
- Graphiti / Zep — bi-temporal knowledge graph
- LangMem — LangGraph-native memory primitives
1---2name: agent-memory-architecture3description: Design tiered agent memory — core / recall / archival — with backend selection (mem0, Letta, Zep/Graphiti, LangMem) and temporal vs snapshot tradeoffs. Use when an agent needs persistent context across sessions, personalization, or temporal knowledge graphs.4---56# Agent Memory Architecture78## Overview910Conversation history ≠ memory. Production agents need tiered stores: hot in-context, warm vector recall, cold archival, plus temporal knowledge graphs for facts that change over time. This skill picks the backend and tier layout.1112## When to use1314- Agent needs to remember user preferences across sessions15- Multi-session task continuity (Ralph, long-running research)16- Personalization that survives restarts17- Multi-tenant agents with strict isolation18- Facts change over time (price, status, relationships) → temporal KG needed1920## Backend selection2122| Backend | Strength | Pick when |23|---------|----------|-----------|24| **mem0** | Self-improving, fact extraction, OSS | Personalization, conversational memory |25| **Letta** (MemGPT) | OS-style tiered memory, persistence | Agent-as-process, long-lived agents |26| **Zep / Graphiti** | Temporal knowledge graph, bi-temporal | Facts change over time, need history |27| **LangMem** | LangGraph-native, simple | Already on LangGraph, no extra service |28| **Postgres + pgvector** | Roll your own, full control | Compliance / on-prem requirements |2930## Tier design3132```33┌─────────────────────────────────────────────┐34│ Core (in context) — identity, rules │ <2k tokens35├─────────────────────────────────────────────┤36│ Recall (vector search) — last N sessions │ 100k+ items37├─────────────────────────────────────────────┤38│ Archival (cold store) — full history │ unbounded39└─────────────────────────────────────────────┘40```4142**Promotion rule**: archival → recall on retrieval; recall → core on repeated use.43**Eviction rule**: core → recall on token pressure; recall → archival on staleness.4445## Temporal vs snapshot4647- **Snapshot**: latest value wins (mem0 default). Simple, loses history.48- **Temporal (bi-temporal)**: every fact has `valid_from`, `valid_to`, `recorded_at`. Required when "what did the agent believe yesterday?" matters.4950Graphiti / Zep give you bi-temporal out of the box. Hand-rolled needs `(entity, relation, value, t_valid_start, t_valid_end, t_recorded)` tuples.5152## Privacy patterns5354- Per-tenant memory namespace, never share embeddings across users55- PII detection (Presidio) before embedding56- TTL on recall tier (e.g. 90 days), explicit retention for archival57- User-initiated forget: hard-delete from all tiers + reindex5859## Quick start — mem06061```python62from mem0 import Memory63m = Memory()64m.add("User prefers concise answers in Korean.", user_id="jeo")65results = m.search("language preference", user_id="jeo")66```6768## Quick start — Graphiti (temporal)6970```python71from graphiti_core import Graphiti72g = Graphiti(neo4j_uri, neo4j_user, neo4j_pwd)73await g.add_episode(name="session_1", episode_body="User joined Acme Corp 2026-03-01", reference_time=datetime.now())74nodes = await g.search("where does the user work?")75```7677## Further reading7879- mem0 — fact extraction, semantic search80- Letta (MemGPT) — OS-style memory blocks81- Graphiti / Zep — bi-temporal knowledge graph82- LangMem — LangGraph-native memory primitives