Memory poisoning

Also known as: agent memory poisoning

On this page 7

Memory poisoning is an attack in which an adversary writes malicious content into the persistent memory of an AI agent or assistant, so that the stored entries later steer its answers, decisions or tool use. In AI security, it is treated as a distinct threat because the injected content survives beyond the session in which it entered, turning a single successful manipulation into a lasting compromise.

Modern assistants and agents keep long-term memory in forms such as saved user facts, conversation summaries, vector stores of past interactions and learned task notes. Memory poisoning, also called agent memory poisoning, abuses the fact that this memory is usually trusted at recall time, even though some of it was written from untrusted inputs such as web pages, emails or documents.

How memory poisoning works

A memory poisoning attack follows a write phase and a trigger phase. In the write phase, the attacker gets content into the memory store, most often through indirect prompt injection hidden in material the agent reads. In the trigger phase, a later query retrieves the poisoned entry and the model treats it as reliable context.

The gap between the two phases is what makes the attack effective. The malicious input may arrive days before any harm occurs, so the link between cause and effect is hidden from the user and from simple logging. The table below breaks the attack into stages.

StageWhat happensTypical attacker technique
DeliveryUntrusted content reaches the agentHidden text in a web page, file or email
Memory writeAgent stores the content as a fact or noteInstruction such as remember this for later
PersistenceEntry stays in the store across sessionsPhrasing that looks like a user preference
RetrievalLater query recalls the entryTrigger keywords tuned for similarity search
EffectModel acts on the poisoned contextFalse answers, data leaks or unsafe tool calls
Stages of a memory poisoning attack

Types of memory that can be poisoned

The attack surface depends on which memory mechanism an agent uses, because each has its own write path and its own retrieval logic. Explicit memory is written deliberately by a tool call, while implicit memory is derived automatically from conversation history.

Memory typeHow it is writtenPoisoning risk
Saved user factsModel calls a memory toolHigh when injected text can trigger the tool
Conversation summariesAutomatic summarization of sessionsMedium, injected text may enter the summary
Episodic vector storeEmbeddings of past interactionsHigh, retrieval favors crafted trigger text
Procedural notesAgent records lessons for future tasksHigh, poisoned lessons change behavior
Shared team memorySeveral users or agents write to one storeVery high, one user can affect others
Agent memory types and their exposure

Research systems have shown that an attacker does not always need direct access to the store. Some attacks inject records only through ordinary queries, relying on the agent to save its own reasoning, and optimized triggers can reach high retrieval rates while leaving normal behavior almost unchanged.

Memory poisoning sits between prompt injection and data poisoning. It uses injection to get content in, but its impact resembles poisoning because the corrupted data persists and influences many later outputs. Unlike training data poisoning, it changes no model weights.

ThreatTargetPersistenceWho can fix it
Memory poisoningAgent memory storeUntil the entry is deletedOperator or user editing memory
Direct prompt injectionCurrent conversationOne sessionEnds with the session
RAG poisoningShared document corpusUntil the document is removedCorpus owner
Training data poisoningModel weightsUntil retrainingModel developer
Model poisoningWeights or updates directlyUntil replacementModel developer
Memory poisoning and neighboring threats

The practical consequence is that session-level defenses are insufficient. A guardrail that blocks a malicious instruction in the current turn does nothing about an entry stored last week, so defenses must cover both the write path and the recall path.

Defenses against memory poisoning

Effective protection treats memory as untrusted input with provenance, not as part of the trusted system prompt. No single control is sufficient, so mature designs layer several measures across writing, storage and retrieval.

ControlWhere it appliesWhat it prevents
Write gatingMemory writeBlocks memory updates triggered by external content
User confirmationMemory writeMakes users approve new long-term entries
Provenance taggingStorageRecords whether an entry came from user or tool output
Isolation per userStorageStops one tenant from poisoning another
Expiry and reviewStorageRemoves stale or unverified entries
Retrieval-time markingRecallLabels recalled entries as data, not instructions
Anomaly detectionRecall and logsFlags entries with instruction-like text
Controls against memory poisoning

Architectural patterns from prompt injection defense also help. The dual LLM pattern and capability-based designs such as CaMeL keep a privileged model away from untrusted text, and instruction hierarchy training teaches models to give stored data less authority than system and user instructions.

Common mistakes in agent memory design

Many incidents stem from design shortcuts that treat memory as harmless, because memory features are often built for convenience first and secured later.

  • Allowing tool outputs to trigger memory writes without any user signal.
  • Injecting recalled memory into the system prompt with full authority.
  • Offering users no view or deletion interface for stored entries.
  • Sharing one memory store across tenants or agents without access control.
  • Logging memory writes without the source content, which blocks forensic review.

In plain words

Some AI assistants keep a notebook about you. They write down your preferences and past tasks. Memory poisoning means someone sneaks a false note into that notebook.

The trick often hides in a web page or email the assistant reads for you. Later, the assistant reads its notebook and trusts the fake note. It may give wrong advice or send data to the wrong place. Good systems ask before saving notes and let you see and delete them.

A real-world example

A sales team uses an AI agent that reads incoming email, drafts replies and keeps long-term notes about each client. An attacker sends a message with white text on a white background stating that all invoices for one client must now go to a new bank account, and asking the agent to remember this as a permanent client preference.

The agent stores the note. Three weeks later, a staff member asks it to prepare a payment reminder for that client, and the draft includes the attacker’s account details. A finance employee notices that the account differs from the contract and stops the transfer before money leaves the company.

The security review traces the draft to a single memory entry created by email content. The team then disables memory writes from external messages, adds provenance labels, and requires a person to approve any stored change to payment details.