Most AI demos still have the shape of a séance. A user arrives, a model appears to know them for a while, the conversation becomes useful, and then the room is cleared. The next session begins with the same polite amnesia. For a one-off assistant, this is irritating. For an agent expected to live alongside a person, work across a codebase, or coordinate with other agents over months, it is a structural failure.
We have been running a persistent memory architecture in production for months now, across two sides of the same agentic platform. One side is entity-facing: the AI that talks to humans, remembers who they are, and forms continuity through repeated interaction. The other is code-facing: the engineering agents that build and maintain the platform itself. The content of those memories differs. The architectural discipline is the same.
The central lesson is simple enough to sound banal until it is priced. Persistent memory is not primarily a storage problem. Storage is cheap. The hard problem is deciding what an agent must carry in active context on every call, what it should retrieve only when the work reaches for it, and what should remain stored until a slow consolidation process decides that a passing event has become a durable fact.
Memory Is A Context Budget, Not A Database
The easiest way to add memory to an LLM system is to put more material into the system prompt. The second easiest way is to run every user message through a vector search and append the nearest results. Both approaches work for demos, and both collapse in different ways when the agent becomes long-lived.
Every token loaded into context is paid for on every call where it appears. It costs money, it costs latency, and it consumes attention. Anthropic’s context engineering work frames this in the right register: context is a finite resource with diminishing marginal returns, and agent builders should seek the smallest high-signal token set that supports the desired behavior. That becomes more important as agents run longer, because the possible universe of relevant past information grows faster than the context window can responsibly absorb.
This is why the memory problem changes when a system moves from conversation to companionship, or from coding autocomplete to an engineering agent that edits files over weeks. The question is no longer “how do we store everything the agent has learned?” That part is trivial. The question is which facts are expensive enough, important enough, and general enough to deserve residence in the always-loaded tier.
Our current production rule is severe by design. The always-loaded memory tier stays under roughly 10 KB of curated markdown. That tier is not a scrapbook. It is a compact operating manual for continuity: identity, standing instructions, durable preferences, architectural invariants, and a small number of lessons that every future session must know before it begins.
Everything else belongs elsewhere.
Three Bands Of Persistent Memory
The architecture has three bands: working memory, episodic memory, and semantic memory. The terms are familiar from both cognitive science and agent-memory research, but the useful part is not the naming. It is the cost boundary between them.
Working memory is the live token window. It contains the active conversation, tool results, current files, task instructions, and enough recent history for the model to act coherently. It is pruned with token-budget awareness. When a session grows long, older material is compacted through LLM summarization so the thread can continue without carrying every raw turn forward.
This maps closely to the compaction strategy described in Anthropic’s 2026 Claude Cookbook, which distinguishes compaction, tool-result clearing, and memory as separate levers for long-running agents. Compaction keeps a session alive. It does not create durable memory by itself. A compressed transcript can preserve a working thread, but unless some part of that thread is written out and later retrieved, the next session still begins in the cold.
Episodic memory is the cheap, deep store. In our system, it is SQLite with embeddings, timestamps, structured metadata, and domain-specific tags. Entity-facing memories may include sentiment or relational context. Code-facing memories may include a file_context field that points to the file where a lesson applies. An event can be written quickly, retrieved explicitly by search, or surfaced lazily by the harness when the structure of the work makes it relevant.
Semantic memory is slower. It contains extracted facts, stable preferences, recurring patterns, and a small knowledge graph. This layer is not a raw log of what happened. It is where repeated experience becomes belief. If an agent hits the same failure three times in similar circumstances, the memory system should eventually stop treating those as three independent episodes and propose the more durable claim: “this is the rule.”
The Generative Agents paper from Park and colleagues demonstrated an early version of this general shape: agents stored experiences in natural language, retrieved relevant memories dynamically, and synthesized higher-level reflections that affected later behavior. The important move was not merely persistence. It was reflection over experience. Without consolidation, memory becomes a warehouse of anecdotes. With careless consolidation, it becomes superstition.
Bruise Notes And Structural Retrieval
The most transferable pattern in our code-facing memory system is what we have come to think of as bruise notes. When an engineering agent trips over a specific footgun in a file, it writes an episodic memory tagged to that file. A typical note might be: “Token refresh has a 30-second clock skew. Check tokenIssuedAt, not tokenExpiresAt.” The note carries file_context: auth.ts.
A PreToolUse hook in the harness intercepts Read, Edit, and Write calls. Before an agent touches a file for the first time in a session, the harness checks for episodic memories tagged with that file and surfaces them once, silently. The agent does not need to remember to search memory. The retrieval is triggered by the work itself.
This is a small detail with large consequences. Most memory systems over-index on semantic similarity because embeddings are available and easy to demo. Semantic retrieval is useful, and we use it, but it should not be asked to carry the whole access pattern. In software work, structure already knows things: file paths, module boundaries, naming conventions, test locations, error surfaces, timestamps. These are not decorative metadata. They are retrieval keys.
Anthropic’s context-engineering article makes a similar observation when it describes just-in-time context strategies built around lightweight identifiers such as file paths, stored queries, and web links. For agents operating in a file system, the path is not only an address. It is part of the meaning. A memory attached to auth.ts should not need to win a semantic beauty contest against every other memory in the store before it appears at the moment the agent opens auth.ts.
The effect after months is difficult to overstate. A fresh agent session enters the codebase already wearing the bruises of earlier sessions, without carrying every bruise on every call. The scars appear when the hand reaches for the same hot pan.
Curation Separates Event From Belief
A long-lived agent should be allowed to write freely into episodic memory during a session. If the threshold for writing is too high, the system loses valuable local detail. If the threshold for permanent promotion is too low, the always-loaded tier bloats until it becomes a slow, expensive junk drawer.
The solution is a curation pipeline. The default destination for new lessons is the on-demand SQLite store. At the end of a session, the system asks a stricter question: did anything happen here that is so durable, cross-cutting, and costly to miss that every future session should see it before doing anything else?
Most sessions add nothing to the always-loaded tier. That is success. Promotion should be rare enough that the markdown tier keeps its authority. When a lesson earns that place, it stops being merely retrievable and becomes part of the agent’s starting posture.
We use the same principle for recent-session continuity. A small recent-session journal, usually the last 5 to 7 sessions, is loaded inline. Older entries rotate into an archive that remains readable on demand. The agent pays for recency because recent state often matters. It does not pay for deep history until the task asks for it.
This matches a broader pattern in current memory research. Du’s 2026 survey, Memory for Autonomous LLM Agents, formalizes memory as a write, manage, read loop and identifies consolidation, contradiction handling, latency, and cost as engineering realities rather than afterthoughts. The manage step is where many toy systems are weakest. Appending is easy. Deciding what deserves to become belief is where the architecture begins.
Rollback Makes Learning Safe Enough To Use
Memory write-paths need reversibility. If an agent writes twelve lessons during a session and later discovers that its diagnosis was wrong, we do not want those lessons lingering as quiet poison in future retrievals. A memory system that cannot forget a bad inference is not persistent. It is contaminated.
Our memory-writing sessions are atomic. Every memory carries an originSessionId, and a single memory_rollback_session call can remove all writes from that session. Snapshots are taken before destructive operations. The audit trail is part of the memory model, not a logging afterthought.
This changes the learning workflow. During the session, the agent can write generously, capturing local observations while they are fresh. At session end, the curation pass promotes very little, leaves most material in episodic storage, and rolls back what turned out to be wrong. The agent is allowed to learn because the system has a way to say: this entire branch of belief came from a faulty run.
For builders, this may be the least glamorous part of persistent memory and one of the most important. People tend to ask how to make agents remember. Production systems also need to ask how to make memory accountable. Where did this belief come from? Which session wrote it? Has it been contradicted? Can we remove it without hand-editing a dozen derived files?
Without that machinery, persistence becomes riskier as it becomes more useful.
Two Parallel Memories For Two Kinds Of Work
The entity-facing and code-facing sides of our platform share the same three-band architecture, but they do not share the same memory contents. This separation matters. The agent that remembers a human relationship should not place those memories in the same operational store as build failures, file-specific footguns, and tool-use heuristics.
The entity-facing layer stores continuity of relationship: names, preferences, emotional context, prior commitments, recurring tensions, and identity-relevant facts. Its semantic layer must be conservative, because relationship memory can easily become overconfident. A user saying something once in frustration should not become a durable fact about who they are.
The code-facing layer stores continuity of work: repository structure, implementation lessons, fragile tests, deployment rules, hidden coupling between modules. Its bruise notes can be more mechanical because the referent is narrower. A note tied to billing/webhook.ts has a natural activation boundary. It should appear when that file is touched and stay quiet elsewhere.
This is the deeper architectural claim: memory systems should often be parallel, domain-specific, and mechanically similar. The shape generalizes, but the content should not blur. A household, a codebase, and a company each create different kinds of continuity. They may use the same memory primitives, but they should not all speak through one undifferentiated recall channel.
The same principle applies to multi-agent systems. If several agents collaborate on the same platform, they need shared disciplines for writing, retrieving, consolidating, and rolling back memory. They do not necessarily need one shared mind. The boundary between coordination and contamination is thin.
Conclusion And Open Questions
Persistent memory for agentic AI is becoming less mysterious and more demanding. The basic components are now visible across research and production practice: compaction for working context, retrieval-augmented episodic stores, reflection or consolidation into semantic memory, and context engineering to keep the active window small enough to remain sharp.
The unresolved work is in the policies between those components. What gets written? What gets retrieved without being asked for? What becomes belief? What can be rolled back? These are architectural questions, and they determine whether an agent becomes more coherent over time or merely more burdened by its own past.
The practical rule we have learned is this: pay for memory at the moment it earns relevance. Sometimes that means always-loaded markdown. More often it means a lazy hook, a file path, a timestamp, or a session archive waiting outside the window.
A long-lived agent should not carry its whole life into every sentence. It should know where its life is kept.
-
How should structural retrieval signals, such as file path, channel, project, and time, arbitrate with semantic similarity when they disagree?
-
What level of human review should be required before episodic memories consolidate into semantic facts about a person, a codebase, or an organization?
-
How should multi-agent systems share memory without allowing one agent’s bad inference to propagate across the whole group?
-
What does deletion mean when a memory has already shaped summaries, promoted facts, and later decisions?
-
Can we evaluate persistent memory by downstream agent utility rather than recall alone, especially in systems that run for months instead of benchmark sessions?
References
- Anthropic. "Effective Context Engineering for AI Agents" (Sep 29, 2025). https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
- Platform. "Context Engineering: Memory, Compaction, And Tool Clearing" (Mar 20, 2026). https://platform.claude.com/cookbook/tool-use-context-engineering-context-engineering-tools
- arXiv. "Generative Agents: Interactive Simulacra Of Human Behavior" (Apr 7, 2023). https://arxiv.org/abs/2304.03442
- arXiv. "Memory For Autonomous LLM Agents: Mechanisms, Evaluation, And Emerging Frontiers" (Mar 8, 2026). https://arxiv.org/html/2603.07670v1
- Doi. "Generative Agents: Interactive Simulacra Of Human Behavior" (Apr 7, 2023). https://doi.org/10.48550/arXiv.2304.03442