AI Memory: Challenges and Solutions for Smarter Agents
Le brief IA que les pros lisent chaque soir
Les 7 actus IA du jour, décryptées en 5 min. Gratuit.
Inclus dès l'inscription : notre sélection des meilleurs guides & comparatifs IA.
Choisis ton rythme
Gratuit · Pas de spam · Désabonnement en 1 clic
Understanding the Memory Problem in AI Agents
Large language models, despite their advancements, exhibit a notable characteristic: the absence of persistent state. Each interaction with the API is independent, meaning the model receives a block of text, processes it, returns a response, but retains no information between calls. This lack of updated internal storage between interactions works well for one-off queries. However, it poses a fundamental problem for agent systems that require continuous memory to coordinate actions across multiple sessions, learn from feedback, or manage complex tasks.
To illustrate this challenge, consider the following questions:
- What happened before? An agent tasked with booking events in a calendar must be able to remember already scheduled events to avoid double bookings.
- What does this user want? A writing assistant needs to retain the user's preferred style and tone to avoid starting from scratch in each session.
- What has the agent already attempted? A research agent must remember unsuccessful queries to avoid repeating the same mistakes and hitting dead ends.
- What facts has the agent accumulated? An agent discovering that a file is missing must record this information to account for it in future steps.
The memory problem involves endowing an intrinsically stateless system with the ability to behave as if it possesses persistent and queryable knowledge about the past.
Types of Agent Memory
Contextual Memory or Working Memory
The simplest form of memory is contextual memory, or working memory. It includes everything present in the current context window: the conversation history, the results of tool calls, system prompts, and relevant documents. All of this is passed to the model as text with each call. This approach is precise and immediate, allowing the model to reason with high fidelity about everything in context. There is no retrieval step, no approximation, and no chance of pulling the wrong record.
However, the major constraint is the size of the context window. Current models support between 128K to 1M tokens, but costs and latency increase with length. Thus, it is not feasible to simply dump everything into the context window and consider it done. In practice, contextual memory works best for the active state of a task: the current conversation, recent tool outputs, and documents directly relevant to the immediate step.
External Memory
For information that is too large, too old, or too dynamic to be permanently retained in context, agents query external storage and extract what is relevant as needed. This is retrieval-augmented generation (RAG) applied to agent memory. Two retrieval models address different needs:
- Semantic search on a vector database finds records similar in meaning to the current query.
- Exact search against a relational or key-value store retrieves structured facts by attribute — user preferences, task status, previous decisions, and entity records.
In practice, the most robust agent memory systems use both in combination: performing vector searches and structured queries as needed, then merging the results for maximum efficiency.
Large-Scale AI Agent Memory Architecture
What Needs to Be Stored
Not all information deserves the same treatment, and it is important to be precise about what you are actually storing. Agent memory naturally falls into a few categories:
- Episodic memory captures what happened: specific events, tool calls, and their results.
- Semantic memory captures what is true: facts and preferences extracted from experience.
- Procedural memory captures how to do things. It encodes learned action patterns, successful strategies, and known failure modes.
Writing to Memory: When and What to Store
An agent that writes every token from each interaction to memory generates noise at scale. Memory must be selective. Here are two common models:
- End-of-session summary: After each session, the agent or a dedicated summarization step extracts highlights, decisions, and outcomes and writes them as compact memory records.
- Event-triggered writes: Certain events explicitly trigger memory writes — user corrections, explicit preference statements, task completions, and error conditions.
What not to store: large-scale raw transcripts, intermediate reasoning traces that do not affect future behavior, or redundant duplicates of existing records.
Memory Retrieval: Obtaining the Right Context
Here is an overview of the three main retrieval strategies:
-
Vector similarity search queries memory storage with an embedding of the current context and returns the K most semantically similar records. It is fast, approximate, and works well for unstructured memory. It also requires an embedding model and a vector index like HNSW or IVF-based. Quality depends on the slicing strategy and the embedding model.
-
Structured query retrieves facts by attribute — user ID, time range, entity name. Precise when you know what you are looking for. It does not handle semantic drift. Works with SQL queries or key-value searches.
-
Hybrid retrieval combines the two: run a vector search and a structured query in parallel and merge the results. Useful when memories have both semantic content and structured metadata, such as finding memories related to billing issues from the last 30 days for that user.
Memory Decay and Versioning
Memories become outdated. A user's title changes. A previously correct API endpoint is now obsolete. An agent that promotes outdated memories causes downstream errors. You need ways to handle this, and here are the most relevant:
- Temporal decay: Weight recent memories more heavily than older ones.
- Versioned entity records: Maintain versioned entity storage so updates replace previous values with timestamps.
Multi-Agent Memory
When multiple agents share memory — a coordinator and several sub-agents working in parallel — consistency becomes a challenging issue. Here are common approaches:
- Central memory: Use locking or optimistic concurrency to control writes.
- Namespaces: Each agent writes to its own memory space.
- Append-only logs: Store all changes and resolve conflicts at read time.
There is no one-size-fits-all solution; it depends on how the agents operate and share state.
Evaluation
Memory systems often fail silently. The agent retrieves something incorrect, reasons from it, and produces a plausible-sounding erroneous response. Here are some metrics to track:
- Recall measures whether the system surfaces relevant memory when it exists.
- Precision measures whether it also pulls noise.
- Fidelity measures whether the agent uses the retrieved memory in its reasoning.
- Staleness rate measures how often the agent surfaces an outdated fact.
Effective memory management essentially involves storing information while keeping it relevant and retrievable.
Conclusion
Agent memory functions like a stack. Contextual memory maintains the current working state, while external retrieval brings in historical and relevant facts. The engineering challenge lies in determining what to record, when to trigger retrieval, and how to maintain a clean and useful memory as it grows.
Brief IA — L'actualité IA en français
L'essentiel de l'actualité de l'intelligence artificielle, décrypté et expliqué chaque jour.