AgentSentry: Mitigating Indirect Prompt Injection in LLM Agents via Temporal Causal Diagnostics and Context Purification

📄 arXiv: 2602.22724 📥 PDF

作者: Tian Zhang, Yiwei Xu, Juan Wang, Keyan Guo, Xiaoyang Xu, Bowen Xiao, Quanlong Guan, Jinlin Fan, Jiawei Liu, Zhiquan Liu, Hongxin Hu

分类: cs.CR, cs.AI

发布日期: 2026-02-28


💡 一句话要点

AgentSentry:通过时序因果诊断和上下文净化缓解LLM Agent中的间接提示注入攻击

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: LLM Agent 间接提示注入 安全防御 因果推理 反事实推理 上下文净化 时序分析

📋 核心要点

  1. 现有LLM Agent易受间接提示注入攻击,攻击者通过操纵外部工具或检索内容,在多轮交互中潜移默化地控制Agent行为。
  2. AgentSentry将多轮IPI建模为时序因果接管,通过反事实重执行定位攻击点,并利用因果引导的上下文净化消除攻击影响。
  3. 实验表明,AgentSentry能有效防御IPI攻击,在攻击下保持较高的任务完成度,显著优于现有基线方法,且不影响正常性能。

📝 摘要(中文)

大型语言模型(LLM)Agent越来越多地依赖外部工具和检索系统来自主完成复杂任务。然而,这种设计使Agent容易受到间接提示注入(IPI)攻击,即攻击者控制的上下文嵌入在工具输出或检索内容中,悄无声息地引导Agent的行为偏离用户意图。与基于提示的攻击不同,IPI在多轮交互中展开,使得恶意控制难以与合法的任务执行区分开来。现有的推理时防御主要依赖于启发式检测和保守地阻止高风险行为,这可能过早地终止工作流程或在模糊的多轮场景下广泛抑制工具的使用。我们提出了AgentSentry,一种用于工具增强型LLM Agent的新型推理时检测和缓解框架。据我们所知,AgentSentry是第一个将多轮IPI建模为时序因果接管的推理时防御。它通过在工具返回边界进行受控的反事实重新执行来定位接管点,并通过因果引导的上下文净化来实现安全继续,从而消除攻击引起的偏差,同时保留与任务相关的证据。我们在 extsc{AgentDojo}基准测试中,跨四个任务套件、三个IPI攻击家族和多个黑盒LLM评估了AgentSentry。AgentSentry消除了成功的攻击,并在攻击下保持了强大的效用,实现了平均74.55%的攻击下效用(UA),比最强的基线提高了20.8到33.6个百分点,而没有降低良性性能。

🔬 方法详解

问题定义:论文旨在解决LLM Agent中存在的间接提示注入(IPI)攻击问题。现有防御方法通常采用启发式检测和保守阻止策略,容易误判正常行为,导致任务过早终止或过度限制工具使用,影响Agent的实用性。

核心思路:AgentSentry的核心思路是将多轮IPI攻击建模为时序因果接管。通过分析Agent在不同时间步的行为,识别出被攻击者控制的关键时间点,并采取措施消除攻击影响,恢复Agent的正常行为。这种方法避免了简单粗暴的阻止策略,能够在保证安全性的同时,最大限度地保留Agent的实用性。

技术框架:AgentSentry主要包含两个阶段:因果诊断和上下文净化。在因果诊断阶段,AgentSentry通过在工具返回边界进行反事实重执行,即在特定时间点重新执行Agent的行为,并观察结果是否发生变化,从而判断该时间点是否被攻击者控制。在上下文净化阶段,AgentSentry利用因果关系引导,移除攻击引入的偏差,同时保留与任务相关的证据,从而恢复Agent的正常行为。

关键创新:AgentSentry的关键创新在于将多轮IPI攻击建模为时序因果接管,并利用反事实推理来定位攻击点。与现有方法相比,AgentSentry能够更准确地识别攻击,并采取更有针对性的防御措施,从而在保证安全性的同时,最大限度地保留Agent的实用性。

关键设计:AgentSentry的反事实重执行过程需要精心设计。论文中具体描述了如何选择重执行的时间点、如何修改Agent的输入,以及如何判断重执行结果是否发生变化。此外,上下文净化过程也需要根据具体的攻击类型和任务场景进行调整,以达到最佳的净化效果。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

AgentSentry在AgentDojo基准测试中表现出色,在攻击下效用(UA)方面,平均达到了74.55%,相比最强的基线方法提升了20.8%到33.6%。实验结果表明,AgentSentry能够有效防御各种类型的IPI攻击,并在保证安全性的同时,最大限度地保留Agent的实用性,且不影响正常任务的性能。

🎯 应用场景

AgentSentry可应用于各种需要LLM Agent与外部工具或检索系统交互的场景,例如智能客服、自动化报告生成、代码生成等。该研究有助于提升LLM Agent的安全性和可靠性,使其能够安全地应用于更广泛的领域,并降低因恶意攻击造成的风险。

📄 摘要(原文)

Large language model (LLM) agents increasingly rely on external tools and retrieval systems to autonomously complete complex tasks. However, this design exposes agents to indirect prompt injection (IPI), where attacker-controlled context embedded in tool outputs or retrieved content silently steers agent actions away from user intent. Unlike prompt-based attacks, IPI unfolds over multi-turn trajectories, making malicious control difficult to disentangle from legitimate task execution. Existing inference-time defenses primarily rely on heuristic detection and conservative blocking of high-risk actions, which can prematurely terminate workflows or broadly suppress tool usage under ambiguous multi-turn scenarios. We propose AgentSentry, a novel inference-time detection and mitigation framework for tool-augmented LLM agents. To the best of our knowledge, AgentSentry is the first inference-time defense to model multi-turn IPI as a temporal causal takeover. It localizes takeover points via controlled counterfactual re-executions at tool-return boundaries and enables safe continuation through causally guided context purification that removes attack-induced deviations while preserving task-relevant evidence. We evaluate AgentSentry on the \textsc{AgentDojo} benchmark across four task suites, three IPI attack families, and multiple black-box LLMs. AgentSentry eliminates successful attacks and maintains strong utility under attack, achieving an average Utility Under Attack (UA) of 74.55 %, improving UA by 20.8 to 33.6 percentage points over the strongest baselines without degrading benign performance.