论文代码
AutoPI: Taxonomy-Guided Adaptive Red Teaming for Prompt Injection in LLM Agents
AutoPI 是一款面向使用工具的 LLM 智能体的自适应红队工具。它的设计目标是找出多种不同的方式来 攻破智能体,而不仅仅是频繁地攻破它。对于每个场景,攻击者 LLM 会针对提示注入分类法中的每个子技术 编写间接提示注入,然后利用 LLM 评判器的反馈对失败的注入进行改写。
有效的注入十分罕见,据推测它们位于区域中,每种技术对应一个区域。AutoPI 分三个阶段进行搜索, 策略可以跳过、调整大小、重复或重新排序这些阶段:
使用捆绑的 AgentDojo 安装 AutoPI。推荐使用 Python 3.11。
git clone https://github.com/stevendamianakis/autopi
cd autopi
python3.11 -m venv .venv && source .venv/bin/activate
pip install -e . -e benchmarks/agentdojo
将目标和生成器指向一个兼容 OpenAI 的服务器(例如运行在 8000 端口上的 vLLM),并对全部 949 个 AgentDojo 场景运行 Full 策略:
autopi run --benchmark agentdojo \
--target vllm:8000:MODEL_ID \
--refiner vllm:8000:MODEL_ID \
--strategy configs/strategies/full.yaml \
--logdir runs/agentdojo-full
将 --dry-run 添加到检查设置并列出场景,而不调用模型。每次运行都会将其解析后的设置以及每个场景的每次尝试写入 --logdir 文件夹。在代码中,生成器被称为 refiner。
在 configs/models.example.yaml 的副本中为每个模型命名一次,然后传入这些名称。API 密钥从环境变量读取,绝不存储在文件中。
cp configs/models.example.yaml configs/models.local.yaml
autopi run --benchmark agentdojo --models-config configs/models.local.yaml \
--target target --refiner generator \
--strategy configs/strategies/full.yaml --logdir runs/agentdojo-full
提供商包括 openai-compatible(任意 URL)、openai、anthropic、google 和 ollama,并且像 anthropic:MODEL_ID 这样的简短
规格无需文件即可使用。模型配置 涵盖了
解码设置、思考模式以及恢复被服务器端工具解析器移除的文本。
pip install -e benchmarks/ipi_arena
# the 8 browser scenarios also need:
pip install -e 'benchmarks/ipi_arena[browser]' && python -m playwright install chromium
autopi run --benchmark ipiarena --models-config configs/models.local.yaml \
--target arena-target --refiner generator --judge arena-judge --worldsim arena-judge \
--seed-source agentdojo \
--strategy configs/strategies/full.yaml --logdir runs/ipiarena-full
IPI Arena 包含 41 个场景:18 个工具使用、15 个编码和 8 个浏览器场景。只有当某个场景的所有判定标准都通过时,该场景才被视为被攻破,而 --ipi-ignore-concealment 会选择仅基于动作的指标。目标使用原生工具调用,浏览器场景需要具备图像能力的目标。该基准不附带种子,因此请使用 --seed-source agentdojo、--seed-file,或不含种子块的策略。
--mode 3 是默认值,也是论文中的设置,它会向生成器展示用户任务和注入目标。模式 1 和模式 2 编写目标盲模板,模式 2 还会看到用户任务。--no-judge、--no-context 和 --no-legitimize 会分别关闭三种自适应机制之一。--seed-file 使用另一个种子,而 --no-seed 以扫描开始。--taxonomy-path 使用相同文件布局扫描另一个分类体系。--no-early-stop 在首次成功后继续运行,用于覆盖率运行。--shard 和 --num-shards 将一次运行拆分到多个工作进程,而 --resume 会继续被中断的运行。autopi run --help 会列出所有选项。
策略是一个有序的块列表、每个场景的尝试预算以及停止规则。configs/strategies/ 中的三个文件分别是论文中的 AutoPI-Full、AutoPI-Seed-Exploit 和 AutoPI-L1。它们只是示例,并非限制:
| 文件 | 块 | 尝试次数 | 目标 |
|---|---|---|---|
full.yaml | 种子、L1 扫描、每条失败行的 3 个变体 | 529 | 覆盖率 |
seed-exploit.yaml | 种子、种子的 600 个变体 | 601 | 使用强种子的 ASR |
l1.yaml | 种子、L1 扫描 | 133 | 低成本 |
# configs/strategies/full.yaml
version: 1
budget: 529
stop: first_success
blocks:
- kind: seed
- kind: sweep
id: exploration
level: 1
order: priority
- kind: sweep_exploit
source: exploration
reps: 3
块可以被省略、重新排序或重复,并且每次扫描都采用自己的分类子集、顺序、组合层级和限制。参见策略指南。
AutoPI 默认附带 PIAtlas 作为其分类体系:
6 个类别、34 项技术和 131 个命名的子技术,外加一项没有子技术的技术,因此一次
完整扫描共有 132 个单元。任何采用相同 JSON 布局的其他分类体系都可以替换它,而无需更改
代码:通过 --taxonomy-path 传入其文件即可。
日志记录了每一行是为哪个子技术生成的。这是溯源信息,而非注入的标签, 因此不要将其报告为论文的覆盖率指标,该指标是在运行后对成功注入进行标注的。
引擎从不导入基准。适配器为其提供一个名称和两个方法:
class MyBenchmark:
name = "my-benchmark"
def iter_points(self):
"""Yield the scenarios to attack, each with its user task and injection goal."""
def run(self, point, injection_text):
"""Place the injection, run the target once, and return the outcome and the transcript."""
Extending AutoPI 描述了完整的协议和 Python API。
| 路径 | 内容 |
|---|---|
src/autopi/ | 引擎:策略、生成器与评判器提示词、种子、分类体系、模型客户端、适配器以及运行框架 |
configs/ | 策略文件和一个示例模型配置 |
benchmarks/ | AutoPI 运行所基于的 AgentDojo 和 IPI Arena 源码及其许可证。THIRD_PARTY.md 列出了上游修订版本和少量本地改动 |
docs/ | 策略、模型、扩展、发布说明 和 验证 |
tests/ | 引擎的测试 |
examples/ | 一个运行两个基准测试的示例脚本 |
scripts/ | 本地 vLLM 服务器的启动器 |
pip install -e '.[dev,recovery]' -e benchmarks/agentdojo -e 'benchmarks/ipi_arena[dev]'
python -m pytest -q tests
python -m pytest -q benchmarks/agentdojo/tests benchmarks/ipi_arena/tests --import-mode=importlib
GitHub Actions 在 Python 3.10、3.11 和 3.12 上运行这些检查,requirements-tested.txt 保存了本地验证过的包版本。
论文中的实验使用此代码的早期版本以及论文列出的设置运行。使用此版本获得的结果应注明其模型、服务器和解析器版本、策略和设置。该仓库不包含任何模型权重、凭据、服务器地址或实验输出。
@misc{damianakis2026autopi,
title = {{AutoPI}: Taxonomy-Guided Adaptive Red Teaming for Prompt Injection in {LLM} Agents},
author = {Damianakis, Stavros and Psounis, Konstantinos},
year = {2026}
}
AutoPI 依据 MIT 许可证 发布。随附的基准测试保留其各自的 MIT 许可证和版权声明。