AI agent memory: what to keep, where, and how much
How to give an AI agent a memory that works. The kinds of memory an agent needs, why plain files beat a vector database for most of it, what deserves a line, why a cap helps, and how it remembers further back.
There are two ways an agent's memory fails. The first is no memory at all: every session starts blank, and on Tuesday it asks again what you told it on Monday. You stop correcting it, because the correction won't last.
The second is too much memory. Every conversation is kept and fed back, the agent reads a thousand lines before each answer, half of them out of date, and it confidently follows a rule you dropped three weeks ago.
Good agent memory sits between the two, and it's mostly a writing problem, not a database problem: deciding what deserves a line, keeping it short, and keeping it true.
#What kinds of memory does an agent need?
"Memory" covers several things that behave differently:
| Kind | Holds | Who writes it | When it's read |
|---|---|---|---|
| Instructions | Its job, its rules, its tone | You | Every run |
| Long-term memory | Preferences, corrections, decisions, facts it'll need again | The agent, as it learns | Every run |
| About you | Who you are, how you work, rules for every agent | You and the agents | Every run, by every agent |
| Work log | What it did, day by day, what's next | The agent, after each run | The last few days every run, the rest when needed |
| Conversations | Everything said | Nobody, it's a transcript | Only when searched |
| Knowledge | Docs, code, files, skills | You and the agents | When a task needs it |
The first four are small and always loaded. The last two are large and only searched. Mixing them up is where most designs go wrong.
#Why not just keep every conversation?
Because whatever is loaded is paid for, on every run, and competes for the model's attention:
- Cost. A memory read at the start of each run is billed each time. Ten thousand tokens of history on a routine that runs every hour adds up fast.
- Staleness. Conversations record what was true then. "Use the staging database" from a month ago is still in there after you moved to the new one.
- Contradictions. The longer the history, the more it disagrees with itself, and the model has to guess which version wins.
- Dilution. One important rule in a thousand lines of chat gets less attention than the same rule in a list of twenty.
Keep conversations, by all means, but as an archive the agent can search when it needs to, not as something it rereads every time.
#Plain files or a vector database?
For what an agent reads every run, plain files. A short Markdown file of bullet points is:
- Readable. You can open it and see exactly what the agent believes.
- Editable. A wrong line is fixed in two seconds. Try that with an embedding.
- Searchable. The agent can grep its own work log like any other folder.
- Portable. It goes into git, a backup, or a teammate's copy of the agent, as is.
Vector search earns its place for the archive: finding a decision from five months ago in a thousand pages of notes, by meaning rather than by exact words. Even there, it's the search that changes, not the storage. The notes stay text.
#What deserves a line in an agent's memory?
Save at the moment you learn it, one short line each, in plain words:
- A correction. "Don't open a pull request for typo fixes, commit them on main."
- A preference. "Weekly report as a table, revenue first."
- A decision, with its why. "Refunds only within 30 days: the payment provider charges a fee after that."
- A fact it will need again. "The staging site deploys from the
nextbranch."
And leave out:
- Progress on the task at hand. That belongs in the work log, not in memory.
- One-off details. The order number of yesterday's ticket won't matter next week.
- What the instructions already say. Two copies of a rule drift apart.
- Secrets. A key in a memory file is a key in every prompt, every backup and every copy of that file.
When something stops being true, delete the line. A memory with a wrong line is worse than a memory without that line.
#Why cap the memory?
A cap is what keeps memory useful. Without one, an agent adds a line for everything and never removes any, and in two months it's back to the "too much" failure.
With a cap, say 2,000 characters (around 500 tokens, a few dozen short lines), a full memory forces a choice: merge two lines, drop one that matters less, rewrite the whole thing shorter. That's exactly the work that keeps a memory true. And at that size it costs almost nothing to load on every run.
Do the same for what the agent knows about you, kept apart and shared by every agent, so you don't teach each one your time zone and your dislike of emoji.
#How does an agent remember further back?
With a log and a search, in that order:
- A work log by day. After each run, one to three lines: what it did, what's next. Each day is a file. The end of the last day or two goes into the next run, so it picks up where it left off.
- Search the log. "Do you remember when we changed the pricing?" is a grep through the daily files. Every past day is still there, it just isn't loaded unless asked.
- Search the conversations. If the log doesn't have it, the transcripts might. Only then should the agent say it doesn't know.
This is how people work, too. You remember the rules, you keep a diary, and you look things up in old mail when you have to.
#Who should see and edit an agent's memory?
You should, always. An agent whose memory you can't read is an agent you can't correct: it keeps acting on a misunderstanding and you never find out why. Its memory, what it believes about you and its work log should be a click away, editable, with a way to tell it "forget that".
On a team, decide what travels. If teammates each run a copy of the same agent, its memory and its work log should sync, so a correction made on one machine reaches every copy. What it knows about you shouldn't: that's yours. See how to share AI agents with your team.
#How does Claude Code handle memory?
Claude Code starts each session with a fresh context and two ways for knowledge to survive: CLAUDE.md files you write for the project and for yourself, and auto memory, notes Claude keeps about your corrections in a MEMORY.md. /memory opens them. It's the same split as above: rules you write, notes the agent writes, both plain files you can read. The CLAUDE.md guide covers what to put where.
#In Relais
Each Relais agent has three plain files. MEMORY.md in its folder holds what it should always remember, 2,000 characters at most; USER.md holds who you are and your rules, the same size, and every agent reads it. Its work log keeps one file per day, a few lines after each run, and the end of its last two days starts each new session. Agents save with remember the moment they learn something, drop lines with forget, and log with log_work; when a memory is full, the save is refused until the agent rewrites it shorter. To remember further back, an agent searches its whole log first, then its past conversations, before saying it doesn't know. You read and edit all three in the agent's details: Memory, About you, and the last seven days of its Work log. When an agent is shared with your team, its memory, work log and skills sync to every teammate's copy; USER.md, your keys and your conversations never do. More on shared agents and the agents page.