Answer

How does memory work in an AI agent, and how is it different from RAG?

Agent memory is durable state that an agent writes about its own work and reads back later. Retrieval-augmented generation searches a corpus that already exists and was not written by the agent. Vendors implement memory in two shapes: files the model edits through a tool, and namespaced stores the framework reads and writes for you. The two are complementary, not competing, and the failure modes are different enough that choosing wrong is expensive.

Published · Updated · Evidence-linked, not search-volume ranked.

Short answer

Memory in an AI agent is durable state that the agent itself writes and reads back across turns or sessions, so it does not have to keep everything inside the context window. Retrieval-augmented generation searches a body of documents that already existed and that the agent did not author, then pastes the matching passages into the prompt. The practical difference is authorship and lifetime: memory records what happened and what was learned during the work, while retrieval fetches reference material that was true before the work started. Most production systems need both, and the common mistake is trying to make a vector search over documents do the job of a progress log.

Why this question is current

Exact query-volume data was unavailable, so RepoRadar uses these as current demand and intent signals rather than a claimed volume ranking.

  • ai agent memory · Google Suggest · US · checked 2026-09-01T07:22:00Z
    Ten live completions including ai agent memory system, ai agent memory architecture, ai agent memory management, ai agent memory types, ai agent memory tools, ai agent memory open source, and ai agent memory layer. A query-shape signal that people are looking for the mechanism and the tooling, not a definition. Intent signal, not volume.
  • agent memory · Google Suggest · US · checked 2026-09-01T07:22:00Z
    Completions include agent memory systems, agent memory benchmark, agent memory framework, agent memory management, agent memory mcp, agent memory architecture, and agent memory paper. Confirms the same cluster from a shorter seed. Intent signal, not volume.
  • stories created in the trailing 24 hours with more than 60 points · Hacker News Algolia search_by_date · global English-language developer community · checked 2026-09-01T07:21:00Z
    Story titled Agent memory as a file format, objectID 49508317, 172 points and 89 comments, linking to calpaterson.com/memoryfields.html. Corroborates current practitioner attention on how agent memory should be stored. Community attention signal, not a factual source.
  • geo=US daily trends feed · Google Trends Trending Now RSS · US · checked 2026-09-01T07:21:00Z
    Returned only general-interest breakout terms and no AI-technology entries. Recorded here as a negative result so no ranking or volume claim is implied anywhere in this article.

Who this helps

  • developers building multi-session coding or research agents
  • teams deciding between a memory layer and a retrieval pipeline
  • builders whose agent forgets context between runs
  • anyone evaluating a hosted memory product against a self-managed store

The shortest distinction

Memory is what the agent writes down about its own work. Retrieval is what the agent looks up in material somebody else wrote. That single difference in authorship drives almost every other difference between them.

A memory record says the user prefers metric units, or the migration on the orders table failed twice for the same reason. A retrieved passage says what the refund policy is, or what a function signature looks like. The first only exists because the agent ran; the second was true before the agent existed.

Short-term and long-term memory are different systems

LangGraph's documentation splits agent memory by recall scope. Short-term memory is thread-scoped: it tracks the ongoing conversation as part of the agent's state, and that state is persisted to a database through a checkpointer so a thread can be resumed. Long-term memory is stored under custom namespaces, shared across threads, and recallable at any time in any thread.

This split matters because the two have different pressures. Short-term memory fights the context window: the docs note that even models supporting long contexts still perform poorly over them, getting distracted by stale content while costs and latency rise. Long-term memory fights correctness and staleness instead, because a wrong fact written once will be recalled forever.

The same docs borrow a three-way classification from psychology and map it onto agents: semantic memory stores facts about a user, episodic memory stores past agent actions, and procedural memory stores instructions such as the agent's system prompt. It is worth reading that table carefully, because the documentation itself flags a trap: semantic memory is a term about storing facts and is not the same thing as semantic search.

The two shapes vendors actually ship

The first shape is memory as files the model edits. Anthropic's memory tool gives Claude commands to view, create, and edit files under a /memories path, and the model checks that directory before starting a task. The important detail is that the tool is client-side: the model only requests operations, and your application executes each one against storage you control and returns the result. The /memories path is a prefix your handler maps onto real storage, such as a per-user directory or database keys. It is available on Claude 4 and later models.

The second shape is memory as a store the framework manages. LangGraph persists long-term memories as JSON documents under a namespace and key, with cross-namespace search through content filters and optional embedding-based search. Here the framework, not the model, owns the read and write path, and you decide when to write.

There is a third option that is really a packaging decision rather than an architecture: hosted memory-as-a-service. Mem0, for example, markets a drop-in memory layer with an add, learn, retrieve loop, and states it is benchmarked on LoCoMo, LongMemEval, and BEAM. Those are the vendor's own claims and we have not verified them. The tradeoff is the usual one — less code to write, one more third party holding conversation-derived data about your users.

When to write, and why it is the hard part

LangGraph's docs frame the write timing as a real design choice. Memories can be updated on the hot path, meaning the agent decides to record something before it replies, or in a background task that generates memories asynchronously. Hot-path writes are immediately available but add latency and let a bad turn poison the store. Background writes keep the interaction fast but mean the next turn may not see what just happened.

The update pattern matters as much as the timing. A profile is a single continuously updated JSON document, which is simple to reason about but becomes error-prone as it grows, so the docs suggest splitting it or using strict decoding to keep the schema valid. A collection appends discrete records instead, which scales better but pushes the difficulty into retrieval and de-duplication.

Anthropic's docs describe a concrete pattern for multi-session software work that sidesteps a lot of this: an initializer session sets up the memory files deliberately before real work begins — a progress log, a feature checklist, a reference to any startup script — and every later session opens by reading them and closes by updating the log. The stated principle is to work on one feature at a time and mark it complete only after end-to-end verification, not when the code is written. That is a discipline for keeping the log honest, and it is the part most teams skip.

Where retrieval is the right answer instead

Retrieval is a ranking problem over a corpus. OpenAI's retrieval guide describes semantic search over vector stores, where a query returns matching chunks with similarity scores and the file each chunk came from. Their example is a good illustration of what this buys you: for the query when did we go to the moon, the highest-scoring passage is the first lunar landing occurred in July of 1969, which shares no words with the query at all.

That behaviour is exactly what you want for documentation, policies, product catalogues, and codebases — bodies of text that exist independently of any conversation. It is exactly what you do not want for tracking whether step three of a task succeeded.

The decision rule that holds up: if the information would still be true and useful if this agent had never run, it belongs in retrieval. If it only exists because the agent ran, it belongs in memory. Facts about a user sit awkwardly in between, which is why the semantic-memory category exists at all.

Risks that come with the memory, not with the model

Path traversal is a real, documented hazard. Because Anthropic's memory tool is client-side, your handler is the security boundary. The docs are explicit that handlers must restrict all operations to /memories, reject sequences such as ../ and ..\\, watch for URL-encoded traversal like %2e%2e%2f, and use built-in path utilities rather than string checks. If you write the handler yourself, this is not optional hardening — it is the whole control.

Memory also widens the blast radius of prompt injection. Anything the agent reads can influence what it writes to memory, and anything written to memory is read back automatically at the start of later sessions. A single poisoned turn can become a persistent instruction. Treat the memory store as untrusted input on read, not as trusted configuration.

There is a data-handling dimension too. Memory files accumulate whatever the agent found worth recording, which in practice includes user details nobody consciously decided to retain. Because the storage is yours in the client-side model, so are the retention, deletion, and access-control obligations.

Limits of this answer

Everything factual above comes from current vendor and framework documentation checked on 2026-09-01. We have not run benchmarks, and we do not repeat any vendor's performance numbers as fact. The memory benchmarks named on Mem0's page are that vendor's own framing.

The field is moving. Anthropic's memory tool is versioned in the tool type string itself, and both Anthropic and LangChain are actively revising their context and memory guidance. Check the linked documentation before committing to an API shape.

A useful next action

Take one agent that currently forgets things between runs and write down, in one sentence each, what it should remember and why. If every item on that list would still be true had the agent never run, you do not need memory — you need better retrieval, and adding a memory layer will only give you a second place for stale facts to hide.

If items remain, start with the cheapest thing that works: a single append-only progress file the agent reads at the start of a session and updates at the end, following the initializer pattern in Anthropic's docs. Run it for a week before reaching for a namespaced store or a hosted memory service. You will learn what actually needs to persist, which is the input every larger design depends on.

Sources checked

  • Anthropic Claude Platform Docs: Memory tool ↗ checked · vendor documentation, global

    Primary source. States that the memory tool lets the model create, read, update, and delete files that persist between sessions, that it operates client-side so the application executes each requested file operation against storage the developer controls, that the /memories path is a prefix the handler maps onto real storage, that handlers must reject paths outside /memories to prevent traversal, that the tool is available on Claude 4 and later models, and that it pairs with context editing and server-side compaction. Also documents the multisession software development pattern in which an initializer session creates a progress log and feature checklist that later sessions read and update.

  • LangGraph documentation: Memory overview ↗ checked · framework documentation, global

    Primary source. Defines short-term memory as thread-scoped state persisted through a checkpointer and long-term memory as namespaced records shared across threads and recallable at any time. Provides the semantic, episodic, and procedural memory table mapping facts, experiences, and instructions to agent equivalents. Documents the profile versus collection update patterns, the hot-path versus background write tradeoff, and the JSON-document store with namespace and key. Explicitly warns that semantic memory is a psychology term for storing facts and is not the same thing as semantic search.

  • OpenAI API documentation: Retrieval ↗ checked · vendor documentation, global

    Primary source for the retrieval side of the comparison. Describes semantic search over vector stores, shows that a search call returns matching chunks with similarity scores and the file of origin, and gives a worked example in which the highest-scoring result for when did we go to the moon contains none of the query words. Establishes that retrieval is a ranking operation over an existing corpus.

  • Mem0 product page ↗ checked · vendor marketing page, global

    Vendor claim, not an independent measurement. Describes a hosted drop-in memory layer with an add, learn, retrieve loop and states the approach is benchmarked across LoCoMo, LongMemEval, and BEAM. Cited only as evidence that a hosted memory-as-a-service category exists; the performance claims are the vendor's own and are not verified here.

RepoRadar separates factual source claims from analysis. Recheck vendor docs before purchase, deployment, or policy decisions.