AgentLearn

Memory systems

Memory is application-managed state. Decide what to remember, who may read it, and when it should expire.

Three different kinds of remembering

Working state records the current run. Conversation history preserves recent interaction. Durable memory stores selected information across sessions. None is free: old facts can become false, summaries can drop important qualifiers, and stored personal data creates privacy obligations. A customer's temporary shipping address should not silently become a permanent preference.

How it works

Store structured facts with provenance, creation time, expiration, and ownership. Separate user-provided preferences from model inferences. Retrieve only the memory needed for the current task. Provide an update and deletion path. A summary is a lossy representation, so keep the authoritative transaction record outside model-generated memory.

A concrete example

The support assistant remembers a user's preferred language for 30 days in this fictional policy. It does not remember payment credentials. At retrieval time, it checks both owner and expiry; a vector similarity match alone would not establish either condition.

Apply it to your assistant

Move now beyond the expiry and verify that the memory is no longer returned. Before running the exercise, predict the result. Afterward, explain which assumption changed and add one case where the system should refuse, ask for clarification, or escalate.

All exercise inputs and outputs are deterministic teaching examples. No language model is called. Run the same idea against a versioned dataset before making a production claim.

Key takeaway

Treat memory as governed data, not an ever-growing transcript.

JavaScript exercise: Memory systems · code experiment

Move now beyond the expiry and verify that the memory is no longer returned.

const now = 1000;
const memories = [
  { owner: 'u1', key: 'language', value: 'Spanish', expires: 1500, source: 'user preference' },
  { owner: 'u2', key: 'language', value: 'French', expires: 2000, source: 'user preference' },
];
console.log(memories.filter(m => m.owner === 'u1' && m.expires > now));

Knowledge check

What should durable memory include beyond the remembered value?

  1. Ownership, provenance, and a retention policy
  2. Only a high similarity score
  3. Every token from all conversations
Answer and explanation

Ownership, provenance, and a retention policy

Memory needs access controls and lifecycle rules. Similarity measures relevance, not permission or freshness.

Sources

Read this lesson as Markdown

Continue learning

  • Tools & function calling — A tool call is an untrusted request to application code. A schema describes the request; authorization determines whether it may run.
  • Memory systems — Memory is application-managed state. Decide what to remember, who may read it, and when it should expire.
  • Errors, retries & guardrails — A reliable agent distinguishes failures it can retry from failures that need a different decision or a human.
  • Agentic patterns — Choose the simplest control flow that matches the task: a pipeline, a router, a bounded loop, or a coordinated workflow.