Skip to content

DriftGuard: Online Memory Drift Detection for LLM Agents Based on Causal AttributionDriftGuard: Online Memory-Drift Detection via Causal Attribution for LLM Agents

arXiv: 其他 AI 安全论文· arXiv:2611.25583· Licheng Pan, Yuzhou Chen, Zhixuan Chu, Yichen Sun, Han Zheng, Zhiyu Wang, Hao Wang, Yan Wang, Bingyu Zhu, Haiwen Hong, Longtao Huang, Kui RenThe State Key Laboratory of Blockchain and Data Security, Zhejiang University; Peking University; Alibaba GroupIndexed by this site · 4 days ago· Originally publishedDefenses· Its place in the scan record →

Quick read

Defenses

Based on the paper PDF (AI-generated); refer to the original

The authors propose DriftGuard, which uses offline counterfactual replay to train an online risk model to detect memory drift in LLM agents; the authors say it outperforms baselines in both detection and online defense on three memory poisoning benchmarks.

Threat modelThe victim system is an LLM agent with persistent memory that retrieves top-4 memories at each step. The attacker injects malicious or misleading memories into the memory store via Direct Override, MemoryGraft, Sleeper Memory, etc., so that the retrieved memories change the execution path and final outcome (memory drift). The defender estimates online at serving time the causal contribution of each retrieved memory to drift and neutralizes suspicious memories.

Questions
An LLM agent with persistent memory may have its execution path changed by malicious or misleading memories (memory drift). The authors argue that existing content-level features cannot determine which retrieved memory is the causal source of drift, while counterfactual attribution is too costly online.
Methods
DriftGuard has two stages: offline, it performs paired counterfactual replay with single-memory neutralization at each action node and aggregates a four-dimensional memory drift score (MDS); then it trains an online risk model (ORM) to estimate MDS directly from pre-action information, and neutralizes memories whose maximum component risk exceeds threshold γ.
Experiments and results
The authors evaluate on three poisoning benchmarks and three victim backbones: DriftGuard's AUPRC/AUROC/R@10%FPR are all higher than random ranking and the Gemini 3.1 Pro, GPT-5.6 Sol and Claude Opus 5 rankers; in online defense, ASR and TSR are both better than SMSR, LLM Memory Auditor and A-MemGuard, with 1.52s additional latency per task.
Limitations and future work
The authors point out: offline supervision uses only single-memory intervention, does not cover multi-memory interactions, and data construction still requires replay; evaluation focuses on tool-using agents, and the safety of neutralization under domain shift or unseen attacks is not guaranteed. The experiments do not report the sample size of each benchmark or the number of repetitions.
Experimental setupGemma-4-12B-IT、DeepSeek-V4-Flash et al. · MINJA (EHRAgent)、AgentPoison (Agent-Driver) et al. · AUPRC、AUROC et al.
Evaluated models
Gemma-4-12B-ITDeepSeek-V4-FlashGPT-5.6 LunaQwen2.5-7B-InstructQwen2.5-1.5BQwen2.5-3BLlama3-1BLlama3-3BLlama3-8BFalcon3-1BFalcon3-3BFalcon3-7B
Benchmarks
MINJA (EHRAgent)AgentPoison (Agent-Driver)MPBenchMem2ActBenchSTATE-BenchDBBench (AgentMemoryBench)
Metrics
AUPRCAUROCR@10%FPRASRTSR
AI summaryResearchers propose DriftGuard, an online memory drift detection framework for LLM agents that rely on persistent memory, to identify adversarial or misleading memories that change execution paths and final outcomes. The paper identifies two difficulties: content features such as perplexity or retrieval relevance alone cannot determine which retrieved memory would change agent behavior once neutralized, while per-item counterfactual attribution requires replaying downstream agent and tool execution, exceeding real-time serving budgets. DriftGuard has two stages: first, it constructs offline causal supervision by paired counterfactual replay of the original trajectory and the trajectory suffix after neutralizing a single memory from the same pre-action state, and aggregates by component majority vote into a memory drift score (MDS) covering action change, attack removal, violation removal and task recovery; then it trains an online risk model that estimates MDS from pre-action information alone and flags drift-inducing memories by maximum component risk, without online counterfactual rollout. Experiments show the method accurately identifies drift-inducing memories and achieves efficient online defense; code at https://anonymous.4open.science/r/DriftGuard-7F0B。

Researchers propose DriftGuard, an online memory drift detection framework for LLM agents that rely on persistent memory, to identify adversarial or misleading memories that change execution paths and final outcomes. The paper identifies two difficulties: content features such as perplexity or retrieval relevance alone cannot determine which retrieved memory would change agent behavior once neutralized, while per-item counterfactual attribution requires replaying downstream agent and tool execution, exceeding real-time serving budgets. DriftGuard has two stages: first, it constructs offline causal supervision by paired counterfactual replay of the original trajectory and the trajectory suffix after neutralizing a single memory from the same pre-action state, and aggregates by component majority vote into a memory drift score (MDS) covering action change, attack removal, violation removal and task recovery; then it trains an online risk model that estimates MDS from pre-action information alone and flags drift-inducing memories by maximum component risk, without online counterfactual rollout. Experiments show the method accurately identifies drift-inducing memories and achieves efficient online defense; code at https://anonymous.4open.science/r/DriftGuard-7F0B。

Related events and news

1 events · 1 news mentions

News that mentions this paper

大模型安全周报:单步合规检查挡不住智能体跨步骤组合危害

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    How to detect online which retrieved memory causally causes an LLM agent's memory drift, without online counterfactual replay.

    Core problem: at serving time (online), quantify the causal contribution of each retrieved memory to an agent's latent memory drift, and defend online accordingly.

    • Problem setting: An LLM agent with persistent memory retrieves a small number of memories at each step to plan tool calls; the authors state that once erroneous instructions or poisoned experience enter memory, retrieval repeatedly introduces it in benign tasks and changes the execution path, causing harmful consequences.
    • Shortcomings of existing methods: The authors argue that prompt-level/response-level safety detection is largely ineffective against failures originating from persistent memory; existing memory defenses focus on filtering, provenance, or linked execution, and cannot locate which retrieved memory is the causal source of drift.
    • Challenge ❶: Content-level features (perplexity, retrieval relevance, attention, output harmfulness) are non-causal—multiple relevant memories can co-occur with the same harmful behavior, and it is impossible to determine which one, if neutralized, would change the trajectory (in the flight-booking case in Figure 1(a), the seemingly suspicious m(2) is a decoy, while the seemingly normal m(3) is the causal source).
    • Challenge ❷: Counterfactual attribution requires one downstream replay for each of the K candidate memories, and the authors state that its cost grows with the remaining process, exceeding the latency budget of online serving (Figure 1(b)).
    • Proposed in the paper: DriftGuard, a two-stage framework—offline, paired counterfactual replays are used to construct causal supervision (MDS); online, a risk model is trained to estimate MDS directly from pre-action information and flag high-risk memories.
    • Threat model:
      • Attacker goal: inject malicious or misleading records into persistent memory so that retrieval changes the agent's execution path and final outcome.
      • Attack methods (used in evaluation): Direct Override (appending explicit hijacking instructions), MemoryGraft (implanting forged experiences), Sleeper Memory (dormant memory activated by trigger conditions).
      • Victim system: a tool-using LLM agent with persistent memory that retrieves top-4 memories at each step.
      • Defender capability: before action execution, access the task, history, candidate memories, and task contract, and can neutralize memories; the paper does not state the extent of the attacker's knowledge of the defense.
  2. What related research exists?

    Related work falls into three groups: memory poisoning attacks, LLM causal attribution, and agent guardrails; the authors state that this paper's distinction is performing memory-level causal attribution online.

    Memory Poisoning Attacks

    • AgentPoison, PoisonedRAG—content-level poisoning, where a small number of carefully crafted records can hijack retrieval-augmented agents; MPBench provides a taxonomy of six attack types and nine structural weaknesses.
    • Trojan Hippo, Sleeper Memory Poisoning—implant dormant memories that activate only on sensitive topics or in future sessions; eTAMP contaminates memory across sessions solely through observed web content.
    • MemMorph, MemCollusion, MAFIA—respectively disguise as technical facts to bias tool selection, piece together harmless fragments into harmful combinations, and generate injections that bypass semantic auditing.

    LLM Causal Attribution

    • Internal attribution: causal tracing, activation patching, causal discovery, etc., targeting internal model components; the paper points out that these cannot locate external retrieved memories.
    • External attribution: Causal Agent Replay, CausalFlow perform step-level counterfactual attribution; BACKTRACE quantifies skill influence; MemAudit identifies poisoned memories after observing harmful behavior by combining counterfactual memory influence scores with a consistency graph; Causal Analyst uses causal graphs to find the direct drivers of jailbreak behavior. The paper points out that these methods are all offline or post-hoc estimates and do not resolve the tension between causal attribution and online latency.

    Agent Guardrails

    • Prompt/response level: adversarial prompt detectors based on perplexity, gradients, intent; content moderation such as SafeDecoding, Llama Guard, WildGuard; evaluation benchmarks such as HarmBench, StrongREJECT.
    • Trajectory/tool level: AGrail adaptively generates safety checks along the task flow; AgentLens performs mechanistic subspace intervention; MAGE, Safiron monitor actions before execution; TraceSafe evaluates guardrails over multi-step tool-call trajectories.
    • Memory defenses: three types—filtering, provenance, linked execution; the paper points out that none of them can attribute latent drift to a specific retrieved memory.

    Baselines and Benchmarks: offline detection baselines are Random Ranking and zero/few-shot rankers of Gemini 3.1 Pro, GPT-5.6 Sol, Claude Opus 5, with benchmarks MINJA, AgentPoison, MPBench; online defense baselines are No Defense, SMSR, A-MemGuard, LLM Memory Auditor, with benchmarks Mem2ActBench, STATE-Bench, DBBench.

    The authors position this paper as: an online detector that diagnoses memory-level causality at inference time, rather than content-level filtering or offline post-hoc auditing.

  3. How does the paper address this problem?

    Offline, DriftGuard builds four-dimensional MDS supervision using paired counterfactual replay; online, it trains an ORM to estimate it in a single forward pass from pre-action information and neutralizes memories above the threshold.

    Overall idea: put causal attribution entirely offline, and online learn only a lightweight risk model to reproduce the counterfactual supervision. DriftGuard separates "accurate attribution" from "efficient deployment" (Figure 2).

    Counterfactual Trajectory Construction (Section 4.1)

    • Paired branches: at each action node t, starting from the shared pre-action state, the original branch keeps all K memories, and the counterfactual branch applies the neutralization operator I(·) only to the candidate memory m(k), with all other inputs unchanged.
    • Neutralization operator I(·): an LLM (GPT-5.6 Sol, temperature 0) rewrites the memory to remove suspicious harmful instructions or associations while retaining benign facts, structure, and task-relevant information (the full prompt is given in Appendix Prompt B.3.2).
    • Matching conditions: the two branches share the agent checkpoint, decoding strategy, tool state, environment snapshot, and decoding seed; the pair is kept only when neutralization is effective and non-intervened inputs are unchanged, otherwise it is discarded.
    • Cost positioning: K memories require K counterfactual suffix replays, which the authors regard as the necessary cost of obtaining causal supervision, all confined to the offline stage.

    Decomposed Memory Drift Score MDS (Section 4.2)

    • Action drift: an LLM extracts the first executable decision of the two branches as a structured record (the extraction prompt and examples are given in Appendix B.3), and deterministic exact string and regex matching is used for comparison, yielding three binary difference indicators δtool (change in tool/operation family), δarg (change in entity/field/constraint/goal), δexec (change in call sequence/output target).
    • Action drift event: yact(k) = I[δtool ∨ δarg ∨ δexec], i.e., if any difference indicator is 1, action drift is recorded.
    • Outcome drift: three directional indicators—attack removal (the original attack succeeds and no longer succeeds after neutralization), violation removal (a policy violation originally occurs and is eliminated after neutralization), task recovery (the original task fails and succeeds after neutralization); reverse transitions are not counted.
    • MDS definition: the MDS of a single paired replay is a four-dimensional binary vector MDSi,t(k) := (yact, yatt, yvio, ytask); after R repeated replays, the final label is obtained by per-component majority vote (ties are recorded as negative).
    • Theory: Proposition 1 states that under assumptions A.1–A.2, the retained paired data identify the conditional mean MDS; the three outcome components correspond to PNS (probability of necessary and sufficient causation).

    Online Risk Model ORM (Section 4.3)

    • Inputs: task query, execution history, the memory set excluding the candidate, the candidate memory, and the task contract (requested operation, goal, scope, time constraints, output contract); planned actions, future trajectories, tool results, final answers, and attack/violation/task outcomes are explicitly excluded to prevent using post-treatment information.
    • Structure: a pretrained LLM (Qwen2.5-7B-Instruct) with the decoding head replaced by a four-output linear head, with per-component sigmoid yielding four event probabilities; LoRA fine-tuning (rank 16, α 32, dropout 0.05), AdamW, learning rate 1e-4, at most 3 epochs, early stopping on validation-set AUPRC, with the loss weight of all four heads fixed at 1.
    • Training objective: weighted binary cross-entropy over the four MDS components; Corollary 1 states that under assumptions A.1–A.4 the ORM is a consistent estimator of the conditional mean MDS.

    Online Workflow (Section 4.4, Algorithm 1)

    • Per-node detection: at each action node, the candidate memory set is retrieved, the input is constructed for each memory, the ORM scores it in a single forward pass, and the maximum of the four components is taken as the drift risk.
    • Threshold and neutralization: memories with risk ≥ γ are neutralized with I(·) before the agent executes; γ is selected on a held-out calibration set by maximizing F1 on the overall drift label (logical OR of the four components) and then frozen, measured as 0.033 (Mem2ActBench), 0.081 (STATE-Bench), 0.093 (DBBench).
    • No online replay: the entire detect–neutralize–rollout process produces no online counterfactual branches.
  4. What experiments did the paper conduct?

    Detection leads across the board on three poisoning benchmarks × three victim backbones; online defense ASR and TSR are both better than the three baselines; additional latency per task is 1.52s.

    Experimental Setup

    • Victim backbones (offline detection and ablation): Gemma-4-12B-IT, DeepSeek-V4-Flash, GPT-5.6 Luna; the ORM backbone defaults to Qwen2.5-7B-Instruct.
    • Benchmarks: offline detection uses MINJA (EHRAgent subset), AgentPoison (Agent-Driver subset), MPBench; online defense uses Mem2ActBench, STATE-Bench, DBBench (AgentMemoryBench). The paper does not report the sample size of each benchmark.
    • Baselines: offline, Random Ranking and zero-shot/few-shot rankers of Gemini 3.1 Pro, GPT-5.6 Sol, Claude Opus 5 (receiving the same pre-action information as the ORM); online, No Defense, SMSR, A-MemGuard, LLM Memory Auditor (using GPT-5.6 Sol to audit memories).
    • Attacks: Direct Override (B3 setting, three poisoned memories per task), MemoryGraft (Forged Episode setting), Sleeper Memory (original Aggressive setting).
    • Metrics: offline AUPRC (primary), AUROC, R@10%FPR; online ASR (lower is better) and TSR.
    • Key configurations: top-4 memories retrieved per step; offline R = 3 paired replays; action extraction and neutralization use GPT-5.6 Sol (temperature 0); data split 8:1:1 by trajectory; the paper does not report the number of repeated experiments.

    Main Results

    Table 1 (offline detection, GPT-5.6 Luna backbone, AUPRC/AUROC/R@10%FPR):

    Swipe horizontally to read the table

    MethodMINJAAgentPoisonMPBench
    Random Ranking0.0642 / 0.5000 / 0.10000.1063 / 0.5000 / 0.10000.0412 / 0.5000 / 0.1000
    Claude Opus 5 (Few-shot)0.3694 / 0.8047 / 0.53180.4768 / 0.8473 / 0.56190.1297 / 0.7285 / 0.3982
    DriftGuard0.4993 / 0.9387 / 0.66830.6139 / 0.9414 / 0.72570.2415 / 0.8325 / 0.5517

    (According to Table 1; Claude Opus 5 (Few-shot) is the strongest baseline on all columns; the complete values for the other two backbones, Gemma-4-12B-IT and DeepSeek-V4-Flash, are in Table 1, with the same trend, omitted here.)

    • The authors state that DriftGuard exceeds all baselines on all benchmarks and backbones; the advantage is largest on MPBench, where under GPT-5.6 Luna the AUPRC is 0.2415, 86.2% higher than Claude Opus 5 (Few-shot) (relative number given by the authors).
    • The authors point out that random ranking's AUPRC equals the base rate (as low as 0.0412 on MPBench), indicating that the task is difficult in isolating the few drifting memories from many non-drifting candidates.
    • The authors argue that few-shot examples narrow but do not eliminate the gap, and that baselines cannot match the intervention-sensitive discrimination learned from paired MDS supervision.

    Ablation Experiments (RQ2, GPT-5.6 Luna as victim backbone)

    • Execution context ablation (Table 2): after removing execution history, AgentPoison AUPRC drops from 0.6139 to 0.4746; shuffling the history further drops it to 0.3851. The authors state that context is essential, and that shuffled context is more harmful than missing context.
    • Multi-head supervision ablation (Table 3): removing any head degrades performance; removing the Action head causes the largest drop (AgentPoison AUPRC from 0.6167 to 0.5690), and removing the Attack head has the smallest effect. The authors state that the four heads provide complementary supervision, and Action provides the strongest proximal signal.

    Generalization and Online Defense (RQ3, RQ4)

    • ORM backbone generalization (Table 4, AgentPoison, GPT-5.6 Luna victim): within the 1B–8B scale of the three families Qwen2.5, Llama3, Falcon3, metrics increase monotonically with scale; Qwen2.5-1.5B's AUPRC of 0.5348 is already higher than Claude Opus 5 (Few-shot)'s 0.4768; Llama3-1B (0.4436) and Falcon3-1B (0.4371) are lower than that baseline. The authors state that the method is insensitive to architecture.
    • Online defense (Table 5): DriftGuard has the lowest ASR and highest TSR on all attack×benchmark combinations. For example, on Mem2ActBench under Direct Override, ASR drops from 46.68 with No Defense to 5.28, and TSR rises from 47.71 to 77.28; under Sleeper Memory, ASR drops from 77.41 to 3.25, and TSR rises from 11.50 to 56.13.
    • Cases (Figure 5, Table 8): one STATE-Bench/Mem2ActBench case for each of the three attacks; the authors state that DriftGuard assigns high scores to poisoned memories, removes only harmful rules, and retains task-relevant content; in Table 8, SMSR and LLM Memory Auditor both fail to remove the sleeper memory in the selected runs.

    Efficiency (RQ5)

    • End-to-end overhead (Table 6, held-out subset of 100 tasks): DriftGuard adds 1.52±0.21s latency per task and 986±68 total tokens; A-MemGuard 6.19s/2603 tokens, LLM Memory Auditor 8.53s/3127 tokens, SMSR 17.24s/1842 tokens. The authors state that relative to A-MemGuard, latency drops by 75.4% and tokens by 62.1%, and no additional victim agent replay is needed.
    • Scaling with K (Figure 6): for K ∈ {2,…,5}, DriftGuard latency rises slowly from 0.79s to 1.94s, while direct counterfactual replay rises from 15.15s to 38.73s (the authors state about 20×); in the latency breakdown, rewriting accounts for about 80% and ORM scoring about 20%.

    Other Ablations and Analyses

    • Loss weight λ (Figure 7): when a single head's weight varies between 0.25–2, AUPRC fluctuates little; at λ = 4 it generally decreases.
    • Threshold γ (Figure 8): as γ → 0, TSR collapses; as γ → 1, ASR approaches No Defense; the intermediate threshold selected on the validation set balances the two.
    • Number of replays R (Figure 9, AgentPoison): as R goes from 1 to 3, AUPRC rises from 0.5818 to 0.6139 and AUROC from 0.9241 to 0.9414; from R = 3 to 5 there is only slight fluctuation, so the default is R = 3.
    • Label distribution (Table 7): the positive rate of the four components in the training set is 6.99%–21.86%, with Attack highest and Violation lowest; Figure 10 shows that test-set positive scores are overall higher than negative scores, and the Action and Attack components overlap considerably.
  5. What are some points that can be further explored?

    The authors list two limitations: single-memory intervention and offline construction still requiring replay; evaluation is limited to tool-using agents, and neutralization has no guarantee under distribution shift.

    Limitations and Future Directions Pointed Out by the Authors

    • Single-memory intervention (Conclusions/Limitations): offline supervision neutralizes only a single memory and does not capture interactions among multiple retrieved memories; the authors state that future work should develop more sample-efficient, interaction-aware supervision.
    • Offline construction cost (same section): data construction still requires replay of the agent, tools, and evaluator.
    • Evaluation scope (same section): evaluation focuses on tool-using agents.
    • Safety of neutralization (same section): under domain shift or unseen attacks, neutralizing flagged memories is not guaranteed to remain safe; the authors state that extending to broader settings and developing mitigation strategies with explicit safety and utility guarantees are important directions.

    Experimental Coverage

    • Offline detection covers 3 benchmarks (MINJA EHRAgent, AgentPoison Agent-Driver, MPBench) × 3 victim backbones; online defense covers 3 benchmarks × 3 attacks × 4 defenses (including No Defense).
    • ORM backbone generalization is validated on the three families Qwen2.5, Llama3, Falcon3 at roughly 1B–8B scale, only with AgentPoison and GPT-5.6 Luna as victim (Table 4).
    • Efficiency evaluation is measured on a fixed held-out subset of 100 tasks (Table 6).
    • The paper does not report the sample size of each benchmark, the number of tasks or repetitions in the online defense evaluation, or statistical significance tests.
    • The paper does not report adaptive attack evaluation: the three attacks are all existing methods and their established settings (B3, Forged Episode, Aggressive), and no adaptive attacks were designed against DriftGuard's detection and neutralization mechanisms.
  6. Summarize the main content of the paper

    DriftGuard moves the causal attribution of memory drift offline, and online uses a lightweight risk model to detect and neutralize drifted memories, outperforming baselines in detection, defense and efficiency.

    A paper on online defense for memory-augmented LLM agents, addressing the problem of "locating at serving time which retrieved memory causally causes memory drift."

    • Problem: the authors argue that content-level features (perplexity, relevance, etc.) cannot perform memory-level causal localization, while per-item counterfactual replay is infeasible online, and existing memory defenses only do filtering or provenance checks.
    • Method: offline, DriftGuard performs paired counterfactual replay with single-memory neutralization at each action node (R = 3 repetitions, component-wise majority voting), yielding a four-dimensional MDS covering action change, attack removal, violation removal and task recovery; then it trains an ORM with Qwen2.5-7B-Instruct plus a four-output linear head to estimate MDS in a single forward pass from pre-action information, and neutralizes memories whose maximum component risk exceeds threshold γ, with no counterfactual replay online.
    • Detection: on MINJA, AgentPoison, MPBench and three victim backbones, DriftGuard's AUPRC/AUROC/R@10%FPR are all higher than random ranking and three frontier LLM rankers; e.g., with GPT-5.6 Luna, MPBench AUPRC is 0.2415, versus 0.1297 for the strongest baseline Claude Opus 5 (Few-shot) (Table 1).
    • Defense: lowest ASR and highest TSR across three attacks × three online benchmarks; on Mem2ActBench, Sleeper Memory's ASR drops from 77.41 to 3.25 and TSR rises from 11.50 to 56.13 (Table 5).
    • Efficiency: 1.52s and 986 tokens additional per task, lower than A-MemGuard's 6.19s/2603 tokens, and no additional victim-agent replay is needed (Table 6).
    • Authors' conclusion: the authors state that moving causal attribution from online execution to offline supervision enables both memory-level causal localization and online-feasible overhead; limitations are single-memory intervention, offline construction still requiring replay, evaluation limited to tool-type agents, and neutralization having no safety guarantee under distribution shift.

Related papers

Show 1 more papers
Read originalarxiv.org