01 · Project · Personal research project, Nov 2026
Trojan Memories
A reproducible study of what happens when an AI agent with long-term memory saves a malicious note from an untrusted web page or email, how often it acts on that note in a later session, and which defenses stop it.
- Built a simulated LLM-agent testbed from scratch, with a hand-written agent loop, ChromaDB memory and simulated tools, to study sleeper injections: untrusted content saved to memory and misused in a later session. It has 40 attacks and 15 benign tasks, scored by exact-match code with no AI judge, using Wilson 95% confidence intervals.
- With no defense, Gemini 3.5 Flash-Lite carried out the attacker's action in 20 of 80 runs (25.0%, 95% CI 16.8–35.5), and in 55.6% of cases where the bad note was saved. Qwen3-Coder-30B did so in 0 of 80. Web pages were the dangerous channel; emails were not.
- Designed the Memory Provenance Guard, which decides trust from code-tracked memory provenance plus an action-time destination check, instead of from the text. On Qwen, task success was 86.7% against a 93.3% baseline, and I reported where it fails (12 of 80 runs bypassed by the agent's own paraphrase).
- Compared five defenses on two models and showed they don't transfer. A prompt warning cut Gemini's saved attacks from 18 of 40 to 0, but raised Qwen's from 22.5% to 30.0%. An LLM memory audit removed all attacker memories but deleted the user's own memory in 5 of 15 normal tasks (task success 66.7%).
- Attacked my own defense with 8 manual adaptive attacks and an automated attacker, plus 25 payloads tested offline against its code. 19 of 25 got past the layer they targeted, though no planted memory redirected an action in end-to-end runs. Two attacks still beat it: a user message saying "save anything useful" made the attacker's memory count as endorsed, and a spoofed bill sent money to the attacker in 8 of 8 runs because the payee account printed on the bill counted as trusted.
- Python
- ChromaDB
- llama.cpp
- Gemini API



