
Local test range for agent memory poisoning - watch a planted memory steer an agent, then prove the repair. Synthetic targets, scripted deterministic agent.
Your agent remembered it. Should it have?
A local test range for agent memory poisoning: persistent memory as an attack surface. Feed an agent's memory controlled untrusted writes, watch a planted memory change what the agent does, then try to stop it - and prove the repair worked.
Scope, plainly. Synthetic targets, a scripted deterministic agent. This repo demonstrates the mechanics of memory poisoning, defense and repair from published research, on real memory backends. It is not evidence about the safety of any real LLM, hosted memory service, or production system. Never point anything in here at a system you do not own.
Agent memory layers are shipping fast, and the attack classes against them are documented in research (see Sources). This repo is a small, local place to watch those attacks happen and test a fix. The first four scenarios are built from the published taxonomy; A5 extends the range to the ranking window itself, and A6 to a second decision the owner never wrote a policy for:
| Scenario | Attack class | Mechanic under test |
|---|---|---|
| A1 - Direct injection | Instruction-shaped content in one untrusted tool write | Naive recency lets the newest "preference" win over owner policy |
| A2 - Summary laundering | Payload survives compaction | Extractive summarization relabels the write summary; the label looks trustworthy, the true origin is still the untrusted source |
| A3 - Repetition | The same claim, three times | Duplicate merging boosts the claim's confidence above the owner's own policy |
| A4 - Laundered import | Poison arrives pre-labeled summary from another system | Screening scoped to tool writes never sees it, and the true pre-import origin is unrecoverable; default-deny on non-owner claims is what stops it |
| A5 - Retrieval flooding | Ten untrusted writes with high query-token overlap | The owner policy is pushed out of the agent's top-k recall window, so even a weak per-write claim wins by eviction; screening quarantines the flood, and the origin policy is the backstop |
| A6 - Preference grafting | One untrusted write grafts a preference onto a subject the owner never set (the courier) | Nothing instruction-shaped to screen, and no owner claim to contradict - so origin default-deny blocks it, but conflict-scoped repair alone cannot remove it. Once the owner states a policy, the same repair pass removes the graft |
Each scenario runs three ways against fresh, real backends - no mocks:
repair(), and the decision must return to baseline. A6 is the deliberate exception: with no owner claim on the grafted subject, conflict-scoped repair has nothing to anchor to and removes nothing - the scenario pins that limit and the remediation (owner states a policy, repair removes the graft).Current scoreboard, verified by the test suite: 6/6 attacks flip the undefended agent, 6/6 are blocked with defenses on, 5/6 are restored by repair alone - A6 documents the repair limit and is restored once the owner states a courier policy.
The attacks and defenses are properties of the memory contract, not of one implementation, so the whole range runs against three backends:
ReferenceMemory - dependency-free in-memory store. Good for reading the mechanics.ChromaMemory (mpolab/adapters.py) - an adapter over ChromaDB, a real local vector store with its default ONNX embedding model. No server, no API key, no paid calls: pip install chromadb and the same six attacks replay against embeddings and nearest-neighbor recall. One disclosure: the first ChromaDB run downloads its default ONNX embedding model (about 80 MB) from the internet; after that one-time download it runs fully offline.SQLiteVecMemory (mpolab/adapters.py) - an adapter over sqlite-vec, nearest-neighbour vector recall inside SQLite (exact KNN, no index): no server, no model download at all. It embeds with a deterministic hashed bag-of-words (standard library only), so it exercises real vector-recall plumbing offline; it is not a measure of semantic embedding quality. pip install sqlite-vec.tests/test_adapters.py runs a conformance contract plus every registered scenario against every installed backend. Adding your own adapter (mem0, Zep, Letta, pgvector - anything with retain/recall) inherits the entire attack suite.
Every memory entry carries two provenance fields: trust (the storage label the backend reports, which compaction and imports can rewrite) and origin (the source recorded at write time and never rewritten). The defenses reason about origin. That split is where summary laundering lives and dies. One honesty note: an imported entry's origin is only as honest as the system that imported it - pre-import provenance is unrecoverable. That is exactly why the defended policy lets only owner-origin claims set policy (A4), rather than trusting any claimed origin.
python3 scripts/build_demo.py # regenerates demo/index.html from real runs
open demo/index.html # no server, no dependencies
Play the memory writes, click the card you think is the poison, then reveal: the flipped decision, the defense run, and the repair pass. Deep-linkable states (#reveal=A2, #defense=A4) make any outcome shareable as a URL.
After the reveal, the decision evidence panel shows the actual recall window and every stored write. Switch between no defenses, defenses on, and repair alone. A6 also shows the owner-anchored repair. Expand a write to inspect its stored label, recorded origin, source, confidence and the reason the policy selected or rejected it.
The JSON download contains the complete deterministic scenario replay, including every phase, and works offline. It contains the answers, just like the self-contained page source. Ranks are recall order, not relevance scores; a write outside recall may be irrelevant or displaced.
The same evidence is available in Python:
trace = agent.explain("vendor")
print(trace["decision"]) # unchanged decide() result
for entry in trace["entries"]:
print(entry["id"], entry["recall_rank"], entry["reason"])
explain() does not change memory or the decision policy. It snapshots a synchronous decision; coordinate concurrent writers externally. This is evidence about this scripted policy, not an LLM explanation or a new safety score.
Python 3.10+. The reference suite has zero dependencies:
python3 -m unittest discover -s tests -v
To include the ChromaDB backend:
Verified on a clean checkout:
python3 -m venv .venv && source .venv/bin/activate
pip install '.[chroma]' # local checkout extra; pulls chromadb
pip install '.[sqlitevec]' # or the sqlite-vec backend; no model download
python3 -m unittest discover -s tests -v