What is AI agent memory? How long-term memory for LLM agents works

Last updated

A language model remembers nothing between calls: everything it knows about your task has to be in its context window on that turn. AI agent memory is what fills that gap. The agent writes what it learns to a store outside the context window, and reads back the parts that matter on later turns or in later sessions. Long-term memory can be plain files, a vector database searched by meaning, a knowledge graph, or a memory service the agent reaches through tools. The hard parts are deciding what to save, finding the right piece later, and keeping old facts from crowding out new ones.

Short-term and long-term memory

Anthropic's engineering guide on context calls this technique "structured note-taking, or agentic memory": the agent "regularly writes notes persisted to memory outside of the context window," and those notes "get pulled back into the context window at later times." The same guide treats context as "a finite resource with diminishing marginal returns," which is why an agent can't simply keep everything loaded.

Four ways to build it

How it worksGood atWatch for
FilesInstruction and note files loaded into context, such as CLAUDE.md or AGENTS.mdRules every task needs; easy to read and keep in GitEvery line costs context in every session; long files are followed less closely
Vector searchText is split into chunks, embedded and searched by meaningFinding related text in a large pileChunks lose their context; stale chunks match as well as fresh ones
Knowledge graphFacts become entities and relations, often with datesQuestions about how things connect and change over timeExtraction costs model calls, and its mistakes are hard to see
Memory serverA service the agent reaches through tools (often over MCP) to save, search and edit notesSharing one memory across agents, sessions and computersYou trust the service with what you save; agents must be told to use it

These mix. Many memory services use vector search and a graph inside, and many agents use a short instruction file plus a memory service.

How memories get written

There are two broad approaches:

How memories get read

Most agents read long-term memory in two moments:

  1. At the start of a session, a short summary or index loads: what this memory is for and where the key notes are.
  2. Before a step, the agent searches for what that step touches and reads only the best matches.

Loading everything up front is the most common mistake. It costs tokens on every turn and buries the note that matters.

What goes wrong

Memory for coding agents

Coding agents such as Claude Code and Codex start each session with their instruction files and no memory of earlier sessions. Most teams start with CLAUDE.md or AGENTS.md, and add a memory server when the file gets too long or when several agents need the same knowledge. See Why your coding agent forgets between sessions and Keep CLAUDE.md short.

A worked example: Memlo

Memlo is a memory server for the agents you use. It takes the explicit-save approach:

It doesn't capture sessions automatically, and it has no SDK for building it into your own app. For that, see the frameworks compared in Mem0, Letta, Zep and Cognee.

Frequently asked questions

Do LLMs have long-term memory?

Not on their own. A model only sees what is in its context window on each call. Long-term memory is a store outside the model that the agent, or the app around it, reads from and writes to.

What is the difference between RAG and agent memory?

RAG usually means searching a fixed set of documents to answer a question. Agent memory is written by the agent as it works, and changes over time, so it also needs ways to update, replace and retire what it holds.

Should an agent remember everything?

No. Saving every step makes search worse and costs more. Save decisions and their reasons, how things work, preferences and mistakes not to repeat. Don't save numbers that change every day, or secrets.

How do several agents share one memory?

Connect them all to the same memory service and the same account or shared space. See How to share one memory between AI agents.

Sources

Checked on October 31, 2026:

Try Memlo

Memlo is invitation only for now. Join the waitlist and we'll email you when your invitation is ready.

Join the waitlist