· 8 min read · Aravind Baranitharan
agentic memory.
A bigger context window is not memory. How agents decide what to remember, how they find it again, and why forgetting is a feature you have to build.
- AI agents
- Memory
- Retrieval
- Architecture
Every call to a language model starts from nothing. Whatever the agent "remembers" is whatever we put back into the prompt. Agentic memory is the system that decides what to keep, where to keep it, and what to bring back, so an agent can pick up a task tomorrow, learn your preferences, and stop repeating last week's mistakes.
These are my notes on designing it: the kinds of memory, the write path, the read path, forgetting, how it fails, and the architecture I'd start with. Every section is open for feedback at the bottom.
Context is not memory
It's tempting to treat a million-token window as memory and paste everything in. It doesn't hold up:
- Models don't use long contexts evenly. Lost in the Middle found models use information at the start and end of a long prompt far better than information buried in the middle.
- Cost and latency grow with every token, on every call, for the life of the agent.
- Windows end. A task that runs for days, or a user who comes back next month, outlives any window.
- More isn't truer. An old, wrong fact sitting in the prompt competes with the new, right one.
Four kinds of memory
The CoALA framework borrows from cognitive science and splits agent memory into four kinds. The split matters because each one is written, stored and trusted differently:
- Working memory. The scratchpad for the current task: the plan, intermediate results, what's been tried. Fast to change and thrown away at the end.
- Episodic memory. What happened: "on 3 Nov, deploy failed because the migration timed out; fixed by raising the timeout." An append-only log of events with outcomes.
- Semantic memory. What is true: facts, preferences, entities and how they relate. "Prefers TypeScript. Production DB is Postgres 16." Updated in place when facts change.
- Procedural memory. How to do things: skills, playbooks, tool recipes, refined prompts. The most powerful kind, and the most dangerous, because it changes behaviour directly.
The write path: deciding what to remember
Saving every message is not memory, it's a transcript. A useful write path does four things after each turn:
- Extract. Turn raw conversation into atomic facts and events ("user's company is Acme", "task X failed with error Y") that make sense without the surrounding chat.
- Score importance. A user's name and a hard constraint matter. "thanks!" doesn't. Generative Agents had the model rate each memory's importance when writing it.
- Merge, don't duplicate. Look for an existing memory about the same thing. Update it, mark the old one superseded, or add a new one, but don't store the same fact five ways.
- Check trust. Was this said by the user, or read from a web page or an email? Content from untrusted sources should never become an instruction the agent follows later.
The read path: finding it again
Retrieval decides what the model sees, so it decides what the agent knows. Plain vector similarity is a start, not an answer:
- Query from the task, not the last message. "Fix it" retrieves nothing useful; "fix failing deploy for service billing-api" does. Rewrite the query first.
- Hybrid search. Embeddings find paraphrases, keyword search finds IDs and exact names, and a graph finds things connected to the entities in play. Use more than one.
- Rank on three signals. Generative Agents scored memories on relevance, recency and importance together. A relevant but stale fact should lose to a relevant, recent one.
- Fit a budget. Decide how many tokens memory gets this turn and fill them in priority order. Ten sharp memories beat a hundred vague ones.
A memory architecture
Here is how I'd lay it out. The context window sits in the middle; everything else exists to fill it well and keep the stores small and true.
- 01
Context window
All the model sees on this turn: system prompt and task, retrieved memories, recent turns and the scratchpad. Memory's whole job is to make this small and right.
- 02
Write path
Runs after each turn, often in the background so it doesn't slow the reply. It extracts, scores, merges and trust-checks before anything is stored.
- 03
Read path
Runs before each turn. It turns the task into a search query, searches more than one way, ranks on relevance, recency and importance, and stops when the budget is full.
- 04
Memory stores
Four stores with different rules. Working memory is cleared at the end of a task, episodic is append-only, semantic is updated in place with versions, and procedural changes are reviewed before the agent relies on them.
- 05
Consolidate
A background job between sessions, like sleep. It summarises clusters of episodes into lessons, merges duplicates, and resolves contradictions. Generative Agents called its version reflection.
- 06
Forget
Decay memories nobody retrieves, expire facts with a shelf life, and delete on request. Forgetting keeps retrieval sharp and keeps you honest about privacy.
Forgetting is a feature
A memory that only grows gets worse over time. Retrieval returns more near-duplicates, old facts contradict new ones, and the store fills with things that were true once. Good forgetting is deliberate:
- Supersede, don't delete blindly. When "lives in Chennai" becomes "lives in Bengaluru", keep the old fact marked as past. History is useful; acting on it as current is the bug.
- Give facts a shelf life. "The build is broken" should expire in hours. "Prefers metric units" can last years.
- Decay by use. Memories that are never retrieved fade in rank, then get archived.
- Delete for real. When a user asks to forget something, remove it from every store, including embeddings and summaries built from it.
How memory goes wrong
- Memory poisoning. A web page or email the agent reads contains instructions, the write path stores them, and they come back in every future session. Store where each memory came from and never promote untrusted content to an instruction.
- Stale facts. The agent confidently uses something that stopped being true. Timestamps and versions on every semantic memory are the fix.
- Over-retrieval. Loosely related memories crowd the context and pull the model off task. A strict budget and a relevance cut-off help more than a bigger window.
- Wrong person, wrong tenant. Memories leak across users or workspaces. Scope every store by owner from day one; retrofitting it is painful.
- Self-reinforcing mistakes. A wrong lesson in procedural memory gets applied, "confirmed", and stored again. Review procedural changes, and let outcomes demote them.
Evaluating memory
Test memory the way it's used: across sessions. Script a conversation that states facts, changes some of them, and comes back days later. Then measure:
- Recall: does it bring back the fact when it's needed?
- Precision: does it stay quiet when the fact isn't relevant?
- Updates: after a fact changes, does it use the new value and never the old one?
- Deletion: after "forget that", is the fact really gone from every answer?
- Cost: how many tokens does memory add per turn, and is it worth it?
What I'd build first
- A task scratchpad and an episodic log in Postgres, scoped by user, with timestamps and sources on every row.
- Semantic facts with upserts and versions, plus embeddings with pgvector, so one database covers keyword, vector and history.
- A read path with a token budget and recency-weighted ranking.
- A cross-session eval like the one above, before adding anything clever.
- Consolidation and procedural memory last, once you can see what the agent actually needs to learn.
Memory is one of the pieces that makes long-horizon tasks possible at all, and the trajectories from those runs are what RL for agents learns from. The three posts are really one system.
Open questions
- Who should decide what's important, the model at write time, or usage over time?
- Should procedural memory ever update itself without a human approving it?
- Graph or vectors? Entity graphs answer "what is connected to X"; embeddings answer "what is like X". Do most agents need both?
- What does a user need to see of what an agent remembers about them, and how should they edit it?
Rate the post, start a thread on any concept below, or share it with someone building an assistant that keeps forgetting. I'll update it as the discussion changes my mind.