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.
| Stage | What happens | Typical attacker technique |
|---|---|---|
| Delivery | Untrusted content reaches the agent | Hidden text in a web page, file or email |
| Memory write | Agent stores the content as a fact or note | Instruction such as remember this for later |
| Persistence | Entry stays in the store across sessions | Phrasing that looks like a user preference |
| Retrieval | Later query recalls the entry | Trigger keywords tuned for similarity search |
| Effect | Model acts on the poisoned context | False answers, data leaks or unsafe tool calls |
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 type | How it is written | Poisoning risk |
|---|---|---|
| Saved user facts | Model calls a memory tool | High when injected text can trigger the tool |
| Conversation summaries | Automatic summarization of sessions | Medium, injected text may enter the summary |
| Episodic vector store | Embeddings of past interactions | High, retrieval favors crafted trigger text |
| Procedural notes | Agent records lessons for future tasks | High, poisoned lessons change behavior |
| Shared team memory | Several users or agents write to one store | Very high, one user can affect others |
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.
How memory poisoning differs from related attacks
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.
| Threat | Target | Persistence | Who can fix it |
|---|---|---|---|
| Memory poisoning | Agent memory store | Until the entry is deleted | Operator or user editing memory |
| Direct prompt injection | Current conversation | One session | Ends with the session |
| RAG poisoning | Shared document corpus | Until the document is removed | Corpus owner |
| Training data poisoning | Model weights | Until retraining | Model developer |
| Model poisoning | Weights or updates directly | Until replacement | Model developer |
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.
| Control | Where it applies | What it prevents |
|---|---|---|
| Write gating | Memory write | Blocks memory updates triggered by external content |
| User confirmation | Memory write | Makes users approve new long-term entries |
| Provenance tagging | Storage | Records whether an entry came from user or tool output |
| Isolation per user | Storage | Stops one tenant from poisoning another |
| Expiry and review | Storage | Removes stale or unverified entries |
| Retrieval-time marking | Recall | Labels recalled entries as data, not instructions |
| Anomaly detection | Recall and logs | Flags entries with instruction-like text |
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.