Long-term memory

Long-term memory is what the agent remembers across sessions. Without it, every conversation starts fresh and the agent feels like an amnesiac intern. With it, the agent knows your preferences, recalls past decisions, builds context over time. But long-term memory is also where agents get weird: they remember wrong things, forget important things, or leak info across users. Design it deliberately or don't ship it.

What belongs in long-term vs what doesn't

Four storage models

Most production agents use two stores: a key-value for stable facts (loaded on every session) and a vector store for rich history (queried on demand).

What to write, when

Writing policy is more important than read policy. The wrong writes are how long-term memory gets noisy and stale.

Retrieval: when the agent pulls memory in

Memory is only valuable if it's retrieved at the right moment. Three retrieval patterns:

A worked example: remembering a preference

Session 1. User says: "Please always use metric units in your answers." Agent saves: {user_id: 42, pref_units: "metric"} into a key-value store.

Session 2, a week later. User: "How far is the moon?" Agent loads user profile on start, sees pref_units: "metric", answers "about 384,400 km" instead of miles. The agent "remembers" without ever being told again.

That's the payoff. A 20-byte row in a key-value store turns a stateless model into one that feels like it knows you.

Staleness: the silent killer

A preference from 2024 might be wrong in 2026. A fact stored once becomes a lie the agent confidently repeats. Build in:

Privacy and isolation

Long-term memory is where data leaks happen. Make sure:

Pitfalls

What to do with this