Skip to content

Lesson 5 of 9 · 28m

Memory That Does Not Become a Liability

Separate working context, episodic run history, semantic knowledge, and user memory — with retention, provenance, and deletion rules.

Memory is where agent products quietly become privacy products, compliance problems, and debugging nightmares. I have watched teams treat "memory" as one vector database bucket into which they throw conversations, secrets, customer facts, tool output, and half-correct summaries. Six months later nobody knows why the agent believes something, who it applies to, or how to delete it.

There is no single memory

At minimum, separate these stores:

working context    current run state, scratchpad, recent observations
episodic memory    what happened in prior runs and how they ended
semantic memory    stable facts or documentation, ideally curated
user memory        durable preferences or facts the user asked you to retain
procedural memory  learned workflows, policies, or reusable skills

They have different trust levels, retention periods, access controls, and deletion semantics. Lumping them together because embeddings are convenient is a category error.

Provenance beats confidence

Every memory record should answer: where did this come from, when was it written, who or what wrote it, what evidence supports it, and when it was last verified?

{
  "kind": "user_memory",
  "subject": "user_9182",
  "text": "Prefers concise status updates with direct links.",
  "source": "explicit user request",
  "created_at": "2026-11-30T18:02:11Z",
  "last_verified_at": "2026-11-30T18:02:11Z",
  "expires_at": null,
  "confidence": "high"
}

A fact learned from a user statement is different from a fact inferred by the model, which is different again from a fact read in a system of record. Retrieval that ignores provenance turns speculation into institutional knowledge.

Retrieval is a security boundary

Memory search can leak across users, tenants, and trust domains. Filter before similarity search, not after:

matches = memory.search(
    query=query,
    tenant_id=ctx.tenant_id,
    subject_id=ctx.user_id,
    visibility=["user", "team_shared"],
    kinds=["user_memory", "semantic_memory"],
    limit=8,
)

If your retrieval layer cannot enforce tenancy, do not bolt policy on in the prompt. Fix the data layer.

Summaries decay

Long-term memory is often stored as summaries. Summaries are lossy interpretations, not facts. Store source references or raw evidence when policy permits, and make summaries recomputable. Otherwise small errors compound into permanent hallucinations with citations missing.

Forgetting is a feature

Users need correction and deletion. Systems need expiration. Agents need the ability to say "I no longer trust this." Implement tombstones and ensure derived indexes actually remove or suppress deleted records. Vector deletion is operationally easy to get wrong when replicas, backups, and caches are involved.

Field notes

  • Never place secrets in memory, even if the user pastes them. Detect and redact before storage.
  • Similarity is not relevance permission. Retrieve narrow, then let the model reason over a small set.
  • Memory writes deserve validation just like external writes. A malicious tool result can otherwise plant instructions for future runs.
  • When debugging an agent belief, inspect the exact memory record and its provenance; do not argue with the model.

Was this lesson helpful?

Sign in to rate