Writing Patterns Structure AI Agents' Memory

Malfunctioning memory in agents leads to errors that resurface hours later without apparent explanation. Writing and retrieval patterns, strict role-based scopes, and importance scoring help maintain useful history without noise or excessive cost. Here are the practices that scale, along with their thresholds and limitations.
Recurring Pitfalls That Cause Persistent Failures
Several structural errors arise when agents must learn and act across multiple sessions. Shared memory storage among all agents exposes a research agent's retrieval notes to misunderstandings by a coding agent, which may act on a context not intended for it. Writing to memory only at the end of a task loses all intermediate learning if execution is interrupted, forcing the agent to start from scratch on the next attempt. Retrieval performed only once at startup fails on long tasks, where what is relevant at the first step may no longer be so in subsequent steps. As systems grow, certain architectures and compression approaches cease to function, leading to failures that reappear and remain difficult to trace.
Role-Based Distribution Limits Interference Between Agents
Distributing memory according to roles helps limit interference between agents. The orchestrator has global read access, while each sub-agent writes in its own namespace and can read both this space and a shared facts layer managed by the orchestrator. Named spaces such as global, research, execution, and shared are used to organize these different scopes. Each write must be controlled server-side through permission checks; an attempt to write outside the assigned scope must explicitly fail, rather than silently polluting another agent's context.
Systematic Writing Preserves Short-Term Useful Information
Systematic writing to working memory after each step preserves useful short-term information without bloating persistent storage. This working memory is low-cost and short-lived, for example, with a TTL of 3600 seconds, which automatically removes the entry if the task never completes. Episodic memory, which is more expensive to query, only receives steps that have been actually completed. By promoting only successful outcomes, persistent storage remains free of unfinished and potentially misleading fragments.
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.
Choisissez votre rythme
Gratuit · Pas de spam · Désabonnement en 1 clic
Consultation at Each Step Aligns Context with Action
Instead of a single retrieval at launch, consulting memory at each decision point aligns context with the current step. Before a tool call that depends on prior elements, the agent first queries the working memory, which is faster and less costly, then switches to episodic memory if nothing relevant is found. This sequence maintains targeted retrieval and limits the injection of irrelevant information.
Filtering and Persisting with Importance and Confidence Thresholds
Between storing everything, which is costly and noisy, and storing nothing, which forces a restart, hierarchical memory with importance scoring offers a viable path. Before writing, the agent distinguishes between temporary and durable information, and between momentary preference and lasting constraint. Writes take the form of structured entries containing memory type, importance, timestamp, confidence, source, and tags. Long-term persistence occurs beyond explicit thresholds, for example, starting from 0.6 importance and 0.7 confidence, while low-value items are deleted or confined to the short term. At the time of retrieval, filtering by importance and confidence precedes semantic search to reduce the number of candidates and target results.
What the Different Layers of an Agent's Memory Cover
An agent's memory encompasses information written externally during execution to be reused across steps and sessions, distinct from system prompts, conversation history, and static knowledge bases. It consists of four complementary layers. Episodic memory records what has happened, often in vector or document storage, with retrieval by semantic similarity. Semantic memory groups facts, preferences, and domain knowledge, using a mix of vector and key-value storage, with semantic or exact key search. Procedural memory retains ways of doing things, in dedicated structures or through prompt injection, retrieved by pattern matching or directly. Active memory keeps the state of the ongoing task in volatile memory or ephemeral key-value storage accessible by key. Each layer has its own modes of retrieval and failure, highlighting the importance of maintenance and trust decisions, as well as provenance tracking at the time of writing.
Brief IA — L'actualité IA en français
L'essentiel de l'actualité de l'intelligence artificielle, décrypté et expliqué chaque jour.