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.
As large language model (LLM) agents increasingly invoke external tools and interact with real-world systems, unsafe actions may cause irreversible consequences on external states, user data, and downstream services. Recent runtime guardrails mitigate such risks by checking proposed actions before execution, but many remain reactive: they primarily assess the apparent safety of the current action, lacking an explicit model of how risk evolves across the trajectory. This limitation creates a critical blind spot for long-horizon risks, where individually benign-looking actions can gradually drift the agent toward hazardous states. In response, we propose DreamGuard, a proactive guardrail for LLM agents built around a risk-aware world model. The world model maintains a compact recurrent latent state over the trajectory and predicts future latent states from which DreamGuard derives immediate-hazard and prefix-risk evidence. It then fuses these multi-horizon signals into intervention decisions before execution. Experiments across four benchmarks and an online guardrail evaluation show that DreamGuard outperforms generic, reactive, and proactive guardrail baselines, achieves the best safety-utility trade-off among evaluated guardrails, and maintains an average end-to-end latency of 25 ms per call.
Wenhao Lin, Chenyu Yu, Xingwei Lin +6
Zhejiang University · Nanjing University of Posts and Telecommunications · Sun Yat-sen University
LLM-based guardrails typically safeguard agents by evaluating proposed actions or inputs before execution, producing safety signals such as binary allow/deny decisions, risk categories, and/or explanatory rationales about potential policy violations. However, agent risks often arise when otherwise benign tasks are contaminated by untrusted external content, unsafe instructions, or risky tool use. Existing guardrails often flag the entire task uniformly as unsafe, thereby blocking the threat but sacrificing the benign part. Moreover, existing work largely evaluates guardrails in isolation, leaving unclear whether their interventions lead to safer downstream agent behavior. To address this, we introduce TRIAD (Tripartite Response for Iterative Agent Guardrailing), a guardrail-integrated agent framework that leverages guardrail-generated verbal feedback as a guiding signal to keep the agent aligned with benign objectives at each planning step. We finetune a language model on a self-curated training dataset to output one of three decisions: proceed, refuse, or update, together with structured natural-language feedback. Rather than merely allowing or blocking execution, update guides the agent to revise its plan, avoid harmful components, and preserve the benign task where possible. TRIAD injects this feedback into the agent's context, enabling subsequent plan revision and forming a closed loop between guardrail feedback and agent planning. Extensive experiments on ASB and AgentHarm show that TRIAD reduces the average attack success rate to 10.42%, while achieving the best safety-utility trade-off among guardrail-integrated baselines. Our code is available at: https://github.com/YUHAOSUNABC/TRIAD.
Yuhao Sun, Jiacheng Zhang, Shaanan Cohney +3
1The University of Melbourne · 2Tsinghua University · †Corresponding author.
Many real-world tasks require LLM agents to interact with their environments over long execution horizons. Errors that occur early in execution may propagate through both the agent context and environment state, and their effects may be difficult to reverse through subsequent actions. Existing methods mainly seek to reduce such errors through plan refinement and safety checks but provide little support after errors occur. To enable recovery during long-horizon execution, we present AgentRewind, a runtime recovery framework that records aligned checkpoints of the agent context and controlled environment, allowing agents to return to an earlier state and resume execution with information from previous attempts. We also construct MettleBench, a benchmark for evaluating task completion and partial progress on long-horizon engineering assignments containing a series of related requirements. Experiments across tasks, multiple models, execution strategies, and agent harnesses show that AgentRewind improves task success rate and average checklist progress over the compared baselines.
Yu Zhuang, Kefei Chen, Yitong Duan +3
University of Chinese Academy of Sciences · Zhongguancun Academy, Beijing, China · Institute of Automation, Chinese Academy of Sciences +1