lockstep
5 min readNaman Jain

How to give an AI agent memory: 5 approaches, simplest first

How to give an AI agent memory: message history, compaction, memory files with Anthropic's memory tool, a memory store, and shared team memory, compared.

A support agent helps a customer on Monday, learns they're on the enterprise plan and hate long replies, and on Tuesday asks for their plan again. The model is fine. The agent has no memory: each conversation starts from nothing.

There are five common ways to fix that, from a list of messages to a shared memory service. This guide goes from simplest to most involved, drawing on Anthropic's memory tool documentation and LangChain's memory guide, checked on 16 November 2026. Use the first one that covers your case.

First, what kind of memory?

LangChain's guide, following the CoALA paper, splits long-term agent memory into three types:

TypeStoresAgent example
SemanticFactsA user's plan and preferences
EpisodicExperiencesHow the agent solved a similar ticket before
ProceduralRulesThe agent's instructions, refined from feedback

And it separates two scopes: short-term memory within one conversation, and long-term memory across conversations. Knowing which you need rules out most options.

1. Message history (within a conversation)

The baseline. Send the conversation so far with each request. Every chat app does this.

Limit: history grows until it doesn't fit, and long before that, models get worse at using it. Anthropic calls this context rot.

2. Trimming and compaction (long conversations)

When history grows, cut or summarize it. Drop old tool results, keep the last N messages, or replace older turns with a summary. On the Claude API, context editing clears tool results on the client, and server-side compaction summarizes the conversation as it nears the context limit.

Limit: summaries lose detail, and nothing survives the end of the conversation. See compaction.

3. Memory files (across sessions)

Let the agent write notes and read them later. This is the simplest form of long-term memory, and Anthropic's memory tool is built for it.

Add {"type": "memory_20250818", "name": "memory"} to the request's tools. Claude then checks its /memories directory before starting a task and asks to create, read, edit, insert into, rename, or delete files as it works. The tool is client-side: Claude requests each operation, and your application performs it on storage you choose, such as a directory per user.

Anthropic's docs list what you're responsible for:

  • Path traversal: reject any path outside /memories, including ../ and URL-encoded forms. Resolve paths and check they stay inside.
  • Sensitive data: strip it before writing.
  • Size: cap file sizes and how much a read returns.
  • Expiry: delete files that haven't been used in a long time.

For long software tasks, Anthropic suggests a deliberate pattern: the first session creates a progress log and a feature checklist; every later session reads them first and updates the log before it ends.

Limit: files work while there are few of them. Once the agent can't list and skim its memories, it needs search.

4. A memory store with search (many users or facts)

Store memories as records, scoped by user or namespace, and retrieve the relevant ones per request, by semantic search, filters, or both. LangGraph's store and dedicated memory services work this way.

Two design choices matter, per LangChain's guide:

  • Profile or collection. One document per user that the agent keeps updating, or many small memories it adds to. Profiles are easy to read but easy to overwrite; collections lose less but need good search and deduplication.
  • When to write. In the hot path, the agent saves memories as it responds, which is immediate but adds latency. In the background, a separate process extracts memories after the conversation.

For a comparison of the main services, see Mem0 vs Zep vs Letta vs Supermemory.

Limit: memories are extracted by a model, so they can be wrong, duplicated, or stale, and nothing marks which one is current.

5. Shared, owned memory (facts a team must agree on)

Approaches 1 to 4 remember what one agent learned. Some facts aren't learned; they're decided. "Refunds over $500 need a manager" or "we're keeping the v1 API until March" must be the same for every agent and every person, have an owner, and change only when that owner says so. A memory one agent inferred from a conversation is the wrong place for them.

These need a shared record with an owner, a status, and a history, which agents read but don't rewrite on their own. See agent memory vs context window vs RAG for where each fits.

Which to use

SituationStart with
Single conversationsMessage history
Long conversationsHistory plus compaction
One agent across sessionsMemory files
Many users, many factsMemory store with search
Decisions shared across a team and its agentsA shared, owned decision record

Most agents need two of these: compaction for the conversation, and one long-term layer.

Where Lockstep fits

Lockstep is the fifth approach for software teams. It captures decisions from PRDs, Slack, and pull requests, routes each to its owner for approval, and serves them to agents: Claude Code sessions get a briefing on the approved decisions that apply to the work, and any MCP client can query them. A decision changes only when its owner approves the change.

See how it works.

Sources checked 16 November 2026

For memory in coding agents specifically, see the AI coding agent memory guide. For Claude Code's built-in memory, see how Claude Code memory works. For alternatives to Mem0, see Mem0 alternatives. For agents with built-in memory loops, see Claude Code vs OpenClaw vs Hermes Agent.

Frequently asked questions

How do I give an AI agent memory?
Pick by scope. For one conversation, keep message history and summarize it as it grows. For memory across sessions, have the agent write and read notes in files or a database. For many users or a large body of facts, use a store with search. Start with the simplest one that covers your need.
What types of memory do AI agents use?
LangChain's memory guide, following the CoALA paper, uses three: semantic memory for facts, such as a user's preferences; episodic memory for past experiences, often used as few-shot examples; and procedural memory for rules, usually the agent's own instructions or system prompt.
What is Anthropic's memory tool?
A Claude API tool that lets Claude create, read, edit, and delete files in a /memories directory across conversations. It runs client-side: Claude requests file operations and your application performs them on storage you control. You must block paths outside /memories.
Do I need a vector database for agent memory?
Not always. Files or a simple key-value store cover many agents, and the agent can read what it needs. Search, semantic or keyword, becomes useful when memories grow too many to read or list, or when they're spread across many users.
What is the best AI agent memory framework?
It depends on whether you want a hosted service, a library, or a full agent runtime, and on whether you need memory per user or for a team. Mem0, Zep, Letta, and Supermemory take different approaches; compare them on retrieval, temporal handling, and hosting before choosing.

Keep reading