Home / Articles

AI Agent Memory Is Not a Database: What to Keep, Retrieve and Forget

Why agent memory is a relevance problem: how context, memory, state and RAG differ, what to store, how to scope, age and audit it, and why forgetting is a feature.

Publisher: REACTAPP.TOP11 min read2536 words

This article is published in English.

Sources: AI Agent Memory Is Not a Database

Memory for AI agents is usually pitched as a feature that makes them smarter: remember past chats, user preferences, earlier workflow steps, what worked last time, facts from documents. The dream is an agent that knows everything it has ever seen. That's where the confusion begins, because an agent doesn't need to remember everything, and memory isn't the same as storing data.

A database can hold millions of records without any of them belonging in an agent's memory. The engineering questions are different ones. What should be remembered, and for how long? Where does it live, when is it fetched, when is it dropped? And is it memory at all? Seen this way, memory is less a storage problem than a relevance problem.

Why "keep everything" breaks down

Think of an agent on a long-running task. In the first step it learns the user's goal, the chosen document, a few extracted values, a tool result, an interim decision and a validation outcome. Then comes another step, and another, and the pile grows.

The easiest implementation is to keep it all: append each message, store each tool result, resend everything on the next call. That works for a while. Then context balloons, responses slow down, costs rise, stale information starts steering new decisions and outputs that stopped mattering are still sitting in the prompt. The model is effectively asked which of fifty things matters right now. At that point memory has turned into noise.

Four terms that get mixed up

These concepts solve different problems, and agent designs improve once they're separated.

Context is what the model needs to know at this moment: the current request, selected evidence, a few earlier decisions, relevant tool output. It is temporary and serves the present reasoning step.

Memory is information the system may want again later, such as a user preference, a decision someone confirmed, a useful summary or the outcome of a previous task. It can outlive a single model call.

State says where the workflow stands. It might be a status like QUEUED, RUNNING, WAITING_FOR_TOOL, RETRYING or COMPLETED, or finer flags such as document_extracted = true, analysis_completed = true and report_generated = false. State lets the system continue. It isn't knowledge.

RAG means pulling knowledge from an outside source when it's needed: documents, databases, policies, reports, internal wikis, vector stores. That information already lives elsewhere. The agent doesn't have to remember it permanently, only find it when required, which is a different problem.

Short-term memory

Short-term memory is the working set. People solving a problem hold certain facts in their heads and discard most of them once finished, and agents have the same need. During one workflow an agent might use the current request, the selected document, recent tool outputs, intermediate calculations, earlier decisions and task progress. All of that matters now and may be nearly worthless tomorrow. A good definition is the smallest set of information needed to continue the current task, and not everything that has happened since it started.

Long-term memory has to earn its place

Long-term memory is what you deliberately keep because it might help again. Examples include a stated preference such as "prefer concise reports", a confirmed business choice such as "use this reporting format for future analysis", or a confirmed fact such as "this project treats System A as the source of truth".

The bar should be higher here. Before storing anything, ask whether it's likely to improve a future decision. If not, leave it out, because long-term memory has a cost beyond storage: every item is something the system may later retrieve, trust, maintain and get wrong.

RAG isn't long-term memory

Say there are 20,000 internal documents in a vector index and the agent can search them. That isn't agent memory. The documents are knowledge, and RAG is the way to retrieve it. The agent shouldn't carry every document in its head, only know how to find the right one. The healthy flow is: the agent needs information, searches the knowledge source, retrieves relevant evidence and uses it. The unhealthy one copies all knowledge into memory. Knowledge can be enormous, while working memory must stay small.

State often matters more than memory

Much of what gets called agent memory is really workflow state. Suppose an agent has finished extracting a document, retrieving evidence and analyzing it, with the report still to generate. If the worker crashes before the report is done, the system must know where to resume. That's state. The model shouldn't need to recall that the analysis step finished, since the application knows.

Task status, retry counts, checkpoints, job IDs, completed steps and pending actions generally belong in deterministic application state, not inside an LLM conversation. A good rule: if software can know something exactly, let software store it exactly. The model shouldn't be responsible for remembering workflow truth.

Not everything that happened deserves a place

Imagine a tool returns a 500-line JSON payload. Does the next step need all 500 lines? Probably it needs only a field or two, like account_status = ACTIVE, total_balance = 120000 or document_found = true. The raw output can stay in logs or storage, and memory can hold just the parts that matter.

Conversations work the same way. If a user and an agent spent ten messages pinning down a requirement, a compact note such as "user wants the report grouped by category and sorted by severity" does more good than replaying the whole exchange each time.

What deserves remembering

No single answer fits every system, but a few categories are usually good candidates:

  • Stable preferences: output format, language, reporting style.
  • Explicitly confirmed decisions: a selected configuration, an approved workflow option, a chosen source of truth.
  • Useful historical outcomes: a strategy that worked, confirmed classifications, validated mappings. Even these should be checked for relevance.
  • Compact task summaries: for long work, a line like "Document A was analyzed, revenue confirmed as X, two inconsistencies unresolved" is better working memory than thirty earlier model replies.

What to be wary of storing

  • Every model response. Most intermediate reasoning isn't useful later.
  • Every tool output, which can be large, stale or specific to one moment.
  • Temporary errors. Yesterday's timeout shouldn't become tomorrow's context.
  • Unverified model assumptions, the riskiest of the lot. If a model says a document "appears to refer to Company A" and nobody validates that, storing it can turn one weak guess into a permanent fact that later runs build on.
  • Sensitive data with no clear reason to keep it. Memory should have a purpose.

Memory can be wrong

This is among the biggest problems with long-term memory. An agent stores that a customer's reporting currency is USD, and six months later the preference changes while the old entry survives. Which one wins? Memory needs a notion of freshness. Some facts stay valid for years and others for minutes, and a good system tells them apart.

A lifecycle, not store-and-forget

Memory shouldn't follow a path of store and keep forever. A more realistic cycle runs through capture, validation, storage, retrieval, use, and then update, expiry or deletion. To support that, each entry may need a creation time, an origin, a confirmed or unconfirmed flag, a last-used time, an expiry rule and a link to any newer value that superseded it. Writing is only half the job. Maintenance is the other half.

Source matters

Suppose two memories exist. One says the preferred format is PDF, and the user confirmed it explicitly yesterday. The other says the preferred format may be Excel, which an LLM inferred six months ago. They shouldn't carry equal weight, which is why memory ideally records provenance: was it provided by the user, generated by the system, inferred by a model, retrieved from a document, returned by a tool or copied from elsewhere? That context tells the system how far to trust it.

Confidence matters too

"The contract appears to expire in June" is a different kind of statement than "Contract expiration date: 30 June 2027", read from a structured field. One can be treated as high confidence and the other as needing verification, so fuzzy conclusions don't quietly harden into facts. A useful long-term record often carries more than a value. It may also hold source, confidence, timestamp, scope and status, which makes later retrieval much safer.

Summaries are interpretations

Summaries are among the best ways to keep working memory small. Store "user wants a concise technical explanation with examples" rather than a whole conversation, or "three findings confirmed, one unresolved" rather than every analysis step. The catch is that a summary is an interpretation and can drop an important detail. For important workflows, pair the summary with a pointer to the original evidence. The summary keeps the agent efficient, and the original is available if something must be verified.

Don't create a second source of truth

If customer details already live in the main customer database, copying them into agent long-term memory is usually a mistake. Soon the two copies disagree, and nobody knows which is right. Better to treat the authoritative system as the place to retrieve from when needed and feed the result into the agent's context. Don't duplicate a system of record without a very clear reason. The test is whether the information can be retrieved reliably from its source instead of remembered. If so, retrieval may beat memory.

Scope

When several users, organizations or workflows share one agent infrastructure, memory needs boundaries. One user's memory mustn't show up in another's context, one organization shouldn't pull another's data, and one workflow may not need another's intermediate results. Memory generally needs an explicit scope, such as global, organization, user, conversation, workflow or task. The narrower the scope, the smaller the chance that irrelevant information leaks into an unrelated decision.

Retrieving memory is a search problem

With 500 stored memories, nobody should put all of them in every prompt. We're back to the context problem, so memory retrieval needs its own pipeline: look at the current task, determine which kind of memory is relevant, filter by user, workflow and organization, search, rank, select and add the winners to working context. This is why memory and context engineering are so tied together. Memory determines what could be available later, and context engineering determines what is used now.

Write less, retrieve better

Rather than asking what else can be stored, ask which information has enough future value to justify storing. Rather than asking how much memory fits in the prompt, ask which memory is relevant to this decision. A good memory architecture should usually leave the agent seeing less, since irrelevant memory is just irrelevant context.

Observability

Suppose an agent gives a strange answer. The retrieved document looks right and the tool call succeeded, yet the answer is off, and eventually someone finds that an old memory influenced the decision. Without visibility into memory retrieval, that is very hard to debug. For each run it helps to log which memories were pulled and the reason, their origin and age, confirmed status, whether they made it into the final context, and whether they changed the output. That turns memory from hidden behavior into something inspectable.

A more realistic architecture

Instead of everything flowing into memory and then to the agent, picture this: a user or task arrives, the workflow state is consulted, and the system decides what information is needed. Then it draws from distinct places:

  • Working context for what's needed right now, like the current request, the latest tool result and the current decision.
  • Short-term memory for what's needed across this workflow, like a task summary, interim findings and recent decisions.
  • Long-term memory for what may help future workflows, like a stable preference, a confirmed fact or a historical outcome.
  • Knowledge and RAG for information that exists elsewhere, such as documents, policies, reports and databases.
  • Application state for deterministic truth like status, checkpoints, retry counts and completed steps.

After that, filter, rank, assemble the current context and let the agent reason. Calling all of this simply memory hides the structure.

Questions to ask before adding a memory feature

  • Will this help a future task? If not, don't store it.
  • Can it be retrieved from an authoritative system? If so, RAG or an ordinary query may be better.
  • Is it workflow state? Keep that outside the LLM.
  • Has it been verified? Don't promote model guesses to permanent facts.
  • How long is it valid? Some memories need expiry.
  • What happens when it changes? Define update and replacement rules.
  • Who may retrieve it? Memory needs scope and permissions.
  • Can you explain why it appeared in the agent's context? If not, debugging gets hard.
  • Does the model need the raw data or only a summary? Keep the working set small.

Answers to these usually matter more than the choice of memory database.

Forgetting is a feature

Good memory doesn't mean remembering everything. A useful agent should forget plenty: temporary details, old tool results, unverified assumptions, outdated facts and reasoning that no longer matters. More memory doesn't automatically make a system smarter, and sometimes it only hands the model more chances to connect the wrong things. In practice that means: store only what will pay off later, hold workflow state in plain deterministic code, fetch knowledge from where it lives, let just the pertinent memories enter the prompt, note each one's origin, and refresh or retire entries as facts shift.

Databases exist to hold data. An agent's memory has another purpose: putting the right facts in front of the model when they're needed, while keeping old clutter from hardening into later certainty.