TL;DR
To become better over time, autonomous LLM agents compress their past execution histories into reusable "experiences"—rules of thumb for future tasks. However, if an agent encounters bad data or an adversarial prompt injection, that poison gets distilled into its permanent memory, silently sabotaging future tasks. ExpGuard acts as an immune system at the exact moment an agent recalls a memory: it traces the memory's origin, predicts whether using it on the current task is dangerous, and rewrites risky advice on the fly before the agent acts on it.
What Problem Does This Paper Address?
Imagine learning a bad habit—say, someone tells you "cleaning up a workspace means deleting everything in it." If you write that down as a general rule, the next time your boss asks you to clear out just the /tmp folder, you might wipe out the entire project directory.
Long-horizon LLM agents do something very similar. Using standard memory frameworks (like ReasoningBank), agents distill past action-observation trajectories into structured lessons (title, description, content) to avoid starting from scratch on every task. Because agents routinely interact with untrusted files and web pages, adversarial instructions or simple misunderstandings can corrupt these lessons.
Existing guardrails usually inspect raw prompts or final tool calls. Catching corrupted experiences is trickier for three reasons:
- Context matters: Advice that is helpful in one task might violate constraints in another.
- Hidden provenance: You can't always tell a lesson is poisoned just by reading its text; you need to know where it came from and what files or actions spawned it.
- Intertwined utility: Simply deleting a suspicious memory throws the baby out with the bathwater if it also contains genuinely useful workflow steps.
Methods
ExpGuard steps in at the retrieval boundary—after an agent searches its memory library for relevant experiences, but before those experiences enter the agent's active prompt context. It combines three novel mechanisms alongside standard experience extraction and frozen text encoders:
- Task-Conditioned Experience Graph & HGTNN: Instead of judging an experience's text in isolation, ExpGuard builds a snapshot graph connecting five node types (Experience, Task, Action, Observation, Artifact) via seven relationship types (like
derived_fromorwrites). Using only evidence available before reuse, a Heterogeneous Graph Transformer Network (HGTNN) passes messages across this graph to output two probabilities: Attack Risk (will this trigger an unauthorized side effect?) and Task Failure Risk (will this tank the legitimate task?). - Matched Counterfactual Replay (Offline Training): How do you train that graph predictor? You need ground-truth labels isolating the exact causal impact of an experience. Offline, the authors take an original experience and use an LLM to create a "minimally neutralized" twin—stripping out behavioral directives while keeping the topic intact. They restore the exact same task and environment checkpoint, run the agent with both versions, and compare the outcomes. Separate observability masks ensure indeterminate runs don't become false negatives.
- Online LLM Repair & Re-assessment: During live execution, if the higher of the two predicted risks crosses a threshold ($\gamma$), an LLM repair operator rewrites the experience—using its provenance and current task constraints to strip out unsupported claims while keeping useful advice. Crucially, ExpGuard doesn't blindly trust the rewrite: it rebuilds the graph for the new version and re-runs the HGTNN predictor. Only experiences whose risk drops below $\gamma$ are admitted.
Datasets
The authors evaluate ExpGuard across six existing benchmarks (adapting multi-step attacks like MemoryGraft and Sleeper Memory Poisoning for online tests):
- Risk Identification (Offline Ranking): MemForm, CIK-Bench, and SMP-Bench (the dataset from Sleeper Memory Poisoning).
- Online Defense (Live Agent Execution): STATE-Bench, AppWorld, and MemoryArena.
Key Insights and Ideas
- Text isn't enough; provenance is king: When the authors shuffled the historical edges in the graph while keeping all node texts identical, risk detection (AUPRC) dropped by up to 0.052. Knowing how an experience was formed—which actions read or wrote which files—is vital for spotting sleeper attacks.
- Security and utility are distinct failure modes: Training two separate prediction heads (Attack Risk vs. Task Failure Risk) beats training either alone. Notably, dropping the Task Failure head hurt overall detection more than dropping the Attack head, showing that corrupted memories often quietly degrade competence without triggering obvious security alarms.
- Selective gating beats heavy LLM auditing: Rather than asking a massive LLM to audit every retrieved memory on every turn, using a fast graph network to trigger LLM repair only when needed is both more accurate and much cheaper.
Key Results
- Superior Risk Detection: Across 9 combinations of benchmarks and agent backbones (Gemma-4-12B-IT, DeepSeek-V4-Flash, GPT-6 Luna), ExpGuard achieves 0.628–0.721 AUPRC, beating prompt-injection classifiers, text-only MLPs, and few-shot LLM judges by 0.091–0.175. At a strict 10% false-positive budget, it catches 69.2%–75.8% of risky experiences.
- Stronger Online Defense & Task Completion: Across all 9 attack-benchmark pairings, ExpGuard achieves the lowest Attack Success Rate (ASR) and highest Task Success Rate (TSR). Relative to no defense, ASR drops by 26.2–59.1 percentage points while TSR jumps by 21.8–46.0 points (e.g., under adapted MemoryGraft on MemoryArena, ASR drops from 67.9% to 8.8%, while TSR rises from 21.8% to 67.8%).
- Lower Overhead: ExpGuard adds an average online latency of 9.69s and 1,598 tokens per task—cutting latency by 26.8%–60.2% and token costs by 35.3%–60.7% compared to LLM-based memory defenses (A-MemGuard and LLM Auditor–Rewrite).
Limitations and Future Work
- Explicit Retrieval Only: ExpGuard currently guards the explicit retrieval boundary. If an agent architecture injects persistent memory directly into the system prompt without a discrete retrieval step, ExpGuard won't catch it; those pathways need their own assessment boundaries.
- Variance in Repair Costs: While average latency is low (9.69s), the standard deviation is relatively high ($\pm 8.44\text{s}$), likely due to conditionally triggered, multi-round LLM repairs on tough cases. The authors suggest deeper analysis of serving-time costs and repair outcomes across broader agent architectures as future work.
Summary updated