---
kind: concept
slug: agent-memory
title: Agent memory
summary: >-
  How an LLM agent keeps and recalls information across its steps. Memory is a write, manage and read loop over three sources (current trial, past trials, external knowledge), stored as text or as weights. Shared memory can stage writes and commit only checked beliefs before irreversible actions. Results are author-reported; no open benchmark targets agent memory alone.
tags: [agents, memory]
papers: ["2404.13501", "2404.02831", "2406.14373", "2607.23929"]
related: [llm-agent, retrieval-augmented-generation, model-editing, tool-use, multi-agent-systems]
status: draft
updated_at: 2026-10-31
---

## Overview

An agent that acts over many steps needs a way to keep what happened and bring
back the part that matters for the next decision. The survey defines agent
memory as three operations applied to stored items: writing, management and
reading [arxiv:2404.13501 §3.4]. Every design in the survey is a choice of
where the information comes from, what form it is stored in, and how each
operation is carried out.

The survey's narrow definition keeps only the history of the current trial.
Its broad definition also draws on earlier trials, earlier tasks and external
knowledge [arxiv:2404.13501 §3.2] [arxiv:2404.13501 §3.3]. The LLM itself is
treated as a fixed function from memory and context to the next action, so
the memory design sits around the model [arxiv:2404.13501 §3.4].

A perspective on biomedical agents gives the same idea a module role. It
lists memory as one of four modules of a compound agent, next to perception,
interaction and reasoning. Short-term memory sits in the context window or in
latent embeddings. Long-term memory sits in the weights or in an external store,
and can be updated by fine-tuning, interactive learning, model editing, or by
editing the store itself [arxiv:2404.02831 §5.3]. The paper reports no
experiments, so it gives the vocabulary but no evidence for these options.

Once several agents or tools share one memory, a written item can be read and
acted on by others before anyone checks it. A wrong note can then lead to an
action that cannot be undone [arxiv:2607.23929 §1]. The survey's write
operation has no separate check step [arxiv:2404.13501 §3.4], so this is a
gap that the variant under "Admission of writes" addresses.

## Variants

Each variant is a choice along one of four axes. The survey gives no
benchmark that compares them, so the choices are listed here as design axes,
not as ranked options.

### Source of the memory

- **Inside the current trial.** The history of the present task. Almost all
  systems in the survey use it, but it cannot carry knowledge across tasks
  [arxiv:2404.13501 §5.1.1].
- **Across trials.** Summaries of earlier attempts, successful and failed,
  and the lessons drawn from them. Reflexion is the main example and
  Retroformer trains the reflection model [arxiv:2404.13501 §5.1.2]. Card:
  [Zhang et al., agent memory survey](/papers/2404.13501).
- **External knowledge.** Sources such as an encyclopedia, a game wiki, an API
  or a database. It gives facts the agent could not collect itself, and an
  API call can cut down on outdated knowledge [arxiv:2404.13501 §5.1.3].

### Form of the memory

- **Textual, complete.** The whole history is concatenated into the prompt.
  It is the simplest form, and its cost grows with the length of the history
  [arxiv:2404.13501 §5.2.1].
- **Textual, recent.** Only the last few steps or a time window are kept,
  based on the principle of locality [arxiv:2404.13501 §5.2.1].
- **Textual, retrieved.** Entries are embedded when written, scored against
  the current query when read, and the top-K are placed in the prompt. The
  survey leaves the similarity function open; Generative Agents combines
  similarity with recency and importance, and MemoryBank uses a dense
  retriever with FAISS indexing [arxiv:2404.13501 §5.2.1].
- **Parametric, fine-tuning.** Domain knowledge is injected into the weights
  with supervised training, often with LoRA. The survey notes the risk of
  catastrophic forgetting and the cost of repeating training
  [arxiv:2404.13501 §5.2.2].
- **Parametric, editing.** Only the facts that change are edited, and other
  knowledge is left alone. The survey lists MAC, MEND and KnowledgeEditor
  [arxiv:2404.13501 §5.2.2]. See [model editing](/concepts/model-editing).

Textual memory is more interpretable and cheaper to write. Parametric memory
is cheaper to read, because it adds nothing to the prompt. The survey states
this as its reasoning and gives no measurements [arxiv:2404.13501 §5.2.3].

### Operations

- **Writing** turns the latest action and observation into a stored item.
  The item may be the raw observation or a summary. Examples are an entity
  relation kept in a database (TiM) and topic keys (MemoChat)
  [arxiv:2404.13501 §5.3.1].
- **Management** merges similar items, reflects to form higher-level items,
  or forgets unimportant ones. Examples are daily summaries (MemoryBank) and
  reflection that runs once enough events have built up (Generative Agents)
  [arxiv:2404.13501 §5.3.2].
- **Reading** selects what the next action needs. The survey says this is
  usually a similarity computation. Examples are SQL queries (ChatDB) and
  top-K examples (ExpeL) [arxiv:2404.13501 §5.3.3].

### Admission of writes

This axis is about whether a written item is trusted at once. The survey does
not treat it as a separate design choice, so the two options below come from
the MemTX paper.

- **Direct write.** The item is stored and can be read as soon as it is
  written. This is how the surveyed designs work
  [arxiv:2404.13501 §3.4].
- **Staged, checked and committed.** A write starts as a tentative record. It
  becomes a belief only after four checks: evidence, validity window,
  semantic conflict with a belief already accepted, and no revoked ancestor
  [arxiv:2607.23929 §3.2]. Irreversible tool calls are blocked while any
  unsettled record the transaction did not read exists [arxiv:2607.23929 §3.3].
  Withdrawing a belief revokes its descendants by type: beliefs are
  revoked, derived views are rebuilt, and tool actions are compensated or
  logged as leaks [arxiv:2607.23929 §3.4]. Card:
  [MemTX](/papers/2607.23929).

## When to use which

| Situation | Use | Why |
|---|---|---|
| The task fits in the context window and the history is short | Textual, complete | Simplest. The survey says the cost grows with history length [arxiv:2404.13501 §5.2.1] |
| The history is long and only recent steps matter | Textual, recent | Keeps the prompt short; the survey ties it to locality [arxiv:2404.13501 §5.2.1] |
| The history is long and the needed item can be found by a query | Textual, retrieved | Reads only top-K entries. The survey gives no default for K [arxiv:2404.13501 §5.2.1] |
| The agent must learn from its own earlier attempts | Across-trial memory with reflection | Reflexion keeps lessons from failed trials [arxiv:2404.13501 §5.1.2] |
| The agent needs facts that are not in its own history | External knowledge | Gives facts the agent cannot gather itself [arxiv:2404.13501 §5.1.3] |
| A few facts change and the rest must stay the same | Parametric editing | The survey says editing leaves other knowledge unchanged [arxiv:2404.13501 §5.2.2] |
| Many examples of the same domain must be absorbed | Parametric fine-tuning | Adds knowledge without prompt length, but risks forgetting [arxiv:2404.13501 §5.2.2] |
| The memory must be inspected or written cheaply | Textual | More interpretable and cheaper to write, per the survey [arxiv:2404.13501 §5.2.3] |
| Shared memory feeds tools with real side effects, such as refunds or deletions | Staged, checked and committed writes with an action gate | The MemTX scope is this case; it reports 0.956 against 0.822 for the best baseline on its own 90-case suite with Qwen3-8B [arxiv:2607.23929 §5] [tab. 2] |
| One agent, no irreversible tools, memory written and read by the same loop | Direct write | The checks add verifier calls, 1.36 to 1.58 per case in MemTX's runs [arxiv:2607.23929 app. F]. This is a reasoned choice, not a measured one |

The survey gives no thresholds. It does not say at what history length a
design should change, so measure your own agent before choosing. The MemTX
results are on its authors' own suites, so measure your own tool set too.

## Implementation sketch

The loop is the same for all variants: write, manage, read, then act. The
variants differ in what `write`, `manage` and `read` do, as the survey's
unified formula shows [arxiv:2404.13501 §3.4]. The survey does not say
whether reading comes before or after management, so the order is a choice
to make and test.

```pseudocode
# One agent step with a memory  [arxiv:2404.13501 §3.4]
# Input:  memory M; the latest action and observation; the next context
# Output: updated memory M; next action

def agent_step(memory, action, observation, next_context):
    # Write: turn the raw interaction into a stored item  [§5.3.1]
    item = write(action, observation)
    # Manage: merge, reflect or forget over the stored items  [§5.3.2]
    memory = manage(memory, item)
    # Read: pick what the next action needs  [§5.3.3]
    recalled = read(memory, next_context)
    # Act: the LLM is a fixed function of the recalled memory  [§3.4]
    next_action = llm(recalled, next_context)
    return memory, next_action
```

For retrieved textual memory, `read` embeds the query, scores each entry, and
keeps the top K. Take K and the similarity function from your own tests, since
the survey does not fix either [arxiv:2404.13501 §5.2.1].

If the memory is shared and feeds irreversible tools, put a gate in front of
those tools. MemTX blocks the call while any tentative record is unsettled
and the transaction did not read it [arxiv:2607.23929 §3.3].

```pseudocode
# Action gate for one irreversible tool call  [arxiv:2607.23929 §3.3]
# Reversible tools are not gated.
def gate_allows(tx, store):
    # Block while an unsettled record exists that this transaction did not read  [§3.3]
    for record in store.records:
        if record.state == "tentative" and record.id not in tx.snapshot:
            return False
    return True
```

## Evaluation

The survey splits evaluation into two parts [arxiv:2404.13501 §6].

- **Direct tests** check the memory alone. Human judges can rate coherence
  and rationality. Objective measures are result correctness, reference
  accuracy as an F1 score against the memory that should have been used, and
  the time and peak GPU memory of each operation [arxiv:2404.13501 §6.1].
- **Indirect tests** measure the agent's task result, with and without the
  memory, as an ablation [arxiv:2404.13501 §6.2].

The survey notes that no open benchmark targets agent memory alone
[arxiv:2404.13501 §6.3]. MemTX builds its own suites instead: 90 scripted
cases with 60 traps and 30 controls, and a 56-case hardened suite
[arxiv:2607.23929 §4]. Its scorer is rule-based, and all systems in its
comparison share one harness, so only the memory manager differs
[arxiv:2607.23929 §4].

Two reported effects of memory design come from a multi-agent simulation
rather than a benchmark. Both are author-reported, use nine `gpt-3.5-turbo`
agents in one simulated world, and report no external baseline. Memory depth
has a negative correlation with convergence time (r = −0.3836, p < 0.001,
N = 83) [arxiv:2406.14373 §7.4]. Removing memory is reported with convergence
times of 21 and 36 days, but the text does not say which setting is which
[arxiv:2406.14373 §7.5]. Treat these as a hint to measure memory depth, not as
a tuned value.

## Contradictions

None known. The three cards measure different things: the survey classifies
designs and runs no experiments, the simulation measures convergence in one
world, and MemTX measures task success and harm on its own suites. No card
reports a number that another card disputes.

## Papers

- [Zhang et al., agent memory survey](/papers/2404.13501): a survey that defines agent memory by its write, manage and read operations and classifies 28 systems by source, form and operation. It runs no experiments.
- [Gao et al., AI agents for biomedical discovery](/papers/2404.02831): a perspective that sorts biomedical agents into four autonomy levels and names memory as one of four modules. It reports no experiments.
- [Artificial Leviathan](/papers/2406.14373): a simulation of nine LLM agents with a 30-action memory; it reports memory depth and deletion effects on convergence. It is a thought experiment, not a memory benchmark.
- [MemTX](/papers/2607.23929): a commit protocol for shared agent memory with staged writes, an action gate and typed cascading repair. Results are on the authors' own suites. The repository has no license, so only the method is described here.
