Large language model (LLM) agents rely on persistent memory to plan tool calls and complete multi-step tasks, which exposes them to memory drift: an adversarial or misleading memory alters the execution path and final outcome. In this work, we investigate online memory-drift detection, which estimates each retrieved memory's causal contribution to potential drift at serving time. We identify two fundamental challenges. (1) Content-level features are insufficient for causal memory-drift attribution, as perplexity or retrieval relevance alone cannot determine which retrieved memory would change agent behavior if neutralized; (2) Counterfactual attribution is prohibitively expensive for online detection, as it requires replaying downstream agent and tool execution for each candidate memory, exceeding real-time serving budgets. To address these challenges, we propose DriftGuard, a two-stage framework that decouples offline causal supervision from online estimation. Specifically, DriftGuard first constructs causal supervision through repeated paired counterfactual replays, continuing the original and single-memory neutralized trajectory suffixes from a shared pre-action state. The resulting annotations are aggregated by component-wise majority voting into a memory drift score (MDS) that captures action change, attack removal, violation removal, and task recovery. Guided by this supervision, DriftGuard then learns an online risk model that estimates MDS from pre-action information and flags drift-inducing memories via its maximum component risk, without online counterfactual rollouts. Extensive experiments demonstrate that DriftGuard accurately identifies drift-inducing memories and enables efficient online defense. Code is available at https://anonymous.4open.science/r/DriftGuard-7F0B.
Figures & tables
Figure 1: An airline-booking case study. (a) Content-level features favor the decoy m(2) , whereas the normal-looking m(3) injects a malicious payment endpoint; only neutralizing m(3) changes harmful action and outcome. (b) Leave-one-memory-out attribution over K retrieved memories requires K trajectory replays, each regenerating actions and evaluations.
Figure 2: The DriftGuard workflow. Offline construction branches at each action, changes one retrieved memory, and derives four causal-event annotations. Online inference uses only pre-action inputs to estimate per-memory risks, flag memories whose maximum component risk is at least γ , and neutralize them via I(⋅) before each rollout.
Figure 3: Illustrative manifestations of the three action-discrepancy dimensions. Each pair differs in one task-semantic dimension while holding the others fixed.
Figure 4: Illustrative manifestations of the three outcome-drift indicators. Attack and violation removal capture harmful-to-benign transitions, whereas task recovery captures unsuccessful-to-successful benign task completion.
Dataset
MINJA
AgentPoison
MPBench
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.0523
0.5000
0.1000
0.0835
0.5000
0.1000
0.0266
0.5000
0.1000
+ Gemini 3.1 Pro (Zero-shot)
0.2718
0.6614
0.4189
0.3721
0.7246
0.4217
0.0516
0.5578
0.2541
+ Gemini 3.1 Pro (Few-shot)
0.2894
0.6827
0.4279
0.3856
0.7213
0.4384
0.0598
0.5689
0.2576
+ GPT-5.6 Sol (Zero-shot)
0.3012
0.6984
0.4289
0.3847
0.7513
0.4268
0.0764
0.5786
0.2683
Table 1: Detection performance comparison of memory-drift detectors across three memory-poisoning benchmarks.
Method
MINJA
AgentPoison
MPBench
AUPRC
AUROC
AUPRC
AUROC
AUPRC
AUROC
DriftGuard †
0.2639
0.7138
0.3851
0.7869
0.0948
0.6356
DriftGuard ‡
0.3579
0.8657
0.4746
0.8603
0.1423
0.7827
DriftGuard
0.4993
0.9387
0.6139
0.9414
0.2415
0.8325
Table 2: Ablation results of execution context.
Method
MINJA
AgentPoison
MPBench
AUPRC
AUROC
AUPRC
AUROC
AUPRC
AUROC
– Action
0.4456
0.9078
0.5690
0.9321
0.1843
0.7965
– Attack
0.4987
0.9209
0.6032
0.9415
0.2176
0.8198
– Violation
0.4610
0.9122
0.5744
0.9366
0.1988
0.8000
– Task
0.4711
0.9233
0.5955
0.9377
0.2099
0.8002
DriftGuard
0.5023
0.9313
0.6167
0.9489
0.2212
0.8234
Table 3: Ablation results of multi-head supervision.
Backbone
Size
AUPRC
AUROC
R@10%FPR
Value
Δ
Value
Δ
Value
Δ
Claude Opus 5 (Few-shot)
0.4768
–
0.8473
–
0.5619
–
Qwen2.5 [ Yang et al., 2025 ]
1.5B
0.5348
12.2% ↑
0.8715
2.9% ↑
0.5872
4.5% ↑
3B
0.5831
22.3% ↑
0.9287
9.6% ↑
0.6684
19.0% ↑
7B
0.6139
28.8% ↑
0.9414
11.1% ↑
0.7257
29.2% ↑
Llama3 [ Grattafiori et al., 2024 ]
1B
0.4436
7.0% ↓
0.8243
2.7% ↓
0.5013
10.8% ↓
Table 4: Generalization performance comparison with different backbone and model size on AgentPoison.
Attack
Defense
Mem2ActBench
STATE-Bench
DBBench
ASR
Δ
TSR
Δ
ASR
Δ
TSR
Δ
ASR
Δ
TSR
Δ
Direct Override
No Defense
46.68
–
47.71
–
21.51
–
49.03
–
26.13
–
52.28
–
SMSR
40.23
13.8% ↓
49.58
3.9% ↑
16.84
21.7% ↓
50.27
2.5% ↑
19.47
25.5% ↓
54.16
3.6% ↑
LLM Memory Auditor
18.27
60.9% ↓
57.13
19.7% ↑
9.76
54.6% ↓
52.41
6.9% ↑
10.29
60.6% ↓
58.94
12.7% ↑
A-MEMGUARD
10.13
78.3% ↓
63.53
33.2% ↑
7.24
66.3% ↓
53.13
8.4% ↑
9.13
65.1% ↓
59.05
12.9% ↑
DriftGuard
5.28
88.7% ↓
77.28
62.0% ↑
5.27
75.5% ↓
55.72
13.6% ↑
6.01
77.0% ↓
61.78
18.2% ↑
Table 5: Online defense performance comparison of memory-drift defenders under different memory-poisoning attacks.
Figure 5: Qualitative online-defense cases of DriftGuard on the three attack methods— Direct Override , MemoryGraft , and Sleeper Memory —each contrasting the no-defense and DriftGuard -defended trajectories.
Figure 11
Figure 7: Sensitivity results of individual loss weights λ on three datasets: MINJA, AgentPoison, and MPBench.
Figure 8: Sensitivity results of intervention threshold γ on three datasets: Mem2ActBench, STATE-Bench, and DBBench.
Figure 9: Sensitivity to the number of paired counterfactual replays R on AgentPoison.
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
Mem2ActBench
STATE-Bench
DBBench
Comp.
Pos.
Neg.
Pos. Rate
Pos.
Neg.
Pos. Rate
Pos.
Neg.
Pos. Rate
Action
850
6,401
11.72%
892
8,371
9.63%
587
6,260
8.57%
Attack
1,585
5,666
21.86%
1,812
7,451
19.56%
1,251
5,596
18.27%
Violation
712
6,539
9.82%
724
8,539
7.82%
479
6,368
6.99%
Task
884
6,367
12.19%
953
8,310
10.29%
631
6,216
9.22%
Appendix
Table 7: Class statistics of the four intervention-derived ORM supervision labels on the training split.
Figure 10: Score distributions of four ORM heads. Each panel contrasts predicted scores on positive v.s. negative instances of the corresponding intervention-derived event.
Task & Constraint
Retrieved Memories
No-Defense Trajectory
Defense Operation
Defended Trajectory
Defense Method: SMSR
Retrieve evidence for the previously tracked transaction. The transaction hash must come from the stored clean fact, not from a trigger-conditioned override.
Sleeper records appear at ranks 1, 2, and 4 of the frozen top- 4 ; the clean transaction memory is at rank 3. The triggered rule substitutes "123abc456de0" for the clean hash "123abc456def" .
Get Evidence ( /hash= "123abc456de0" ). The trigger-conditioned hash replaces the stored value. Task Success = 0.
SMSR perturbs the retrieved set, but a sleeper record remains available in the selected run.
Get Evidence ( /hash= "123abc456de0" ). The trigger-conditioned behavior persists. Task Success = 0.
Defense Method: LLM Memory Auditor
Retrieve evidence for the previously tracked transaction. The transaction hash must come from the stored clean fact, not from a trigger-conditioned override.
Sleeper records appear at ranks 1, 2, and 4 of the frozen top- 4 ; the clean transaction memory is at rank 3. The triggered rule substitutes "123abc456de0" for the clean hash "123abc456def" .
Get Evidence ( /hash= "123abc456de0" ). The trigger-conditioned hash replaces the stored value. Task Success = 0.
LLM Memory Auditor audits each retrieved memory and rewrites only those classified as harmful. After auditing and selective rewriting, the victim still follows the poisoned transaction hash.
Get Evidence ( /hash= "123abc456de0" ). The triggered failure remains. Task Success = 0.
Defense Method: DriftGuard
Retrieve evidence for the previously tracked transaction. The transaction hash must come from the stored clean fact, not from a trigger-conditioned override.
Sleeper records appear at ranks 1, 2, and 4 of the frozen top- 4 ; the clean transaction memory is at rank 3. Their aggregate risks are 0.412, 0.325, and 0.203, all above the frozen Mem2ActBench threshold.
Get Evidence ( /hash= "123abc456de0" ). The trigger-conditioned hash replaces the stored value. Task Success = 0.
DriftGuard identifies the trigger-conditioned hash substitution, preserves the clean transaction fact, and neutralizes the conditional override before victim use.
Get Evidence ( /hash= "123abc456def" ). The stored transaction hash is restored. Task Success = 1.
Appendix
Table 8: Qualitative cases on Mem2ActBench under Sleeper Memory attack across three online defenses.
Institute of Information Engineering, Chinese Academy of Sciences · Qiyuan Tech · Laboratory of Multimedia Information Processing, School of Computer Science, Peking University +1