← All questions
AgentsMedium· Agent Memory & State

How do you implement persistent memory for an agent acr...

An agent has no memory across sessions unless something outside the model gives it one — every new session starts from nothing. The standard pattern:

  1. At the end of a session, have the model itself summarize what’s worth remembering — key facts, preferences, decisions — rather than storing the raw transcript.
  2. Embed that summary and store it in a vector database, alongside a structured record for anything that’s an exact fact rather than a fuzzy preference (a user’s plan tier belongs in a normal database field, not a vector search).
  3. At the start of the next session, embed the new query and retrieve the relevant stored memories by similarity.
  4. Inject the retrieved memories into the system prompt so the agent opens the conversation already knowing the relevant history.

Two things matter beyond the happy path. First, memory staleness — without some recency weighting, a three-month-old preference can outrank something the user said yesterday, so retrieval should bias toward recent memories rather than pure similarity. Second, and often skipped until it’s a compliance problem: a deletion path. If memories are personal data, there needs to be a way to delete a specific user’s stored memories entirely, not just stop writing new ones.

Code playground (Python)