Designing Long-Term Memory for LLM Agents

2026-10-02

A longer context window does not automatically give an agent reliable memory. When every past message is copied into a prompt, cost and latency grow, relevant facts become harder to find, and old or contradictory details can mislead the model. A memory system should decide what is worth retaining, when it is relevant, and when it should be removed.

Separate working context from durable memory. Working context contains the current request, recent turns, and temporary task state. Durable memory may hold user-approved preferences, stable facts, project decisions, or lessons from prior tasks. Store only information that will change a future action; do not persist every conversation or treat a model’s inference as a verified fact.

Define a memory record with provenance and lifecycle fields: content, source, subject or tenant, creation time, last confirmation, confidence, sensitivity, expiry, and deletion status. Keep memories scoped to the person, project, or organization that owns them. Resolve contradictions explicitly by preserving time and source—for example, a role that changed—rather than presenting two facts as simultaneously current.

Treat writing to memory as a controlled operation. Extract candidate facts, validate them against policy, deduplicate or update existing records, and require user confirmation for sensitive or high-impact details. Let users inspect, correct, export, and delete their stored information. Apply access controls before retrieval; memory is data, so prompt injection or cross-tenant leakage can enter through it too.

Retrieval should be selective. Combine semantic similarity with metadata filters, recency, importance, and task relevance; then send only a small, cited set of records to the model. Ask the agent to distinguish remembered facts from current observations and to say when no reliable memory was found. A memory search result is context to verify, not an instruction or proof of truth.

Evaluate memory behavior directly: can the agent retrieve a fact after many turns, update a changed preference, avoid using irrelevant personal details, notice contradictions, and forget information on request? Measure retrieval precision and recall as well as task outcomes, privacy mistakes, token use, and latency. Include multi-session cases and test with different wording; a memory that is stored correctly but cannot be found is not useful.

Start with the simplest store that meets the product’s needs—often relational records plus text search or vector retrieval—and add graph or consolidation steps only when evaluations show a gap. Memory research highlights retrieval, updating, long-range understanding, and selective forgetting as distinct capabilities. Keep a deletion path and an auditable trail from the beginning. Reference: https://aclanthology.org/2026.acl-long.27/

Give the next product someone who stays.

Ready to get started? Send me a message - I'm available to start now and to stay. Long-term retainers, not a two-week handoff. Let's discuss your project, requirements, and the best way to move forward.

Ask about experience or services