Topic 4 of 5 · 4 min read
Deciding what an agent should remember
Goal: Write a memory policy stating what an agent may store, for how long, and how a user sees and deletes it.
A memory policy is a written rule for what an agent may save, who can see it, how long it lives, and how it is removed. Without one, the agent saves whatever the model thinks looks useful, and nobody can say what is stored or why.
Check yourself · 1 of 3
Which item should a memory policy forbid an assistant from saving by default?
Why it matters
Stored memory is stored data. It can include names, health details, addresses, passwords pasted into a chat and company secrets. Privacy law in many places gives people rights to see and delete personal data, and your own users expect the same. A policy also protects quality: an agent that remembers every passing remark fills its store with noise and wrong guesses.
What a policy decides
- What may be stored. Allowed: stable preferences, project conventions, decisions, task state. Not allowed: secrets and credentials, payment data, health or other sensitive details unless the product is built and consented for that, and anything the user said "do not save".
- When it is written. Only on explicit request ("remember that...")? Or automatically, with a visible notice? Silent saving is the riskiest choice.
- Whose it is. Every record carries an owner and a scope (user, project, team). Never mix scopes.
- How long. Task notes might expire when the task closes. Preferences might expire after a set idle period. Say the period, and apply it with a date field.
- How a person sees and changes it. A screen or command that lists memories in plain language, with edit and delete. Deleting must also remove copies, including embeddings in the vector store.
- What is logged. Which memory was written or used, when, and by which session, without storing the secret content in the log.
Before and after
Before: "The assistant remembers useful information about you."
After:
Stores: language, units, project conventions, open tasks.
Never stores: passwords, keys, card numbers, health details.
Writes: when the user says "remember", or after showing "Saved: <fact>" with an Undo link.
Keeps: preferences until deleted; task notes 30 days after the task closes.
User can: list, edit and delete any memory in Settings. Delete removes the record and its embedding.
What goes wrong
- Silent saving. Users find a memory they never knew existed, and trust drops.
- Delete that does not delete. The row is gone from the profile but the embedding still returns the fact.
- Secrets saved by accident. A user pastes an API key to debug; the agent notes "key is sk-..." as a useful fact. Filter before writing.
Examples
A visible save
The user writes: "We always deploy via the staging branch." The assistant replies, then shows a small line: Saved to project memory: deploys go through staging first. [Undo] [Edit]. The user knows it was stored and can fix it.
A write filter
const SECRET = /(sk-[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16}|password\s*[:=])/i;
export function canSave(fact: string): boolean {
return !SECRET.test(fact);
}
A pattern check is not complete, but it catches the common accident before it is written, and it is cheap to run.
Key points
- A memory policy states what may be stored, when, for whom, for how long, and how it is removed.
- Prefer explicit or visible saving over silent saving, and give users a way to list, edit and delete memories.
- Never store credentials, payment data or sensitive personal details by default; filter before the write.
- Deleting a memory must remove every copy, including embeddings and caches.
- Scope every record to an owner so one user's memory is never retrieved for another.
Common mistakes
- Letting the model decide silently what to save, with no notice to the user.
- Deleting the visible record but leaving the embedding or a cached copy that still retrieves the fact.
- Using one expiry period for everything, so stale task notes live as long as stable preferences.
- Having no way for the user to see the list of stored memories.
Check yourself · 2 of 3
A user deletes a saved memory in settings, but the assistant still mentions the fact. What is the most likely gap?
Check yourself · 3 of 3
Which write rule best respects the user?
Practice items, not counted towards your mastery.
Start here
- MemGPT: Towards LLMs as Operating Systems (opens in a new tab)PaperFree
The paper that frames context as fast memory and external stores as slow memory the model pages in and out.
- Memory tool (Claude API docs) (opens in a new tab)DocsFree
How a directory-backed memory tool works: view, create and edit commands, and security notes on path handling.
- Memory overview (LangChain docs) (opens in a new tab)DocsFree
Short-term versus long-term memory, and semantic, episodic and procedural memory types, with write timing.
More for this topic
- OWASP Top 10 for LLM Applications (opens in a new tab)StandardFree
Names prompt injection and sensitive information disclosure, the two risks that memory stores amplify.