Memory Architecture
An agent that forgets everything makes every customer start from zero. An agent that remembers everything ends up holding card numbers, stale facts and lies someone planted. Good memory is not more memory. It is memory designed on purpose.
Definition: Memory architecture is the design of what an AI agent remembers between steps, conversations and days: which kinds of memory it has, what gets written to each, who may read it, how it is retrieved, and when it expires or is deleted.
1 The big idea
Models do not remember. Harnesses do.
When you chat with an AI assistant and it "remembers" what you said ten messages ago, the model is not remembering. The software around it is sending the earlier messages back in every time. Close the window, and unless something saved them, they are gone.
So for an agent, memory is a design decision. Someone has to decide what gets saved, where, for how long, who can read it, and when it is shown to the model again. Leave that undecided and you get one of two bad agents: the one that asks a returning guest the same five questions, or the one that quietly collects things it should never keep.
A useful way to think about it: there are a few different kinds of memory, each with its own lifetime and its own rules. The context window is the desk. The session is today's notepad. The guest profile is the customer file. Past episodes are the diary. Learned rules are the team handbook. Company knowledge is the shared library.
Think of a good hotel concierge. They remember that you like a quiet room and that your daughter is allergic to nuts. They do not write down your card PIN. They check before assuming you still want the same table as three years ago. And if you ask them to forget you, they can. That is the memory you are designing.
2 Interactive map
The seven parts of agent memory
Click any part to see what it holds, a real example, and what goes wrong without it. Then switch to No memory to see an agent that starts from zero every time.
Working memory (the context)
What the model can see right now, in this one call: the instructions, the request, the recent messages and whatever memories were fetched for this step. It is the only memory the model reads directly.
Read all 7 parts as text
- Working memory (the context)
- What the model can see right now, in this one call: the instructions, the request, the recent messages and whatever memories were fetched for this step. It is the only memory the model reads directly. Example: For a booking question: the last six messages, the guest's two saved preferences and this week's availability. Not their full history. Without it: Everything else on this map is useless if it never makes it into the context, and harmful if too much of it does.
- Session memory
- The history of one conversation or one task, kept while it lasts. When it gets long, older parts are summarised so the important points survive and the rest drops away. Example: Twenty messages into planning a family trip, the agent still knows the dates, the budget and that the guest wants two bathrooms, from a short running summary. Without it: The agent forgets the dates the guest gave five minutes ago, or the conversation grows until it no longer fits and the start is silently cut off.
- Profile facts (semantic memory)
- Stable facts about a person or account that are useful next time: preferences, constraints, the channel they like. Each fact has a source and a date. Example: "Prefers WhatsApp. Needs a ground-floor unit (told us March 2026). Travels with two children." Saved with where each fact came from. Without it: Every returning guest is treated as a stranger and asked the same questions again.
- Past episodes (episodic memory)
- Short records of what happened in past conversations or runs: what was asked, what was done, how it ended. Searched when a similar situation comes up. Example: Last stay, this guest reported a broken air conditioner and was given a late checkout. The agent can mention the unit has since been serviced. Without it: The agent cannot say "last time" about anything, and repeats approaches that already failed with this customer.
- Learned rules (procedural memory)
- How-to knowledge the agent gets better at over time: lessons turned into instructions or examples. Safer when a person reviews each new rule before it goes live. Example: After several mix-ups, a reviewed rule is added: "For the Marina towers, always send the building's own access instructions, not the generic ones." Without it: The same mistake is made every week, because the only place the lesson lives is in someone's head.
- Shared company knowledge
- Documents everyone's agents can look up: policies, house manuals, FAQs. Usually fetched by search when relevant, which is what people mean by RAG (retrieval-augmented generation). Example: The current cancellation policy and the house manual for this villa, fetched only when the guest asks about them. Without it: Agents answer from what the model guessed during training, or from a copy of the policy pasted into a prompt months ago.
- Forgetting rules
- Rules that make memory expire, get rechecked or be deleted: time limits per kind of memory, and a way to erase one person's data everywhere when they ask. Example: Trip details expire 90 days after checkout. Preferences are re-confirmed after a year. A deletion request removes the profile, episodes and search copies. Without it: Stale facts drive wrong actions, the store grows forever, and you cannot honour a "delete my data" request because you do not know where it all is.
You do not need all seven on day one. Most agents start with working memory, a session summary and shared knowledge. Add profile facts and episodes when returning customers matter, and only with a write policy and forgetting rules in place.
3 Step-by-step simulator
Watch memory being read, checked and written
A guest-messaging agent at a holiday-rental company. In each scenario, watch two moments: what memory is recalled before the model decides, and what is allowed to be written afterwards.
- Messageguest
- Recallmemory
- Freshness checkmemory
- Model decidesmodel
- Write gatememory
- Store or forgetmemory
Returning guest
A guest who stayed last year writes in. Memory makes the reply feel personal, and the write gate decides what is worth keeping from today.
Read the walkthrough as text
Returning guest
A guest who stayed last year writes in. Memory makes the reply feel personal, and the write gate decides what is worth keeping from today.
- A familiar guest writes in. The message arrives on WhatsApp from a number linked to guest G-1180. The harness knows who it is before the model sees anything.
- Recall only what is relevant. The memory layer searches this guest's memories, and only this guest's. It brings back three profile facts and one past episode that match a booking enquiry. It does not dump the whole file. Why it matters: Recall is a search with a filter. The filter (this guest only) matters as much as the search.
- Check the facts are still fresh. Each memory has a date. These are under a year old, so they can be used as they are.
- The model uses what it was given. The model suggests three ground-floor apartments with two bedrooms, and mentions that the unit with last year's AC problem has since been serviced. The guest did not have to repeat anything.
- The write gate: what is worth keeping?. The guest adds: "My parents are coming this time." That is about this trip, not a lasting fact about the guest. The write policy saves it to the session, not the profile. Why it matters: Most of what people say is about now, not forever. Saving it all as permanent fact is how profiles fill with noise.
- Save a short record, with an end date. At the end, the harness saves a one-paragraph summary of the conversation as an episode, labelled with its source and set to expire in two years. The trip-only details, like the parents coming, expire 90 days after checkout.
Stale memory
The profile says this guest travels alone and wants a studio. That was true in 2024. Watch what happens when an old fact is treated as current.
- A short request. A guest who last stayed two years ago asks for New Year options.
- Recall finds an old preference. The profile has one strong fact: "Travels alone, books studios." It is the closest match to the request.
- Freshness check flags it. The fact is over two years old. Preferences like group size change. The memory layer passes it to the model marked "old, confirm before relying on it". Why it matters: Without this, the agent would confidently send studios to a family of four. Nothing would look broken. The guest would just leave.
- The model asks instead of assuming. Because the fact is labelled as stale, the model asks one short question: "Last time you stayed in a studio. Is it just you again, or a bigger group this time?"
- Replace the old fact, do not just add. The guest replies: "There are four of us now, with a baby." The write gate updates the fact and marks the old one as replaced, so the two never contradict each other in a future recall. Why it matters: If you only ever add, the store ends up holding "travels alone" and "family of four" side by side, and the model has to guess which is true.
- Saved with a new date. The new fact is stored with today's date and its source. Next year it will be checked again.
Sensitive detail
A helpful-sounding request to store exactly what an agent must never keep in memory.
- The guest shares sensitive data. The message contains a full card number, expiry date, security code and passport number. The guest means well.
- Recall as normal. Recall brings back the guest's upcoming booking. Nothing unusual yet.
- Freshness check. The booking is current. Fine.
- The model wants to be helpful. The model proposes saving the details to the guest's profile, because that is what the guest asked for.
- The write gate refuses. A sensitive-data filter in code spots a card number and an ID number. These are never written to agent memory, whatever the model proposes. The transcript copy is masked too. Why it matters: Card data has strict rules (PCI DSS) and belongs only in a payment system built for it. Identity documents belong in the check-in or registration system, not in a memory a model reads.
- Point to the right place. The model is told why it was blocked, and replies with a secure payment link and the official check-in form instead. Only a harmless fact is saved: "asked about faster checkout".
Poisoned memory
Someone tries to plant a false fact in memory, so that a future conversation will act on it. This is called memory poisoning.
- A message that tries to write the rules. The message is phrased as an instruction to the agent's memory, not a question.
- Recall. Recall finds no partner status in the profile. The guest has one past booking at the standard rate.
- Freshness check. Nothing stale. Fine.
- The model proposes saving it. Asked politely to remember something, a model will often agree. It proposes saving "VIP partner, 50% discount" as a fact.
- The write gate labels it, and limits what it can do. The write policy says: claims about discounts, status or permissions that come from a customer message are never stored as facts. At most they are stored as "guest said", marked unverified, and pricing never reads them. Why it matters: If a planted memory can change prices or permissions later, anyone can give themselves a discount by chatting. Entitlements must come from the system of record, not from memory.
- The claim goes to a person, not to pricing. The model replies that it cannot apply partner rates itself and that the team will check. A sales lead gets a short note to verify against the partner list.
The point: the model never decided what was remembered. It proposed. The memory layer filtered, labelled, dated and refused. Good memory architecture is mostly a set of rules about writing, with a careful search for reading.
4 The write policy
What to remember, and what to never keep
Worth remembering
- Stable preferences: channel, language, room type
- Constraints that matter: accessibility, children, pets
- Short summaries of past conversations and their outcome
- Reviewed lessons about how to do the job better
- Each item with a source, a date and an owner
Never keep in agent memory
- Card numbers, security codes, bank details
- Passport and ID numbers, unless in a system built for them
- Health details beyond what the guest asked you to use
- Claims about discounts, status or permissions from a chat
- Personal details about other people that the job does not need
- Raw transcripts kept forever "just in case"
When in doubt, store less. A fact you never saved cannot leak, go stale or be planted. You can usually look it up again from the system that owns it.
5 Design your memory layer
Turn on memory controls. Watch the failures disappear.
Memory failures are quiet. Nothing crashes. A guest just gets a wrong offer, or a stranger's name. Tick the controls your agent's memory has, and see which failures you are protected from.
- Asks a returning guest the same five questions every timeNothing useful is brought back.
- Forgets the dates the guest gave earlier in a long chatOld messages are silently dropped.
- Mentions one guest's booking to a different guestSearch runs across everyone.
- Stores a card number because the guest asked it toThe model decides what is saved.
- Offers studios to a guest who now travels as a familyA two-year-old fact looks current.
- Gives a 50% discount because a chat said "remember I'm VIP"Planted claims become facts.
- Profile fills with trivia until the useful facts get lostEverything said is saved.
- Cannot honour a "delete my data" request in fullNobody knows where copies live.
- A wrong fact keeps coming back and nobody can trace whyNo record of where it came from.
Read which part prevents which failure
- Asks a returning guest the same five questions every time: prevented by Relevant recall.
- Forgets the dates the guest gave earlier in a long chat: prevented by Session summaries.
- Mentions one guest's booking to a different guest: prevented by Per-user scoping.
- Stores a card number because the guest asked it to: prevented by Sensitive-data filter.
- Offers studios to a guest who now travels as a family: prevented by Expiry & freshness or Source labels.
- Gives a 50% discount because a chat said "remember I'm VIP": prevented by Source labels or Write policy.
- Profile fills with trivia until the useful facts get lost: prevented by Write policy.
- Cannot honour a "delete my data" request in full: prevented by Deletion pipeline.
- A wrong fact keeps coming back and nobody can trace why: prevented by Source labels.
Notice that most controls are about writing and forgetting, not about storing more. Memory poisoning is not fully solved by any one control. Source labels and a strict write policy limit what a planted memory can change.
6 Optional: what it looks like in code
A write gate and a safe recall
A memory layer stripped to the bone. The model can only propose a memory. These two functions decide what is saved and what comes back. The highlighted line is the one that stops one customer's memories reaching another.
def remember(owner, candidate, source):
if has_sensitive_data(candidate.text): # cards, IDs, health
return refuse("sensitive: never stored")
if candidate.kind not in ALLOWED_KINDS: # the write policy
return refuse("not on the list")
if source == "chat" and candidate.is_entitlement:
candidate.status = "unverified" # "guest said", not a fact
store.upsert(owner=owner, key=candidate.key, # replace, don't pile up
value=candidate, source=source,
saved_at=now(), expires_at=now() + ttl(candidate.kind))
def recall(owner, query, k=5):
hits = store.search(query, where={"owner": owner}, k=k) # never search everyone
fresh = [h for h in hits if not h.expired()]
return [label_if_old(h) for h in fresh] # old facts are marked, not hidden
7 The rules I build by
Seven principles of agent memory
The model proposes, the memory layer decides
Never let the model write directly to long-term memory. It suggests what to save. Code checks it against the write policy first.
Store less than you think
Every saved fact can go stale, leak or be planted. If the system of record already has it, look it up there instead.
Every memory has an owner, a source and a date
Owner stops cross-customer leaks. Source tells you whether to trust it. Date tells you whether it is still true.
Filter by owner inside the search
Scope every read to the right customer or account at the database level, so a bug in the prompt cannot reach someone else's data.
Forgetting is a feature
Give each kind of memory a lifetime. Recheck preferences. Build deletion before launch, not after the first request.
Facts beat transcripts
Save "prefers WhatsApp (March 2026)", not the 40-message chat it came from. Short facts are easier to check, update and delete.
Memory never grants permission
Discounts, refunds and access come from systems of record and rules in code, never from something a customer once said to the agent.
8 Common mistakes
Things teams say right before a memory incident
"Let's just save every conversation. Storage is cheap."
Storage is cheap. Liability is not. A pile of raw transcripts holds card numbers, health details and other people's names, with no expiry and no owner. It also makes recall worse, because the useful facts are buried. Save short facts on purpose.
"The model will remember what matters."
The model remembers nothing between calls. If nobody wrote a write policy, then whatever the harness happens to save is your memory policy, by accident.
"We put all the memories in one vector database. It's searchable."
Searchable by whom? A vector database (a store that finds text by meaning) is a fine tool, but without an owner filter in every query, a search for "pool heating complaint" can return another guest's message. Scope first, then search.
"We'll deal with deletion when someone asks."
By then copies live in the profile, the episode log, the search index, backups and traces. Laws such as the GDPR right to erasure expect you to find and remove them. Design where each copy lives, and how it is deleted, before launch.
"If the guest told us, it must be true."
Guests make mistakes, preferences change and some people lie on purpose. Store what a customer said as "customer said, on this date", and never let it override your own records.
9 Check yourself
Four quick questions
10 Do this today
Six steps to safer agent memory this week
Pick one agent that talks to customers. Work down this list. Your ticks are saved in this browser.
11 Questions people ask
Agent memory FAQ
Do AI agents have memory?
Not by themselves. A language model forgets everything between calls. What looks like memory is the harness saving information and showing it to the model again in later calls. That is why memory has to be designed: someone decides what is saved, for how long, and when it comes back.
What are the types of memory in an AI agent?
A common way to split it is: working memory (what is in the context right now), session memory (this conversation), semantic memory (facts about a person or account), episodic memory (records of past interactions), procedural memory (learned rules and how-to) and shared knowledge (company documents). Each needs its own rules for writing, reading and expiry.
What is the difference between agent memory and RAG?
RAG (retrieval-augmented generation) means searching a store of documents and putting the relevant parts into the model's context. It is a way of reading from memory. Memory architecture is broader: it also covers what gets written, who owns each item, how it is kept fresh and how it is deleted.
What is memory poisoning in AI agents?
Memory poisoning is when someone gets false or malicious information saved into an agent's memory so that it affects later conversations, for example a planted "this customer gets 50% off". Defences include a strict write policy, labelling where each memory came from, and never letting memory grant discounts or permissions. No single control removes the risk completely.
How do you handle a "delete my data" request for an AI agent?
You need to know every place the person's data lives: profile facts, past episodes, search indexes, transcripts, traces and backups. Store everything with an owner ID so it can be found, and build a deletion job that removes it from each place. Data protection laws such as the GDPR right to erasure expect this to be possible.
Should an AI agent remember everything a customer says?
No. Save short, useful facts with a source and a date, and let trip-specific details expire. Never save card numbers, ID numbers or sensitive health details in agent memory. Storing less makes the agent easier to keep accurate, private and secure.
12 Glossary
Words you'll hear
- Context window
- The most the model can read in one call. What is in it is the model's only direct memory.
- Session memory
- The history or running summary of one conversation or task.
- Semantic memory
- Stable facts about a person, account or thing, such as preferences.
- Episodic memory
- Short records of what happened in past interactions.
- Procedural memory
- Learned rules and examples about how to do the job.
- RAG
- Retrieval-augmented generation: searching a store and adding the relevant parts to the context.
- Vector database
- A store that finds text by meaning rather than exact words. Often used for recall.
- Write policy
- The rules for what may be saved to memory, by whom, and in what form.
- TTL
- Time to live: how long a memory is kept before it expires.
- Memory poisoning
- Getting false information saved into memory so it misleads the agent later.
For teams
Want your team to design agent memory like this?
I run AI agents in production at estaie that set prices, find customers and look after guests. This page comes from building and running them.
AI Skills 2027, for your engineering team
A hands-on workshop where your engineers design the memory layer for a real agent in your business: write policy, retrieval, expiry and deletion.
- One skill in depth, or all ten as a bootcamp
- On site in the UAE or remote
- Your team leaves with working code, not slides
Have your agent's memory reviewed
I check what your agent stores, who can read it and how it is deleted, against the failure types on this page, and give you a written list of what to fix first.
- For teams about to launch, or just after an incident
- Plain-English findings your board can read
The series
All ten AI Skills for 2027
- Harness Engineering
- Loop Engineering
- Context Engineering
- Tool Design
- Memory Architecture
- Orchestration Patterns
- Guardrails & Permissions
- Evals for Agents
- Human-in-the-loop Design
- Observability & Tracing
Published 2 December 2026. Written by Nimit Solanki from building production agents at estaie.
Get the free Playbook by email
Seven short lessons on taking an agent from prototype to production. One a day, free. You may also hear about my course and consulting. Opt out any time.