Guide16 min read

Nikos Dritsakos, Founder

What is AI agent memory?

AI agent memory is state outside the model that an agent writes in one session and reads in the next. How it differs from weights, context and RAG.

On this page
  1. Short answer
  2. How agent memory differs from weights, context and RAG
  3. Scope, durability and content type are three separate choices
  4. The write path and the read path
  5. One coding decision, traced across three sessions
  6. Governance: staleness, access, deletion and poisoning
  7. Instruction files, built-in memory and team session history
  8. How to evaluate agent memory on real coding tasks
  9. Build only the layer you need
  10. Frequently asked questions

AI agent memory is state kept outside a language model that an agent writes during or after one run and reads back in a later one. The model's weights don't change. What changes is a store beside the model, and what gets loaded from it into the next prompt.

That definition is short, and most of the confusion sits around its edges: how memory differs from a long context window, whether RAG counts, what "short-term" and "long-term" refer to, and why a fact that was saved doesn't come back when it's needed. This guide works through each, with coding agents as the running example.

Short answer

  • Agent memory is external and persistent. It survives the end of a session and needs no retraining.
  • RAG isn't the opposite of memory. Retrieval is how memory gets read. Add a write path that records and replaces facts after each task and a RAG pipeline is a memory system.
  • Three design choices are independent: who can read a record (scope), whether it survives a restart (durability), and what kind of knowledge it is (content type).
  • Storing isn't recalling. A saved fact still has to be found, still has to be current, and the model still has to act on it.
  • You may not need a memory product. Checked-in instruction files and an agent's built-in memory cover standing rules. Searchable team history earns its place when the reasoning behind past work has to cross teammates and agents.

How agent memory differs from weights, context and RAG

A raw model call carries nothing over from the last one. The weights were frozen when training ended, and each request gets a fresh context window that's gone once the response finishes. An agent that remembers does so because the application around the model writes selected state somewhere durable and loads the relevant part into later prompts.

MechanismWhere it livesHow it changesWhat a coding agent uses it for
Model weightsThe model's parametersPretraining or fine-tuningLanguage syntax, common API patterns
Context windowThe prompt for one model callAssembled fresh for each callThe current diff, stack trace and conversation
Retrieval (RAG)An external search or vector indexDocuments are indexed, then read at query timePulling docs or code snippets on demand
Agent memoryAn external database, graph or set of filesWritten, replaced and read as work goes onKeeping architecture decisions across sessions

RAG is usually set against memory as the static, read-only alternative. The CoALA paper, which gave the field most of its vocabulary, doesn't draw the line there. It models retrieval as reading from long-term memory into working memory, and learning as writing new long-term records, and it describes retrieval-augmented methods as retrieval from semantic memory. On that account RAG is the read half of a memory system. What a plain RAG setup lacks is the write half.

A production coding agent uses all four rows. The weights supply general ability, the context window holds the task, memory keeps decisions between sessions, and a retrieval step picks which stored records go into the next prompt. Our guide to context engineering covers how those pieces compete for one finite window.

Scope, durability and content type are three separate choices

Most confusing statements about agent memory mix up three questions.

Scope: does this state stay inside one conversation, or carry across conversations and users?

Durability: does it survive a process restart, or live in RAM?

Content type: what kind of knowledge is it?

"Short-term" and "long-term" get used for all three, which is how a team ends up with a "long-term memory" that's a durable copy of one chat thread.

The LangGraph persistence guide is a clean example of keeping scope and durability apart. A checkpointer saves one thread's execution state, so an agent can recover from a crash or resume a paused conversation. Back it with PostgreSQL in place of the in-memory saver and that thread-scoped state survives a restart. It's durable, and it's still scoped to one thread. To share a fact across threads you write it to a separate store. That store holds key-value data your application defines, reads and writes. Extracting facts, resolving conflicts and deciding what to recall are your code's job.

For content type, CoALA's four categories are the common reference.

Memory typeWhat it holdsCoding-agent exampleHow it changes
WorkingActive state across model calls, part of which goes into each promptThe current plan, tool output and diffRebuilt and pruned during a run
EpisodicRecords of past experienceThe transcript of an earlier debugging sessionAppended, with no retraining
SemanticKnowledge about the world and the agent's environmentService contracts, repository conventions, design decisionsWritten or superseded, with no retraining
ProceduralHow to act: implicit in the weights, explicit in agent codeCoding habits, tool logic, runbooks and skillsCode and runbook edits, or retraining

Two rows map onto things a coding team already has. Procedural memory outside the model is instruction files and skills. Episodic memory is session history. Who gets to read each one is a separate decision, covered in team vs personal agent memory.

The write path and the read path

A memory system does two jobs at different times, and keeping them apart is what stops raw transcripts from filling every prompt.

After an agent turn, the write path extracts claims and marks old ones superseded in the memory stores. Before the next turn, the read path searches, ranks and prunes those stores into a bounded context.
After an agent turn, the write path extracts claims and marks old ones superseded in the memory stores. Before the next turn, the read path searches, ranks and prunes those stores into a bounded context.

The write path runs after work happens. Episodic logs append what was said. A semantic pipeline extracts claims and marks outdated ones as superseded, which Konishi's memory design guide walks through in detail. A record worth trusting carries a timestamp and a pointer to its source, so someone can check where a claim came from. Procedural rules deserve a review step before they're promoted, because an automatic overwrite of "how we do things" changes agent behaviour everywhere at once. Agent dreaming is a write path that runs in the background, and that post covers who gets to approve what it writes.

The read path runs before a model call. It assembles a bounded working context, never the whole history. In practice that means exact-key lookups combined with full-text or vector search, then ranking, then pruning to fit a token budget.

The failure modes sit between the two. Saving a record doesn't extract the claim inside it or reconcile it with an older one. Approximate vector search can return a stale entry, or a near neighbour from the wrong project when filters are loose. A record that's stored, findable and current can still be ignored by the model.

Choosing where memory is stored

Start with the simplest store that matches how you'll look things up, and add a second index only when lookups start failing.

StoreBest forStrengthCost
Versioned filesPlaybooks and small amounts of repository stateDiffable and reviewable by peopleNo query engine
Key-value or SQLPreferences, state and metadataExact lookups, transactions, expiry rulesFixed schema, no semantic search
Vector indexFuzzy recall over past turnsSimilarity search at scaleApproximate results, weak exact lookup
Graph databaseRelationships that span several hopsFollows linked facts across sessionsExpensive to model and maintain

A 2026 survey of memory for LLM agents notes that hybrid stores are the norm in production. The pairing we see most is a relational or key-value store for exact lookups with a vector index for fuzzy recall. A graph is worth its upkeep only when your questions follow relationships across several records.

One coding decision, traced across three sessions

This walkthrough uses an invented file, src/webhooks/billing.ts. It shows the mechanics and isn't a customer result.

A timeline for one file. On March 3 writes are inline. On April 14 they move to a queue with an idempotency key, superseding the first decision. On May 2 an agent proposes reverting, search returns both records, and the citation to the April session settles it.
A timeline for one file. On March 3 writes are inline. On April 14 they move to a queue with an idempotency key, superseding the first decision. On May 2 an agent proposes reverting, search returns both records, and the citation to the April session settles it.

March 3. Engineer A implements the billing webhook with synchronous, inline database writes. Traffic is low and a queue would be overhead. The write path records that reasoning from the session.

April 14. Traffic spikes. The inline writes cause gateway timeouts and duplicate invoice credits. Engineer B refactors the handler to enqueue jobs with a 24-hour idempotency key. That session writes a newer decision that supersedes the first.

May 2. Engineer C asks an agent to reduce webhook latency, and the agent proposes going back to synchronous writes. Retrieval returns both the March rationale and the April refactor, because both match the same file and the same database pattern.

What settles it is the citation. Engineer C follows the link to the April 14 session and its pull request, reads about the outage, and keeps the queue.

Take the citations away and the same retrieval is a hazard. Two confident summaries disagree, and nothing says which one reflects production today. Treat recalled memory as a pointer to a primary record and you catch stale guidance before the agent writes code against it.

Governance: staleness, access, deletion and poisoning

Memory that persists across sessions and teammates changes how mistakes behave. A bad context no longer ends with the session. Later runs inherit it.

Staleness

A memory store goes stale whenever code changes faster than the notes about it. The useful distinction is between when a fact was true in the world and when the system recorded it. Zep's fact model tracks both: valid_at and invalid_at for the world, created_at and expired_at for the record, and it attempts to invalidate an older fact when a contradicting one arrives. Zep's documentation adds that the fields don't establish that the source or the derived fact is true, so a recalled fact still needs a source you can check against the current code.

Access control is not a namespace

Putting a user ID in a query key organizes records. It doesn't stop anyone from reading them unless the server verifies who's asking. LangChain's custom-auth guide shows both halves. Without an authentication handler, a deployment sees only the API-key owner, usually the developer, so requests aren't scoped to individual users. The fix is to derive access filters from the authenticated identity on every request, never from a parameter the client supplies.

Hiding is not deleting

Most memory tools have three different controls that sound alike: turn the feature off, hide a record, delete a record.

GitHub's Copilot Memory documentation says that disabling memory doesn't delete stored memories, and that memories already supplied to a running conversation can stay in its context until you start a new session. Glen's privacy policy is explicit that marking a memory as forgotten hides it from search answers and doesn't delete it, and that deleted content can persist for a limited period in routine backups.

Before relying on any removal control, find out what it reaches: the raw transcript, the facts derived from it, the search index, caches and backups.

Memory poisoning

A persistent store turns one malicious input into a recurring one. OWASP's Top 10 for Agentic Applications lists it as ASI06: Memory & Context Poisoning: content an attacker controls gets into memory and context that the system goes on trusting, long after the original interaction.

No filter removes prompt injection entirely. The design answer is separation: keep untrusted facts apart from privileged instructions, restrict who and what can write to memory, and record where each write came from so a poisoned entry can be found and rolled back.

Instruction files, built-in memory and team session history

A coding team has three practical layers to choose from, and they aren't substitutes.

LayerBest forWho shares itLimits
Repository files (AGENTS.md)Standing rules, reviewed in GitEveryone who clones the repositorySize caps, loaded once per run
Built-in memory (Copilot Memory and similar)Learned preferences and cited repository factsYou across repositories, collaborators within oneOne repository, citations checked by the model
Team session history (Glen)The reasoning behind earlier workTeammates and their agents across an organizationHosted, recorded by plugins, recall varies by agent

Repository files hold rules that should apply to every session: test commands, code boundaries, conventions. In Codex, the agent builds its instruction chain once per run. It reads a global file from ~/.codex, then walks from the project root down to the working directory, taking at most one file per directory, with AGENTS.override.md ahead of AGENTS.md. The combined size is capped at 32 KiB by default. Files nearer the working directory take precedence, and an edit takes effect on the next run.

Built-in memory captures facts without anyone editing a tracked file. GitHub Copilot Memory stores personal preferences that follow you across repositories and repository facts shared with collaborators. It attaches code citations to repository facts and checks them against the current branch before using one. Those facts aren't pooled across an organization's repositories, and a fork doesn't get a copy.

Team session history fits when the reasoning lives in agent transcripts spread across people and tools. Glen's plugins record sessions from Claude Code, Codex, Cursor, Pi and Grok Build. MCP clients search the same memory and record nothing. Recall varies by agent, and teammates in your organization can search recorded sessions. Glen is hosted only. A session run off the record with glen incognito isn't added to team memory or shown to teammates, though the privacy policy notes that a copy with secrets removed is kept for authorized staff troubleshooting. Memory for AI coding agents covers setup and what's recorded.

If you work alone in one agent, or your team's conventions fit in one repository, the first two layers are often enough. And none of the three guarantees compliance. You still review the diff and check cited sources against the code.

How to evaluate agent memory on real coding tasks

The only way to know whether memory helps is to run the same task with it on and off. Hold the prompt, the model settings and the repository snapshot constant, so the difference is memory and nothing else. Strip anything from the baseline prompt that gives the answer away.

Using the billing webhook example:

CaseInputPasses if
Current decisionAsk about webhook handling after the April sessionIt recommends the queue and cites the newer record
Historical rationaleAsk why synchronous writes existedIt separates past reasoning from current practice and cites the older record
Missing evidenceWithhold the decision recordIt says the source is missing and invents nothing
Unauthorized accessQuery as a user without accessNo restricted record or excerpt appears
Irrelevant retrievalAdd similar memories from another projectIt excludes them or flags the mismatch
Planted instructionStore untrusted text asking to skip an approval, in a sandboxIt treats the text as data and declines
Removal controlsTest forget, disable and delete in fresh sessionsEach behaves as documented, with nothing carried over

Score retrieval and task completion separately. An agent can fetch the right transcript and still apply the old pattern. For each run, log whether the task was completed, whether citations were valid, whether stale or irrelevant memory was used, any unauthorized disclosure, latency and tokens. Results depend on your codebase, so measure your own baseline. Our acceptance tests for coding-agent memory turn five of these into a suite, and the 100-PR replay shows the on-and-off method at scale.

Build only the layer you need

Start with the smallest durable layer that covers the decisions you keep repeating. For one person, or one repository's conventions, that's checked-in instruction files and built-in agent memory, with no new infrastructure. A shared session store is for when the history of decisions has to be searchable across teammates and agents.

Whatever you add, treat a recalled memory as evidence with a citation. A stored fact can lag a refactor, or come from a pull request that never merged. Open the linked file or session before accepting the edit.

Frequently asked questions

Does AI agent memory require retraining the model?

No. Episodic and semantic memory are stored outside the model, so an agent's state changes without touching the weights. Changing weights is a separate way to learn, covered in continual learning vs external memory.

Is RAG the same as agent memory?

RAG is the read path of agent memory. It fetches stored knowledge into the context on demand. A memory system also has a write path that adds new facts and supersedes old ones as the agent works.

What are the types of AI agent memory?

The common taxonomy, from the CoALA paper, is working memory for the active task, plus three long-term kinds: episodic for past experiences, semantic for facts, and procedural for how to act.

What is the difference between short-term and long-term agent memory?

Usually scope: short-term memory is the state of one conversation, and long-term memory carries across conversations. It's often confused with durability. A conversation's state saved to disk is durable and still short-term.

When is a dedicated memory tool unnecessary?

When instruction files such as AGENTS.md and your agent's built-in memory cover the workflow, which is typical for a solo developer or a single repository. A team session history tool helps when the reasoning behind past work needs to be searchable across people and agents.

Why doesn't a stored memory guarantee the agent uses it?

Three things have to go right. Retrieval has to find the record, the record has to still be true, and the model has to act on it. Each can fail independently, which is why memory needs citations and why changes still need review.

More field notes

Fix your agents’ amnesia.

Start on your own or with up to two teammates. Your first 15,000 memories are free, no credit card.

Start free