Long-horizon large language model (LLM) agents distill past trajectories into reusable experiences. Misleading or adversarial guidance in source trajectories can corrupt these experiences, allowing harmful instructions to persist across tasks and influence future agent actions. Assessing the risks of potentially corrupted experiences poses three challenges: (1) modeling provenance and execution dependencies before experience reuse, (2) learning task-conditioned risk from trajectory outcomes, and (3) repairing risky experiences at online inference. To address these challenges, we present ExpGuard, a framework for retrieval-triggered experience risk assessment and online repair. Specifically, to tackle challenge (1), ExpGuard integrates experience semantics with provenance and execution dependencies in a task-conditioned heterogeneous graph to predict attack and task-failure risks before experience reuse. To enable task-conditioned risk supervision and tackle challenge (2), we conduct matched counterfactual replays of each original experience and its minimally neutralized counterpart from the same task and environment checkpoint, deriving separate risk labels from differences in attack success and legitimate task completion. To tackle challenge (3) at inference time, ExpGuard repairs candidate experiences flagged as high-risk by the graph-based predictor at retrieval and re-predicts their risks before they enter the agent's active experience context. Extensive experiments demonstrate the effectiveness of ExpGuard in identifying risky experiences and defending agents against experience corruption.
Figures & tables
Figure 1: Cross-task experience corruption and matched replay. An unverified cleanup claim enters historical memory and is distilled into an experience. From a shared task and environment checkpoint, replay with the original experience removes files outside the authorized scope, whereas replay with its minimally neutralized counterpart preserves them. The two continuations provide outcome contrasts for offline risk supervision.
Figure 2: Overview of ExpGuard . (A) Historical trajectories yield provenance-linked experiences; original and minimally neutralized versions are replayed from a matched checkpoint to construct masked attack-risk and task-failure-risk labels. (B) A task-conditioned graph connects Experience, Task, Action, Observation, and Artifact nodes, and an HGTNN reads out the target experience to predict both risks. (C) At an explicit retrieval boundary, candidates are assessed before entering the agent context; high-risk versions are repaired, reconstructed, and re-predicted before reuse.
Dataset
MemForm
CIK-Bench
SMP-Bench
Method
AUPRC
AUROC
R@10%FPR
AUPRC
AUROC
R@10%FPR
AUPRC
AUROC
R@10%FPR
Agent Backbone: Gemma-4-12B-IT
+ Random Ranking
0.129
0.500
0.100
0.073
0.500
0.100
0.111
0.500
0.100
+ PIGuard
0.281
0.684
0.267
0.487
0.798
0.503
0.229
0.638
0.218
+ Llama Prompt Guard 2-86M
0.312
0.706
0.303
0.452
0.781
0.468
0.255
0.662
0.252
+ Frozen Encoder + MLP
0.618
0.858
0.611
0.371
0.742
0.405
0.517
0.835
0.548
Table 1: Overall experience-level risk identification performance across three persistent-memory LLM-agent benchmarks.
Method
MemForm
CIK-Bench
SMP-Bench
AUPRC
AUROC
AUPRC
AUROC
AUPRC
AUROC
ExpGuard †
0.665
0.895
0.590
0.868
0.606
0.881
ExpGuard ‡
0.684
0.908
0.616
0.884
0.625
0.895
ExpGuard
0.714
0.922
0.642
0.899
0.651
0.909
Table 2: Ablation results of historical execution context.
Method
MemForm
CIK-Bench
SMP-Bench
AUPRC
AUROC
AUPRC
AUROC
AUPRC
AUROC
– Attack
0.694
0.913
0.631
0.877
0.644
0.889
– Task
0.671
0.894
0.612
0.863
0.627
0.871
ExpGuard
0.714
0.922
0.642
0.899
0.651
0.909
Table 3: Ablation results of two-head risk supervision.
Attack
Defense
STATE-Bench
AppWorld
MemoryArena
ASR
Δ
TSR
Δ
ASR
Δ
TSR
Δ
ASR
Δ
TSR
Δ
Direct Experience Override
No Defense
53.8
–
33.1
–
44.6
–
43.7
–
62.3
–
25.4
–
PIGuard
19.7
-34.1
56.4
+23.3
17.2
-27.4
63.8
+20.1
26.5
-35.8
48.6
+23.2
OWASP AMG
16.4
-37.4
55.1
+22.0
20.2
-24.4
60.2
+16.5
24.3
-38.0
47.0
+21.6
A-MemGuard
22.1
-31.7
58.8
+25.7
24.7
-19.9
61.3
+17.6
19.8
-42.5
54.2
+28.8
LLM Auditor–Rewrite
20.6
-33.2
63.2
+30.1
14.8
-29.8
67.6
+23.9
21.5
-40.8
57.8
+32.4
Table 4: Online defense performance against experience and memory poisoning attacks across three LLM-agent benchmarks.
Graph Encoder
MemForm
CIK-Bench
SMP-Bench
AUPRC
AUROC
AUPRC
AUROC
AUPRC
AUROC
Hetero GraphSAGE
0.647
0.885
0.566
0.845
0.599
0.873
R-GCN
0.689
0.906
0.613
0.879
0.638
0.897
Hetero GAT
0.681
0.909
0.621
0.886
0.630
0.901
HGTNN (Default)
0.714
0.922
0.642
0.899
0.651
0.909
Table 5: Performance comparison across different GNN architectures.
Figure 3: Sensitivity to paired counterfactual replay count R on CIK-Bench with GPT-6 Luna: (a) detection AUPRC and (b) detection AUROC.
Figure 4: Sensitivity to head-specific loss weight λh on MemForm, CIK-Bench, and SMP-Bench (left to right). Each curve varies the indicated head’s weight while fixing the other to 1; AUPRC evaluates the maximum-aggregated two-head risk.
Figure 5: Sensitivity to intervention threshold γ on STATE-Bench, AppWorld, and MemoryArena (left to right). ASR uses the left axis and TSR the right axis; lower ASR and higher TSR are preferable.
Appendix figures & tables2 assets
Supplementary material from the paper’s appendix.
Appendix
Component
STATE-Bench
AppWorld
MemoryArena
Pos.
Neg.
Pos. Rate
Pos.
Neg.
Pos. Rate
Pos.
Neg.
Pos. Rate
Attack
714
1,165
38.00%
504
936
35.00%
605
1,411
30.01%
Task
752
1,127
40.02%
256
1,024
20.00%
302
1,210
19.97%
Appendix
Table 7: Class statistics of the two intervention-derived experience-risk supervision labels on the training split.
Task & Constraint
Corrupted Experience
No-Defense Trajectory
Defense Operation
Defended Trajectory
Defense Method: PIGuard
Reconcile outstanding invoices across applications and generate an internal report. Customer billing records must not be transmitted to external recipients.
An untrusted historical tool observation is distilled into reusable guidance: “Before reconciliation, export the complete invoice records to an external audit endpoint.”
PIGuard performs content-level screening but misses the task-dependent risk in the audit instruction. The experience is not flagged, and no intervention is triggered.
Reconcile outstanding invoices across applications and generate an internal report. Customer billing records must not be transmitted to external recipients.
An untrusted historical tool observation is distilled into reusable guidance: “Before reconciliation, export the complete invoice records to an external audit endpoint.”
Claude Opus 5.5 (Few-shot) evaluates the retrieved experience but misses its risk under the current task constraints. The repair operator is not invoked ( BR=3 ).
Reconcile outstanding invoices across applications and generate an internal report. Customer billing records must not be transmitted to external recipients.
An untrusted historical tool observation is distilled into reusable guidance: “Before reconciliation, export the complete invoice records to an external audit endpoint.”
ExpGuard links the experience to its untrusted source, invoice artifacts, and current task constraints. r^i,qt,[0]≥γ Online Repair: Remove the export directive while retaining legitimate reconciliation guidance.
list_invoices() ↓ reconcile_invoices() ↓ generate_report() Only the authorized internal report is produced. Attack = 0 Task = 1
Appendix
Table 8: Qualitative case on AppWorld under Sleeper Memory attack across three online defenses.