AI Agent Memory System Design: Short-Term / Long-Term Memory, Vector Memory and State Management (2026 Guide)
When an agent "forgets" mid-conversation, repeats itself, or loses the thread across sessions, the root cause is usually not the model — it is the memory system. This guide breaks down production-grade agent memory: the three-layer taxonomy (short-term conversation window / working memory / long-term vector memory), three memory architectures (window concatenation / summarization / vector retrieval), when to write and read, forgetting strategies, storage selection (Redis / relational DB / vector DB), token budget control, multi-tenant isolation and sensitive-data governance. Includes a copy-paste memory design decision table and a pitfalls list. [See the memory design decision table →]
Bottom line first: agent “amnesia” is not a model problem — it is a memory system problem
Across the AI projects we have delivered, the most frequent piece of client feedback is “it forgets”: “By the fifth turn it has forgotten what I asked in the first one”, “open several tasks and they bleed into each other”, “I have to reintroduce myself every session”. The first instinct is to switch to a stronger model — but the forgetting persists, because the root cause is the memory system, not the model.
Models are stateless: each call only sees what you put into the context this time. So-called “memory” is really you maintaining state on behalf of the model — what goes into the context, what is persisted externally, and when it is pulled back. Get this loop right and an agent evolves from a “single-turn Q&A machine” into a “workflow that can work continuously”.
This article walks through four things in production order: memory taxonomy, memory architectures, read/write timing, and storage & governance. A copy-paste decision table is included at the end.
1. The three-layer memory taxonomy: decide what you are actually remembering
| Layer | Lifecycle | What it stores | Who reads it | What if it is lost |
|---|---|---|---|---|
| Short-term | Current session | Raw message sequence, recent N turns | The model in this session | ”Amnesia” mid-session, incoherent answers |
| Working | Current task | Executed steps, intermediate results, to-dos | The agent on this task | Task cannot resume after interruption |
| Long-term | Across sessions | User profile, preferences, historical conclusions (summarized) | Agents across all sessions | Reintroduce the user every time, poor experience |
The engineering test is three questions: how long does this data live? Who needs to read it? What happens if it is lost? Run every piece of data through these three and you know which layer it belongs in.
The most common mistake is collapsing all three layers into one — stuffing every message into the long-term vector DB with no trimming and no summarization. Retrieval becomes noisy and irrelevant, which is the same as not remembering at all.
2. Three memory architectures: window concatenation, summarization, vector retrieval
Architecture 1: Context window — simplest; upgrade only when needed
Concatenate the most recent N turns into the context verbatim. Lowest implementation cost; fits short sessions, single tasks, low complexity.
- Pros: zero storage cost, zero retrieval logic, the model sees the freshest context;
- Cons: when the window is full you can only “drop the oldest” (truncation) — long conversations inevitably break;
- Fits: short customer-service queries, single-turn Q&A enhancement, tool-calling assistance.
Architecture 2: Summarization — the default for long conversations
Once the conversation grows past a threshold, compress the old turns into a summary in the context while the new conversation continues. The summary keeps “conclusions” rather than “process”.
- Pros: high context utilization; the model always sees key facts; long conversations keep the thread;
- Cons: summaries lose detail (“rolled away”); generating summaries costs extra model calls;
- Fits: multi-turn deep consulting, long-document Q&A, scenarios that need to reference earlier conclusions.
Trigger summarization proactively, not every turn: set a threshold (e.g. 20 turns accumulated, or 70% of the context consumed) before rolling the summary, to avoid pointless model calls.
Architecture 3: Vector retrieval — required for long histories and cross-session memory
Store long-term memory in a vector DB; at answer time recall the relevant memory fragments by relevance into the context instead of concatenating everything.
- Pros: supports unlimited history accumulation, “remembers” users across sessions, high retrieval relevance;
- Cons: you must operate a vector DB (writes, indexing, recall tuning); recall can miss key memories (relevance ≠ importance);
- Fits: long-lived user profiles, cross-session tasks, “personal memory” for knowledge agents.
The production-grade default is a hybrid: short-term dialogue uses the window, the rolling summary stays resident in context, long-term memory is retrieved on demand — three layers doing their own jobs, not a three-way choice.
3. Write timing and forgetting strategies: 80% of the pitfalls are in “when”
Once the architecture is chosen, the real engineering difficulty is timing — write too early and you pollute, too late and you lose; read too much and it is noise, too little and it is amnesia.
When to write
- Short-term: appended automatically before each model call, no intervention needed;
- Working: write on key state changes — task start (record the goal), each step completion (record the result), task failure (record the reason); not every turn;
- Long-term: only conclusion-level information — explicit user preferences (“reply with tables from now on”), conclusions after a task finishes, facts reused across sessions. Process-level information never enters long-term memory, or the vector DB drowns in noise.
When to read
- At session start: pull the user profile (who you are, your preferences, where we left off);
- At task start: pull relevant historical conclusions (has this task been done before? what was the conclusion?);
- During answering: when the needed information is not in context, trigger one vector retrieval and inject the hit fragments.
Forgetting strategies — the most neglected layer
A memory system must be able to forget, or problems are guaranteed:
- Short-term: cleared when the session ends (TTL or explicit delete);
- Working: archived when the task completes/times out (e.g. 24h) — otherwise it pollutes the next task;
- Long-term: confidence decay — memories not retrieved for N days are downweighted or expired; user-requested deletions must actually be deletable (compliance requirement);
- Version conflicts: when a user corrects a previous preference (“no more tables, use charts”), the old memory must be marked invalid rather than coexisting — otherwise the model sees contradictory information every time.
Conflicting memories are the advanced problem: when retrieval returns two conflicting fragments, the rule is “newer wins + proactively confirm with the user” — never let the model guess.
4. Storage selection and data governance: Redis / database / vector DB each own a segment
Storage selection table
| Data type | Recommended store | Key configuration | What goes wrong otherwise |
|---|---|---|---|
| Short-term session messages | Redis / in-memory | TTL (e.g. 24h) | Grows without bound with no TTL |
| Working memory (task state) | Redis Hash / DB table | Keyed by task_id + crash recovery | Interrupted tasks cannot resume |
| Long-term memory (semantic) | Vector DB (Qdrant/Milvus/pgvector) | Summarize before storing + periodic index rebuild | Raw messages in store: noisy, larger leak surface |
| Long-term memory (structured facts) | PostgreSQL etc. | user_id dimension + update timestamps | Vector search is inefficient for profile-style facts |
Three governance actions you must take
- Sanitize on write: PII detection (IDs / phone numbers / bank cards) before storage, redact or encrypt on hit — plaintext never enters the storage layer;
- Isolate on read: memory is isolated by user_id; multi-tenant systems must enforce row-level isolation — A user’s memories retrieved by B is a security incident;
- Be forgettable: expose a delete API plus a user-visible “clear memory” entry — compliance and a trust signal at once.
Token budget control
Memory’s context occupancy is cost: four levers — truncate (keep only recent N turns) → summarize (roll old turns into a summary) → retrieve (recall on demand) → tier (summary resident + details on demand). Principle: the context always holds only the minimal memory set the current step needs; the rest lives in storage.
Appendix: Agent memory design decision table (copy-paste)
| Decision | Options | Pick it when |
|---|---|---|
| Memory layer | Short-term / Working / Long-term | How long the data lives + who reads + cost of loss |
| Memory architecture | Window / Summary / Vector / Hybrid | Session length × cross-session needs |
| Storage | Redis / DB / Vector DB | Data type + access pattern |
| Write timing | State change / conclusion-level | Whether it affects later decisions |
| Forgetting | TTL / Archive / Decay / Deletable | Compliance + noise prevention |
| Multi-tenant | Row-level isolation | Multiple users share the system |
Pitfalls list (every one from a real project)
- Collapsing three layers into one: everything stuffed into the long-term vector DB → noisy retrieval, same as no memory;
- Write but never read: memories are stored but never recalled at answer time → pointless;
- Read but never write: retrieve on the fly every time → fragmented context, the model “forgets what it is doing”;
- Never forget: expired memories conflict with fresh ones → the model sees contradictions and behaves erratically;
- Raw messages into storage: no summarization, no redaction → storage bloat + privacy risk;
- No multi-tenant isolation: A user’s memories retrievable by B → security incident.
Further reading:
- AI Agent Workflow Orchestration — memory is the agent’s “state management”; orchestration is its “process management”; together they make a production-grade agent
- Enterprise RAG Knowledge Base Guide — RAG solves “domain knowledge retrieval”; this article solves “user and task state” — keep the two separate
- Vector Database Selection Guide — the storage layer for long-term memory: how to choose among Qdrant / Milvus / pgvector
- LLM Model Selection & Routing — memory context is a major cost item; routing and memory compression work well together
- Observability for AI Apps — instrument memory reads and writes: who read which memory, what the hit rate is — observable, then optimizable
Agent memory is not “save the chat history” — it is state management, retrieval engineering, and data governance in one. A well-designed memory system turns an agent from a “single-turn Q&A machine” into a “long-term assistant that remembers you, works continuously, and accumulates across sessions”; a poorly designed one forgets, crosses wires and talks nonsense no matter how strong the model is.
We have delivered agent projects with complete memory systems: memory layer design, vector DB selection and index tuning, write/read timing with forgetting strategies, multi-tenant isolation and sensitive-data governance — the whole chain. If you are building an AI product that “needs to remember its users”, bring us your scenario — we will draw the memory architecture for you first, then talk implementation.
FAQ
What is the difference between agent memory and RAG? Are they the same thing?
They are not the same, even though both use vector retrieval. RAG solves "domain knowledge" — it retrieves documents from an external knowledge base to answer "what is our expense policy". Agent memory solves "user and task state" — who this user is, where the last conversation ended, which step of a running task we are on. Analogy: RAG is looking up references, memory is taking notes. In a real session both appear together: first retrieve knowledge (RAG), then combine conversation state (memory) to compose the answer.
How are short-term and long-term memory separated in engineering terms?
Separate them by lifecycle into three layers: ① Short-term memory — the raw message sequence of the current session, kept in context, invalidated when the session ends; ② Working memory — the state of the in-flight task (executed steps, intermediate results, to-dos), archived or discarded when the task completes; ③ Long-term memory — cross-session user profile, preferences and historical conclusions, usually summarized before being stored in a vector DB or structured storage. The engineering test is three questions: how long does this data need to live, who needs to read it, and what happens if it is lost.
Where should agent memory be stored?
Choose by data type: ① Short-term session messages — Redis or in-memory with a TTL, trimmed against the context window; ② Working memory (task state) — Redis Hash or a database table keyed by task_id, recoverable after a crash; ③ Long-term memory — a vector DB for semantic retrieval of summarized memories (Qdrant / Milvus / pgvector) or a relational store for key-value facts like user profiles (PostgreSQL). A common production combination: Redis for short-term, a database for working state, and a vector DB for long-term semantic memory.
The context window is limited — what do I do when memory grows too large?
Four techniques: ① Truncation — keep only the most recent N turns, discard the rest; simplest but causes "amnesia". ② Summarization — roll old turns into a summary placed in context, keeping key conclusions; the most common compromise. ③ Retrieval — put only the memories needed right now into context, recalled from the vector DB by relevance; essential for long histories. ④ Tiering — summary resident in context, details retrieved on demand. Principle: the context should always hold only the minimal memory set the current step needs; everything else lives in storage and is fetched on demand.
How do you govern sensitive data inside memory? Can it leak?
Three layers: ① Sanitize on write — detect PII (IDs, phone numbers, bank cards) before storage and redact or encrypt; plaintext never enters the storage layer. ② Authorize on read — memory is isolated by user_id; multi-tenant systems must enforce row-level isolation, A user's memories must never be retrievable by B. ③ Provide forgetting — expose a delete-memory API so users can request removal, meeting compliance requirements. In addition, store only summaries rather than raw messages in long-term memory, shrinking the leak surface at the source.
This article comes from AI Enable Harness front-line delivery practice. Need a similar system or optimization service?
Subscribe to Updates
Get notified when new articles are published. No spam, occasional updates only.
Subscribe →