Skip to content

What is AI agent memory?

What AI agent memory is, why a context window isn’t memory, short-term vs long-term memory, how memory is measured, and how to add memory to an agent.

Zain Ali, VP Engineering & Product at Alexein AI

Zain Ali · 7 min read

An AI agent with memory remembers what happened before: who it’s working for, what they asked for last week, what was decided and what has changed since. Without memory, every session starts from zero. You explain the project again, paste the same notes again, and the agent repeats mistakes it has already made.

This guide explains what agent memory is, why a bigger context window doesn’t replace it, the kinds of memory an agent uses, what is worth keeping, how memory is measured, and how to add it to an agent. It’s written by the team that builds Alexein, an AI memory for agents, so every number links to its source.

What agent memory is

Agent memory is the part of an agent that keeps information from one model call to the next, and from one session to the next, and brings back the right piece when it’s needed. A language model on its own remembers nothing: it knows what it learned in training and what is in the prompt in front of it. Anything an agent seems to remember, it remembers because something put it back into that prompt.

So agent memory has two jobs.

  • Keeping. Deciding what is worth holding on to from a conversation, a document or a tool’s result, and keeping it up to date when it changes.
  • Recalling. Finding what matters for the question in front of the agent, and handing it over in a form the model can use: small, current, and with where it came from.

Good agent memory is also personal. An assistant serving a thousand people needs a thousand separate memories, and one person’s facts must never reach another person’s answer.

Why a context window isn’t memory

Models now read hundreds of thousands of tokens, some a million. It’s tempting to put the whole history in the prompt and call it memory. That works for a while, then it fails in three ways.

  • Cost and speed. Every token in the prompt is paid for on every call, and long prompts are slow. A history that grows every day makes every answer dearer than the last.
  • Accuracy. Models read long prompts unevenly. A fact buried in the middle of a long history, or stated once and corrected later, is easy to miss, or to answer with its old value.
  • Limits. Some histories are bigger than any window: BEAM, a public benchmark, uses conversations of about a million tokens. And a window holds one session. It’s empty again when the next one starts.

Our own runs show the difference. On MemoryAgentBench’s test of facts that keep changing, the same model scored 36.0 reading the whole history (262K tokens), and 94.0 reading what Alexein handed it instead. On LoCoMo, it was 80.6 against 94.6. The same model answered the same questions both times; only the memory changed. The benchmarks page has each setup and source, and notes where the grading differs.

A context window is the agent’s working memory: what it is thinking about right now. Long-term memory decides what goes into it.

Short-term and long-term memory

Short-term memory is what the agent holds within one task or session: the conversation so far, the plan, the results of the last few tool calls. It lives in the prompt, and it’s gone when the session ends, or sooner, when the window fills and old turns are cut or summarised.

Long-term memory lasts across sessions, apps and agents. It holds who the user is, what they prefer, what was decided and why, and what happened last time. It lives outside the model, somewhere the agent can save to and search, and only the part that matters is brought into the prompt.

Most useful agents need both: short-term memory to get through a task, and long-term memory so the next task doesn’t start from zero. When people talk about “AI memory” or long-term memory for LLMs, they usually mean the second.

The four kinds of memory

A useful map comes from cognitive science, by way of the CoALA paper, Cognitive Architectures for Language Agents (arXiv 2309.02427). It sorts an agent’s memory into four kinds.

  • Working memory: what the agent is using for the current step. For a language agent, that’s the prompt: the task, the recent turns and whatever was just recalled.
  • Episodic memory: what happened, and when. Past conversations, past runs, the meeting where a date moved. Episodes let an agent answer “what did we decide last time?” and learn from what went wrong.
  • Semantic memory: what is true. Facts about the user, the project and the world: “Maya is vegetarian”, “the launch is on 20 March”. Good semantic memory keeps up as facts change, so the newest value wins and the old one is still there, dated, to explain the change.
  • Procedural memory: how to do things. The model holds most of it, and the agent’s code the rest, but it also covers what is learned along the way: a codebase’s conventions, or how a user likes things written.

In practice the kinds overlap. A note that a deploy failed is an episode; the lesson drawn from it is a fact, or a new way of doing things. What matters is that the agent can find each one when it needs it.

What to keep, and what to let go

Not everything an agent sees is worth remembering. A memory that keeps every message is a slower copy of the history; one that keeps too little forgets what mattered. Three questions help.

  • Will it matter again? Preferences, decisions, deadlines and the reasons behind them usually will. Small talk and one-off lookups usually won’t.
  • Is it still true? Facts change: a launch moves, a price is agreed again, someone changes teams. Memory should keep the newest value in front and the earlier ones behind it, dated, so the agent can answer both “when is the launch?” and “when was it before?”.
  • Whose is it? Memory about a person belongs to that person. They should be able to see it, correct it and erase it, and an agent serving someone else should never see it.

Letting go matters as much as keeping. A fact that is no longer true is worse than no fact at all, because the model will use it with confidence. Good memory updates it, or makes plain that it’s out of date.

How agent memory is measured

Memory is measured with long histories and questions whose answers are somewhere in them. Three public benchmarks are the most cited.

  • LoCoMo: long conversations over many sessions, weeks apart, with 1,540 questions about single facts, facts that take several turns to put together, dates, and open questions.
  • LongMemEval: 500 questions over long chat histories, testing finding a detail, reasoning across sessions, time, information that was later updated, and knowing when not to answer.
  • BEAM: conversations of about a million tokens each, with 700 questions on its 1M-token split, every conversation bigger than the answering model’s window.
Published scoreshigher is better
BenchmarkAlexeinOthers, as published
LoCoMo, same answer model94.694.03 MindMemOS, 93.9 Mnemis, 85.2 Zep, 73.4 LangMem, 66.3 Mem0
LongMemEval-S91.693.4 Mem0 Platform, 91.0 Mem0 OSS in the same setup
BEAM, 1M tokens, same harness63.4964.09 Mem0

Alexein’s scores are self-reported; everyone else’s are as their sources publish them, from MindMemOS, Mnemis, Mem0’s blog and BEAM. The benchmarks page has every setup.

Alexein leads on LoCoMo with the same answer model, and on LongMemEval it is ahead of Mem0’s open-source release in the same setup. When you read any memory benchmark, including ours, look for three things.

  • The same answering model for every system. A stronger model raises every score, memory or not.
  • Who ran it. A vendor’s own numbers and a paper’s runs of the same system can differ a lot.
  • How much the memory hands the model. A system that hands over everything is just a long context.

How to add memory to an agent

There are two common ways in, and they suit different agents.

With an SDK, for agents and apps you build. Your code decides when to save and when to recall. A typical loop: before the model answers, search memory with the user’s message and put what comes back into the prompt; after it answers, add the exchange to memory. Each user gets a memory of their own, named by an id your app already has. Alexein’s Python and TypeScript SDKs do this in two calls (the quickstart shows them), with adapters for LangGraph, CrewAI, the OpenAI Agents SDK and n8n on the integrations page.

Through MCP, for agents you use. Claude Code, Cursor, Claude, ChatGPT and other MCP clients can connect to an MCP memory server and get memory tools; the model decides when to search and when to save. Alexein’s hosted MCP server is one URL for all of them (setup in the docs), so what you tell one assistant, the others can recall.

Either way, four choices decide whether memory helps.

  • Keep each user apart. Whose memory a request reads should be set by your app and enforced by the memory, not left to a filter the model could get wrong.
  • Keep it current. When a fact changes, the new value should win, and the old one should stay, with its date.
  • Hand over little. Recall should return what the step needs, with sources, not the whole history.
  • Let people see it and erase it. What is remembered about someone should be theirs to look at and to delete.

If you’re choosing a memory layer, our comparisons of Alexein with Mem0 and Zep compare scores, setup and price, with every source linked.

Questions

What is AI agent memory?

Agent memory keeps what an AI agent learns between model calls and between sessions, such as who the user is, what was decided and what changed, and brings back the part that matters when the agent needs it. Without it, every session starts from zero.

Is a bigger context window the same as memory?

No. A context window holds one session’s text, is paid for on every call, and is read unevenly when it is long. Long-term memory keeps information across sessions and hands the model only what the current step needs.

What is the difference between short-term and long-term memory in AI agents?

Short-term memory is what the agent holds within one task, in its prompt, and it is gone when the session ends. Long-term memory lasts across sessions, apps and agents, lives outside the model, and is searched when it is needed.

How do I add memory to an AI agent?

In an agent you build, use a memory SDK: save what each user says, and search it before the model answers. For assistants you use, such as Claude Code, Cursor, Claude and ChatGPT, connect an MCP memory server, which gives the model tools to save and search.

How is agent memory measured?

With long histories and questions whose answers are somewhere in them. LoCoMo, LongMemEval and BEAM are the most cited. Compare scores only where the answering model and the setup match.