DawnLoop

Blog

Long-term memory for AI agents: the four approaches

A field guide from a team building one: how each approach works, what it costs, where it breaks, and what's still a research bet.

Every session with an AI agent starts in the same place: an empty context window. The model’s weights don’t change while you talk to it, so whatever the agent knew about your project yesterday is gone unless something outside the model carried it over. Long-term memory for AI agents is the name for that something.

There are four ways to build it. You can put memory in the prompt, retrieve it from a store of embedded text, keep it in a structured graph that gets consolidated over time, or train it into the weights. This guide covers how each one works, what it costs, and how it fails. We’re building DawnLoop around the third approach, so weigh our take on the other three with that in mind.

Last verified: October 12, 2026.

What is AI agent memory?

AI agent memory is any information an agent can use in a later step that isn’t in its current input. The most useful map of the territory is the CoALA paper (Sumers et al., Cognitive Architectures for Language Agents). It borrows from decades of cognitive-architecture research and splits agent memory into four kinds:

  • Working memory: what’s active right now. For an LLM agent, mostly the prompt for the current call.
  • Episodic memory: records of past experience, such as earlier conversations or task runs.
  • Semantic memory: knowledge about the world and about the agent itself.
  • Procedural memory: how to act. It lives in the model’s weights and in the agent’s own code and prompts.

Two more distinctions matter in practice. Short-term memory lasts for one session or thread, while long-term memory survives across sessions. And memory can be given (a rules file you wrote) or learned (something the agent wrote down itself). Most of the hard problems are in learned long-term memory. We go deeper on the episodic and semantic layers in Episodic vs semantic memory for AI agents.

What is LLM long-term memory, and why don’t models have it already?

A language model’s weights are fixed while you use it. At the model level, each call is independent: the model reads the tokens it’s sent, writes tokens back, and keeps nothing. The “memory” in a chat product is the application re-sending the conversation, or a summary of it, with every request.

So LLM long-term memory always means one of two things. Either a system around the model stores information and puts the relevant part back into the prompt, or the weights themselves change. People also call the first kind persistent memory: state that outlives the session. Nearly every working system today is the first kind. The second is still mostly research for this use case, for reasons covered below.

What makes an AI agent stateful?

A stateless agent treats every session as its first. Stateful AI agents carry something between runs: task progress, user preferences, facts about the codebase, what happened the last time they tried a deploy. Whatever the mechanism, a memory design has to answer three questions:

  1. Write: what gets stored, when, and by whom?
  2. Read: how does the right piece come back at the right moment, inside a limited context window?
  3. Change: what happens when something stored goes stale, or is contradicted by something newer?

Most systems are good at the first, decent at the second, and weak at the third. The third question is also where the four approaches differ most.

The four approaches at a glance

Approach Where memory lives How it’s read Cost profile Main failure mode Can a person inspect and fix it?
1. In-context (instruction files, history) Text files and transcripts loaded into the prompt All of it, every session Tokens on every call. No infrastructure Doesn’t scale. Long prompts dilute attention. Goes stale unless someone edits it Yes. It’s a text file
2. Vector RAG over chunks Embedded text chunks in a vector index Top-k similarity search per request Cheap writes and reads Returns similar text, not current truth. Contradictions sit side by side Partly. You can read the chunks, but there’s no “belief” to check
3. Graph memory with consolidation Typed nodes and edges: events, entities, beliefs Walk from a cue to a relevant subgraph Costlier writes (extraction, consolidation). Reads stay small Bad extractions and generalizations harden into wrong beliefs Yes, if beliefs carry provenance
4. Weight updates (fine-tuning, continual learning) Model parameters or an adapter Implicitly, on every token Training and evaluation runs. Many model variants to serve Forgets old skills, weak at new facts, hard to audit or delete No. You can’t see or remove one fact

The approaches aren’t mutually exclusive. Most real systems stack two or three of them.

Approach 1: in-context memory and instruction files

How it works. You write down what the agent should know and load it into the prompt at the start of every session. Coding agents have converged on this. Claude Code reads CLAUDE.md, and AGENTS.md is an open format that more than twenty coding tools support. Claude Code’s memory documentation states the underlying problem plainly: “Each Claude Code session begins with a fresh context window.” Its instruction files and its auto memory (notes the agent writes itself from your corrections) are both loaded at the start of every conversation.

A more ambitious variant lets the agent manage its own context. MemGPT treats the prompt the way an operating system treats RAM: a fixed-size working context that the model edits through function calls, backed by external storage it can page information in from. That shades into retrieval, but the core idea is the same. Memory is whatever is in the window.

Cost. No infrastructure, but every token is paid for on every request. Prompt caching makes a repeated prefix cheaper. It doesn’t make it free, and the tokens still take up room in the window.

Failure modes.

  • It doesn’t scale. Claude Code’s docs recommend keeping each CLAUDE.md under 200 lines, because “Longer files consume more context and reduce adherence.” Its auto memory index loads only the first 200 lines or 25 KB.
  • Position matters. Lost in the Middle (Liu et al., 2023) found that models use information at the start and end of a long input much better than information in the middle.
  • It only knows what someone wrote down. A rules file holds the conventions somebody remembered to record. It doesn’t capture the bug you fixed twice or the decision you reversed in March unless someone edits it, and then it goes stale until someone edits it again.

Use it when the knowledge is small, stable, and worth stating explicitly. Every project should have one. Our post on why AI coding assistants forget covers what rules files fix and what they don’t.

Approach 2: retrieval over embedded chunks (vector RAG)

How it works. Split text into chunks, embed each chunk as a vector, and store the vectors in an index. At request time, embed the query, pull the most similar chunks, and paste them into the prompt. The pattern was named in Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (Lewis et al., 2020), which paired the knowledge in a model’s weights with a searchable index of documents. For agent memory, the documents are past conversations, notes, and logs.

Cost. Low. A write is an embedding call. A read is a nearest-neighbour search plus whatever tokens the retrieved chunks add. It scales to large collections, and it’s a strong baseline: a study of knowledge injection found that RAG consistently outperformed unsupervised fine-tuning, both for knowledge the model had seen in training and for entirely new knowledge.

Failure modes.

  • Similar isn’t the same as relevant. The chunk that shares the most vocabulary with the question isn’t always the one that answers it.
  • Contradictions sit side by side. If last quarter’s notes say “we deploy over SSH” and this month’s say “never deploy over SSH”, both are retrievable, and nothing marks which one is current.
  • No “what changed and why”. Chunks are snapshots. The link between a decision, the incident that caused it, and the code it changed is spread across chunks, if it was written down at all.
  • Questions about the whole collection are hard. Microsoft’s GraphRAG paper notes that standard RAG struggles with questions such as “What are the main themes in the dataset?”
  • Nothing is learned. Every request re-reads raw text and re-derives its conclusions, inside a latency budget.

Use it when you have a large body of mostly static text, and questions that a few passages can answer. We compare it with graph memory in detail in Graph memory vs vector RAG.

Approach 3: structured graph memory with consolidation

How it works. Memory is stored as typed nodes and edges instead of interchangeable chunks. Nodes can be events (“deploy failed, rolled back”), entities (a service, a file, a person), and beliefs (“this team deploys through CI”). Edges say how they relate: about, derived from, contradicts, supersedes. Retrieval starts at a cue and walks the graph to the relevant neighbourhood.

To be clear, this is still retrieval. The bet is that retrieval over a structured, maintained substrate beats retrieval over a pile of chunks, because the structure keeps information that similarity search throws away: time, provenance, and which facts have been overruled.

Several published systems take this shape:

  • Zep builds a temporally-aware knowledge graph called Graphiti. Its edges carry validity timestamps. When new information contradicts an existing edge, the old edge is marked invalid from that point on, so the history is kept.
  • GraphRAG extracts an entity graph from documents and pre-generates summaries for clusters of related entities, aimed at questions about a whole corpus.
  • Generative Agents (Park et al., 2023) kept a stream of observations and periodically synthesized higher-level “reflections” that cite the records they came from. The agents reflected roughly two or three times a day.

That last step, turning many raw events into a few durable conclusions, is consolidation. It’s what separates memory that accumulates from memory that just piles up. Consolidation can run at write time, on every message, or offline in a batch when nobody is waiting. We cover the steps (replay, consolidate, prune, strengthen) in Memory consolidation for AI agents, and the forgetting half in Forgetting in AI memory.

Cost. Writes cost more, because extracting entities and beliefs usually takes model calls, and consolidation takes more. Reads can be cheap and small, because the graph lets you pull a targeted subgraph instead of the top-k chunks. Here’s what that looks like in our prototype. A question on the second day of a synthetic demo pulls a dozen nodes, not the whole graph (real output, trimmed):

episode[13] Deploy the auth changes straight to production | outcome: fail
episode[1] Split auth middleware out of the router | outcome: ok
episode[10] Refactor the auth service to support OpenID Connect | outcome: ok
...
belief[6] Team uses service objects, not fat models | conf: 0.69 | salience: 0.368
(12 nodes pulled from 16 in the graph)

The numbers are tiny on purpose. The point is the shape: episodes carry outcomes, beliefs carry confidence and a retrieval weight, and the prototype caps what it pulls so the context stays the same size as the graph grows.

Failure modes.

  • Errors harden. A bad extraction or a hasty generalization becomes a belief, and beliefs get retrieved with more authority than raw text. Consolidation needs a signal from outside the model, not just the model’s opinion of its own work.
  • Contradiction handling is hard. Deciding that new evidence overrules a particular belief, and not a nearby one, is a judgment call. Our prototype gets this wrong in instructive ways, which the consolidation post walks through.
  • Ranking is a design problem. Which memory wins when ten are relevant? Scoring by recency, importance and relevance goes back to Generative Agents. DawnLoop is designed to add outcome magnitude and contradiction pressure. See Salience scoring for agent memory.
  • More moving parts. A schema, an extraction pipeline, a consolidation job, and evaluations for all of them, compared with one vector index.

Use it when the memory changes over time, contradictions matter, and you need to answer “why do we believe this?” Codebases fit that description well. Decisions get reversed, and tests, merges and reverts are outcome signals that already exist.

Approach 4: changing the weights (fine-tuning and continual learning)

How it works. Train the model on the agent’s accumulated experience, so the knowledge lives in the parameters instead of the prompt. Full fine-tuning is expensive. Parameter-efficient methods such as LoRA freeze the base model and train small added matrices, which makes per-customer adapters plausible. Continual learning is the version where this repeats as new experience arrives.

CoALA classifies the weights as procedural memory, and warns that writing to procedural memory “is significantly riskier than writing to episodic or semantic memory, as it can easily introduce bugs or allow an agent to subvert its designers’ intentions.”

Cost. Training runs, an evaluation suite to catch regressions, and the work of serving and versioning many model variants. The update cycle is slow: hours or days, not one request.

Failure modes.

  • Catastrophic forgetting. Training on new data can degrade what the model could already do. An empirical study found forgetting in models from 1B to 7B parameters during continual instruction tuning.
  • Weak at new facts. The knowledge-injection study mentioned above found that models struggle to learn new facts through unsupervised fine-tuning.
  • Opaque. You can’t open a model and see what it learned, correct one belief, or delete one fact a user asked you to forget. Rolling back means reverting the whole adapter.

Use it when you want to change behaviour (style, format, a skill) rather than store facts, and you can afford the evaluation work. For facts that change, retrieval is the better substrate.

How do you choose?

A practical order, cheapest first:

  1. Start with an instruction file. It’s free, versioned with your code, and fully inspectable. Keep it short.
  2. Add retrieval when the material outgrows the window: documentation, past tickets, transcripts.
  3. Move to structured memory when change over time matters. If you keep hitting “it retrieved the old decision”, or you need to know why the agent believes something, more chunks won’t fix it.
  4. Treat weight updates as an optimization, not a memory store. Gate them behind an evaluation that the memory-only version has to lose first.

If you’d rather adopt than build, our comparison of the best AI agent memory frameworks covers the open-source options.

Where DawnLoop fits

DawnLoop is in development. It’s designed around approach 3: a typed memory graph with an episodic layer and a semantic layer, a small working context, and a nightly pass that consolidates the day’s work using outcome labels such as tests, merges and reverts. That graph-only pass is planned, and it’s the product. Distilling knowledge into per-customer weights is a separate research bet that ships only if it beats the graph-only version on a real evaluation. The full architecture is on How it works.