AI agent memory is not a single database or a full transcript carried from one request to the next. It is a set of deliberate storage and retrieval choices. This guide explains how to separate conversation history, task state, user preferences, summaries, and retrieved knowledge; estimate storage and token costs with repeatable inputs; and define retention, permissions, and deletion rules before stale or unnecessary context becomes a reliability problem.
Overview
A dependable AI agent memory architecture answers three questions for every piece of information: what should be stored, when should it be retrieved, and when should it be removed? Storing everything may appear convenient, but it can increase context size, latency, cost, privacy exposure, and the chance that an old instruction influences a new decision.
Most agents benefit from separating memory into distinct categories:
- Conversation memory: Recent messages and tool results needed to maintain continuity within an interaction.
- Task state: Structured facts about an active workflow, such as completed steps, pending approvals, selected options, or tool outputs.
- User preferences: Durable preferences that the user has explicitly provided or confirmed, such as a preferred output format.
- Long-term memory: Carefully selected information that may help across future sessions.
- Retrieved knowledge: External documents or records fetched for a particular request. This is usually application data, not a personal memory.
- Summaries: Compressed representations of older conversation turns, used when the raw history is no longer practical to include.
These categories should not share identical retention or access rules. A temporary task checkpoint may expire after a workflow ends, while a confirmed preference may remain until the user changes or deletes it. Retrieved documents may need freshness checks, and conversation messages may be retained for a shorter period than audit records.
Memory also differs from model context. Context is what the model receives for one call. Memory is the information your application chooses to preserve and potentially retrieve later. The application, not the model, should control that boundary.
How to estimate
Use a simple inventory before selecting a vector database, cache, relational schema, or framework abstraction. For each memory type, estimate volume, retrieval frequency, average size, retention, and access scope.
A practical monthly storage estimate is:
Stored volume = records per user × average record size × active users
If records expire or are deleted during the period, use the expected retained records rather than total records created. For token usage, estimate:
Monthly memory tokens = requests × average retrieved memory tokens
To estimate a rough context budget, add the tokens for the system instructions, current user request, recent conversation, task state, retrieved memories, tool definitions, and expected model output. The result should remain below the model's supported context limit with room for variation. Context limits and pricing can differ by provider and model, so treat them as deployment inputs to verify rather than permanent assumptions.
For each memory category, assign a retrieval policy:
- Always include: Only small, high-value state such as the current task identifier or confirmed constraints.
- Include by relevance: Search long-term memories or documents using a clear query and a limited result count.
- Include by recency: Use recent conversation turns when continuity matters more than historical detail.
- Include by workflow step: Load only the state needed by the current agent or tool.
- Do not retrieve: Exclude data that is expired, unverified, outside the user's permissions, or unrelated to the current request.
A useful decision test is: if removing a memory would make the agent less accurate, less consistent, or unable to resume an active task, it may deserve storage. If it merely makes the transcript longer, it probably belongs in a short-lived log or nowhere at all.
Inputs and assumptions
Record these inputs in a design document or configuration file so the estimate can be updated without redesigning the whole system:
| Input | Example assumption | Why it matters |
|---|---|---|
| Active users | Expected monthly users | Scales records, searches, and access checks |
| Requests per user | Average agent turns per month | Drives retrieval and model usage |
| Conversation window | Recent turns or token budget | Controls continuity and context size |
| Memory write rate | Only confirmed preferences and task events | Prevents indiscriminate storage |
| Retrieval count | Maximum memories returned per request | Limits noise, latency, and token use |
| Retention period | Defined separately by memory type | Determines storage growth and deletion work |
| Access scope | User, team, tenant, or public | Prevents cross-user or cross-tenant leakage |
| Freshness rule | Review or expiry interval | Reduces stale instructions and outdated facts |
A minimal memory record might contain an identifier, user or tenant scope, memory type, content or structured value, source, creation time, last-used time, confidence or confirmation status, expiry time, and deletion status. Keep metadata that supports review and removal. Do not treat a similarity score as proof that a memory is true; relevance and validity are different checks.
Permissions should be enforced before retrieval results enter the prompt. Deletion should remove the source record and any searchable representation your system creates, according to the requirements of your application. Sensitive data deserves an explicit decision: do not store it merely because a model can summarize it.
Worked examples
Example 1: A support agent with short-lived conversation memory
Suppose an agent handles a support case over several turns. It retains the latest conversation messages, a structured case status, and a small set of confirmed account preferences. Older messages are summarized when the active context approaches its budget. The summary includes unresolved questions, decisions, and relevant identifiers, but not every conversational detail.
The workflow is: write the latest turn to the session log, update task state from validated events, check whether the context budget is approaching its threshold, summarize older turns if needed, and retrieve only the current case state for the next model call. When the case closes, temporary task state can expire while the audit record follows its separate retention rule.
Example 2: A planning agent with long-term preferences
A planning agent may learn that a user prefers concise plans and a particular calendar format. Those preferences should not be inferred from a single response. A safer workflow marks a preference as a candidate, asks for confirmation when it will materially affect future behavior, stores the confirmed value with a source and timestamp, and provides a way to change or delete it.
At request time, the application retrieves only preferences relevant to the requested plan. It should not inject every stored preference into every prompt. If the user changes the calendar format, the new value supersedes the old record or updates it in place, and the retrieval layer must not return both values without a clear precedence rule.
Example 3: Context overflow and stale memory
When a request exceeds the planned context budget, do not simply increase the prompt indefinitely. First remove duplicate tool output and low-value older turns. Next load the task state and a focused summary. Then retrieve a small number of relevant long-term memories. Finally, ask the agent to proceed with an explicit note about missing information rather than allowing it to guess.
If users report that the agent repeats outdated preferences, inspect the memory write and retrieval paths separately. The write path may be saving unconfirmed assumptions, while the retrieval path may lack expiration, recency weighting, conflict resolution, or user-scope filtering.
When to recalculate
Revisit the architecture and estimates whenever the agent gains a new tool, changes its workflow, adds users or tenants, or begins storing a new category of personal or operational data. Recalculate when model context limits, provider pricing, embedding options, database rates, or application traffic assumptions change. These inputs can alter the cost and practicality of a memory strategy even when the prompts remain unchanged.
Review memory quality when users report stale context, repeated questions, incorrect personalization, unexpected tool actions, or slow responses. Track operational measures such as average retrieved tokens, retrieval hit rate, memory write rate, expired-record volume, deletion completion, and the rate of responses that require correction. Segment results by memory type; a healthy conversation summary does not prove that long-term preferences are reliable.
Use this maintenance checklist:
- List every memory type and its business purpose.
- Assign an owner, retention rule, access scope, and deletion path.
- Set a context budget and measure actual retrieved tokens.
- Test stale, conflicting, missing, and unauthorized memories.
- Confirm that summaries preserve active tasks without inventing facts.
- Re-run cost and capacity estimates after traffic or pricing changes.
- Schedule a quarterly review of framework APIs, storage choices, context limits, privacy requirements, and implementation examples.
Start with the smallest memory system that can resume real tasks reliably. Add long-term memory only when a measured use case justifies it, and make every stored item explainable, scoped, retrievable, and removable.