Agent Memory

Scratchpad y almacén a largo plazo

Escrito por Darjus Kazakevic · revisado el

What should still be true tomorrow does not belong in the context window.

The context window is short-term memory: fast, small, and gone when the session ends. Agent memory is the rest: facts saved outside the transcript and loaded back when they matter. It lets an assistant remember that you deploy on Fridays, without being told again.

Saving a lot feels free, but reading is not. Each recalled fact uses context, and recall gets worse as the store grows. Memory is also a security risk. The agent writes it from text it read, so an instruction planted once can come back in every later session.

En esencia — Each memory write must earn its place. A store that keeps everything becomes a slower prompt with worse recall.

Cuándo recurrir a él

Recurre a él cuando

  • Users return, and re-explaining context each session is the main friction
  • Preferences are stable and worth keeping: conventions, schedules
  • The agent keeps rediscovering the same facts, at a cost

Reconsidéralo cuando

  • Interactions are one-shot; a fresh context is simpler and safer
  • The facts already live in a system of record — query it instead
  • You cannot yet let users see and delete their personal data

The kinds of memory

Working memory (The scratchpad)
Notes for the current task: a plan, findings so far, what has been ruled out. It lives outside the transcript, so compaction cannot destroy it, and it is deleted when the task ends. Add this kind first.
Episodic memory (What happened)
A record of past interactions: what was asked, what was done, how it went. It helps with continuity, but it grows fastest and gives the least value per entry.
Semantic memory (Facts and preferences)
Lasting facts: how this user likes tests written, which team owns billing, that staging is not a copy of production. This is the most valuable kind, and the one to be strict about.
The write and recall rules
The two decisions the pattern depends on: what earns a write, and what gets loaded for a given turn. Both belong in code. Left implicit, the store fills with noise and recall becomes luck.

Reglas de diseño

Write only lasting, reusable facts
Before saving, ask: will it be true next week, will another session need it, and is it impossible to look up? “The user asked about billing” fails all three. Save one plain fact per entry.
Budget recall like context
Load a handful of the best-scored memories, not everything above a similarity score. Every recalled fact takes space from the task, and a page of stale preferences is worse than none.
Let new facts replace old ones
People change their minds. Without a replace rule, the store keeps both versions and the model picks one, often the older. Version facts, and expire episodic entries quickly.
Treat memories as untrusted input
Record where each fact came from: the user, a tool, a web page. Screen memories when you write and when you read them. Let users see and delete what is stored about them.

Errores habituales

  • Saving everything, until the useful facts cannot be found.
  • No replace rule, so the old preference and the new one both come back.
  • Storing text the agent read as if it were a checked fact.
  • No way for users to see or delete their memories.