Agent Memory: 4 Designs Tested Across 12 Sessions

OpenRouter ·

Agent Memory: 4 Designs Tested Across 12 Sessions

A model doesn’t remember anything between API calls. End a chat with your coding assistant, open a new one, and it has forgotten that your repo uses pnpm, that nobody pushes to main, and which host runs staging. When an agent does seem to remember you, it’s because your app saved something from an earlier session and put it back into the prompt.

There are several ways to do that, and they differ most in how much they send with each request. We ran the same 12 sessions through the four common designs on three models. You’ll see what each design got right, what it cost per request, where it broke, and which one to build first.

Tl;dr

  • Summary notes, retrieval, and notes plus retrieval each scored 47 of 48 on recall questions. Full history scored 46 of 48 while sending about 150 times as many tokens per request as summary notes.
  • Every memory design got stable facts, updated facts, and one-time config details right in every run.
  • Counting events across sessions was the weakest question. A structured JSON event log made it worse, so record countable events in a database your agent can query.
  • Start with summary notes, and add retrieval when users ask about exact details from old chats.

What is agent memory?

Agent memory is the information your application saves from earlier conversations and adds to new prompts, so an AI agent can use what it learned in past sessions. Inside one session, the conversation is the agent’s short-term memory, because you send the whole transcript with each request.

Across sessions, an LLM has no memory of earlier chats. To give it long-term memory, you decide what to keep from past transcripts, where to store it, and how much of it to send with each new request.

This is a separate problem from keeping one long run inside the context window. If you need to shrink an active transcript during a long task, see our cookbook on compacting long agent sessions. This article is about carrying facts from session 1 into session 13 without resending every line of code written in between.

What are the main ways to give an agent memory?

Most applications use one of four designs:

  1. Full history replays every past message in every new request.
  2. Summary notes use a model after each session to rewrite a short memory file, and that file goes into the system prompt of the next session.
  3. Retrieval embeds past messages, and for each new question, your app sends the closest few messages.
  4. Notes plus retrieval sends both the notes file and the retrieved messages.

Line chart comparing prompt token growth across 12 sessions for four agent memory designs: full history, summary notes, retrieval, and combined.

Each design does its work at a different time. Full history does nothing between sessions. Your app appends the new session to the old ones, so the prompt grows every time. Summary notes add a small step after each session, when a model rewrites the memory file. Retrieval embeds messages as they arrive and looks up the closest ones when a question comes in. Because it sends the original messages, retrieval keeps exact strings, like a hostname or a date, that a summary might drop.

How did each design do on the same 12 sessions?

Summary notes, retrieval, and notes plus retrieval each scored 47 of 48 correct answers. Full history scored 46 of 48. The scores were close, but the prompt sizes were far apart.

How we set up the test

We wrote 12 synthetic sessions between a developer and a coding assistant, in two versions generated from two random seeds. Each version came to about 345,000 characters, which is 95,000 to 130,000 tokens depending on the tokenizer. Every session had 24 ordinary coding requests and replies. Between them, at fixed points, we planted 19 facts, updates, and distractors.

The facts the agent needed to keep were:

  • A stable preference: “we use pnpm in this repo, never npm or yarn.”
  • A repo rule: “never push directly to main, always open a PR against develop.”
  • A one-time detail: the staging database is pg-stg-07.internal on port 6543.
  • Two updates: tests moved from Jest to Vitest in session 3, and the user moved from Lisbon to Berlin in session 7.
  • The v2 launch date, March 18.
  • Three staging deploy failures, in sessions 1, 3, and 9, caused by an out-of-memory (OOM) error in the build step.

The distractors looked like the real facts on purpose: a production database host, a teammate in Lisbon, the v1 launch date, an old Jest config, a production deploy failure, and two successful staging deploys.

In session 13, we asked the agent 8 questions with exact answers, each worded differently from the fact it tested.

#Question (paraphrased)Expected answerWhat it tests
1What should I use to install dependencies?pnpmStable preference
2Can I push to main, and which branch should I target?No, developRule
3What’s the staging database host and port?pg-stg-07.internal, 6543One-time detail
4Which test runner should new tests use?VitestUpdate
5Which city’s time zone should I use?BerlinUpdate
6How many times has the staging deploy failed, not counting production?3Count across sessions
7What’s the v2 launch date for the changelog?March 18Fact with a distractor (the v1 date)
8What kept breaking staging?An OOM in the build stepCause across sessions

We ran five setups, no memory plus the four designs, on Claude Haiku 5.5, GPT-6 Luna, and DeepSeek V4.1 Flash, each with reasoning.effort: "low". All three sit behind the same OpenRouter API, so switching models meant changing one string.

In the two notes designs, each model wrote its own notes after every session, using this instruction:

Rewrite the memory file. Keep durable facts, preferences, rules, credentials-free
config details, and events worth tracking (with counts). Replace facts that changed
instead of keeping both. Under 250 words. Output only the memory file.

For retrieval, we embedded every past message with mongodb/voyage-4 through our embeddings API. For each of the 8 questions, we took the 4 closest messages, 27 distinct messages in all, and injected them labeled with their session number. In production, pass retrieved transcript history as untrusted user or context data—clearly separated from trusted system instructions—so past tool output or pasted text cannot be followed as policy. Code scored all 48 answers per design (8 questions, 3 models, 2 seeds) by exact match.

The results

DesignCorrectClaude Haiku 5.5GPT-6 LunaDeepSeek V4.1 FlashMedian prompt tokensMedian time
No memory0 of 480 of 160 of 160 of 162612.4 s
Full history46 of 4816 of 1615 of 1615 of 1697,3414.9 s
Summary notes47 of 4816 of 1615 of 1616 of 166393.6 s
Retrieval47 of 4816 of 1615 of 1616 of 167853.0 s
Notes plus retrieval47 of 4815 of 1616 of 1616 of 161,1633.6 s

Times are from our setup and will differ in yours.

With synthetic sessions and 48 answers per design, a one-point gap between 46 and 47 is noise. The real difference is prompt size. Summary notes scored as well as full history while sending under 1% of the tokens per request.

Every memory design got the stable preference, both updates, the staging host, the launch date, and the cause of the failures right in every run. Apart from the count question, the only misses came from Claude Haiku 5.5. Twice it answered the push question with “no” but left out the develop branch, once with notes plus retrieval and once with a structured design we tried later.

Why do agents get counts wrong across sessions?

Agents get counts wrong because a model either mixes up similar events in a long transcript or drops the number when it summarizes a session. The staging failure count was the hardest question in our test. Across all memory runs, it was right 22 times out of 30.

Three of the four designs missed it at least once. With full history, GPT-6 Luna and DeepSeek V4.1 Flash both answered 4 on seed 2, because they counted the production failure even though the question said not to.

Retrieval made the same mistake once, with GPT-6 Luna. Summary notes failed differently. GPT-6 Luna answered “unknown,” and its notes show why: “Staging builds have had reported OOM failures,” with no number. The instruction asked the model to keep events with counts. It kept the event and lost the count. Notes plus retrieval was the only design that got the count right in all six runs.

We tried to fix this with a sixth design. The same model kept a JSON memory file in three parts:

  • Facts, holding current values that get overwritten when they change
  • Rules
  • Events, an append-only list with one entry per notable event per session, never merged or deleted

It scored 43 of 48, which is worse than plain summary notes. The count was right in only 2 of 6 runs, and the wrong answers were 2, 1, 4, and “unknown (at least 2 logged).” Over the 12 sessions, the event logs grew to between 24 and 79 entries, and the models logged the same kind of failure differently from one session to the next. The JSON file also made each request bigger, at a median of 3,297 prompt tokens, and writing it cost $0.017 to $0.060 per model over the 12 sessions.

A model that summarizes or logs events will sometimes miss one or count one twice. If your agent needs to count or total things across sessions, such as failed deploys or support tickets, record those events from your own code in a database table and give the agent a tool that queries it.

What does each memory design cost?

At request time, summary notes, retrieval, and notes plus retrieval cost between $0.00011 and $0.00051 per question set, depending on the model. Full history cost $0.012 to $0.066 for the same questions, and that number grows with every session you add.

DesignCost per question setBackground cost over 12 sessionsAs sessions pile up
No memory$0.00007 to $0.00021NoneStays flat
Full history$0.012 to $0.066NoneGrows every session
Summary notes$0.00011 to $0.00037$0.015 to $0.031 per model to write the notesStays about the same size
Retrieval$0.00018 to $0.00051$0.006 per seed to embed about 600 messages and the questionsThe prompt stays the same size; the index grows
Notes plus retrieval$0.00013 to $0.00043Both of the aboveStays about the same size

Cost per question set is one request that answers all 8 questions. At these prompt sizes, cost depends mostly on answer and reasoning length and, for DeepSeek, on which provider served the request, so the ranges overlap.

Full history cost $0.012 on GPT-6 Luna, $0.022 on DeepSeek V4.1 Flash, and $0.066 on Claude Haiku 5.5. Haiku’s tokenizer turned the same history into about 130,000 tokens instead of about 95,000. That put each request past Haiku 5.5’s 100,000-token mark, where its input price rises from $0.10 to $0.50 per million tokens. Full history was the only design that crossed it.

Summary notes also cost something between sessions. Each rewrite reads the whole session transcript once, which came to about $0.001 to $0.003 per session. Over all 12 sessions, writing the notes cost roughly the same as one full-history request in session 13.

How to build agent memory that holds up

Start with summary notes, add retrieval when users ask about exact details from old chats, and keep event counts in a database tool.

  1. Start with summary notes. In our test they scored as well as full history at under 1% of the tokens. Tell the notes writer to replace outdated facts instead of keeping both versions. Every model handled the Jest-to-Vitest and Lisbon-to-Berlin updates when asked to. Set a word limit and check it, because models drift past it. Ours said under 250 words, and the files ran from 170 to 340.
  2. Use a cheap model to write the notes. Because every model sits behind the same API, you can run your agent on a larger model and give the notes job to a smaller one. In our test, each model wrote its own notes, and GPT-6 Luna did it for about $0.0013 per session. We didn’t test the split setup, so check note quality on your own sessions before you rely on it.
  3. Add retrieval for exact details. When users ask about hosts, IDs, error messages, or dates from old chats, retrieval returns the original message instead of a summary of it. Embed past messages with our embeddings API, and label each retrieved message with its session number or date so the model can pick the newest value when a fact has changed.
  4. Keep counts and totals out of model memory. Log countable events from your app into a database table, and give the agent a tool that queries it.
  5. Save a run’s state, and keep memory separate. In our Agent SDK, callModel accepts a StateAccessor that saves one run’s ConversationState, so the run can resume after a crash, a deploy, or a human approval. It keeps the full message history, so for memory across sessions, pair it with summary notes rather than replaying the saved messages. See tool approval and state for the interface and the long-horizon agents cookbook for a full recipe. Our tutorial on how to build an always-on AI agent shows that split in practice. Its agent keeps a file of story IDs it has already seen as its long-term memory and starts each check with a fresh conversation.
  6. Test your memory design on your own sessions. Write questions with exact answers, and include updates and counts. Score each design with a short script, as we did.

Next steps

For memory across sessions, start with summary notes, and add retrieval with our embeddings API when users ask about exact details from old chats. To save and resume a single run’s state with a StateAccessor, see the long-horizon agents cookbook.

Frequently asked questions

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

Short-term memory is the transcript of the current session, which you send in the messages array with each request. Long-term memory is whatever your application stores when a session ends and puts back into later prompts, such as a summary file a model rewrites or past messages found by embedding search.

Is agent memory the same as RAG?

No. Retrieval-augmented generation (RAG) is one way to build agent memory, where you embed past messages and send the closest matches for each new question. Agent memory also covers designs without retrieval, such as summary notes, where a model rewrites a short memory file after each session and that file goes into the next session’s system prompt.

How do you stop an agent remembering outdated facts?

In a summary notes design, tell the model that writes the notes to replace facts that changed instead of keeping both versions. In a retrieval design, label each retrieved message with its session number or date so the model can tell which value is newest. In our 12-session test, every memory design got both planted updates right in every run.

Does a bigger context window replace memory?

Not on its own. Full history works while the transcript fits in the context window, as our history of 95,000 to 130,000 tokens did, but you pay for every past token on every request. In our test, full history sent about 150 times as many tokens as summary notes for the same score. Much longer histories also lose accuracy as the context fills up, which our post on context rot covers.

By subscribing you agree to receive the OpenRouter newsletter: model usage data, product updates, and research reports, about one email a week. Unsubscribe anytime via the link in every email. See our Privacy Policy.