ActGuard 是一种针对工具使用型 LLM 智能体中间接提示注入的执行前动作审计防御机制。本仓库包含最终的 ActGuard 实现以及评估所需的基于 AgentDojo 的运行时。
本版本仅包含最终的完整 ActGuard 配置。内部组件仍使用标识符 reflective_audit,以兼容 AgentDojo 基准测试和追踪格式。
meta-llama/Meta-Llama-3.1-8B-Instruct 检查点的访问权限,或等效的本地检查点推荐使用 uv:
uv sync --frozen --extra actguard
或者,安装到已激活的 Python 环境中:
python -m pip install -e '.[actguard]'
在仓库根目录下执行:
export OPENROUTER_API_KEY=...
uv run --frozen --extra actguard ./scripts/run_actguard.sh
如果项目是通过 pip 安装的,请运行:
export OPENROUTER_API_KEY=...
./scripts/run_actguard.sh
该脚本使用 important_instructions 攻击评估 workspace 套件。主智能体和验证器使用 OpenRouter,嵌入检索和对比对数概率归因使用 Hugging Face 兼容的本地模型。在下载默认的受限 Llama 检查点之前,可能需要先进行 Hugging Face 身份验证。
要使用已下载的检查点,请将 scripts/run_actguard.sh 中 --reflective-audit-embedding-model 和 --reflective-audit-logprob-model 的值替换为其本地路径。使用 uv run --frozen actguard-benchmark --help 查看所有基准测试选项。
结果写入以下路径:
runs/openai_gpt-4o-mini-2024-07-18-reflective_audit/actguard/
runs/ 目录已被 Git 忽略。
运行 ActGuard 回归测试:
uv run --frozen pytest -q tests/test_agent_pipeline/test_reflective_audit.py
src/agentdojo/agent_pipeline/reflective_audit.py:ActGuard 实现src/agentdojo/agent_pipeline/agent_pipeline.py:流水线集成src/agentdojo/scripts/benchmark.py:基准测试 CLIsrc/agentdojo/default_suites/:评估套件和任务定义tests/test_agent_pipeline/test_reflective_audit.py:回归测试src/agentdojo/reflective_audit_trace.py:追踪生成与检查运行日志、本地环境、凭据、论文草稿、临时分析输出以及对比防御措施均有意排除在本版本之外。
本项目在 MIT 许可证下分发。它包含一个源自 AgentDojo 的基准测试运行时;有关保留的上游版权声明,请参见 LICENSE。
| 参数 | 设置 |
|---|
| 后端模型 | 通过 OpenRouter 使用 openai/gpt-4o-mini-2024-07-18 |
| 后端模型温度 | 0 |
| 分块长度 | 80--180 个字符 |
| 嵌入模型 | sentence-transformers/all-MiniLM-L6-v2 |
| 检索分块数 | k = 3 |
| 对比对数概率模型 | meta-llama/Meta-Llama-3.1-8B-Instruct |
| 对数概率阈值 | 0 |
| 相似分块分组阈值 | 0.9 |
| 工具结果上下文 | 完整的可审计历史 |
| 验证器模型 | 通过 OpenRouter 使用 openai/gpt-5-mini |
| 验证器温度 | 0 |
| 预测的下一工具集大小 | 1--3 |
| 相邻分块扩展 | 每侧 1 个分块 |
| 每个动作的最大修复尝试次数 | 2 |
| 本地掩码文本 | [Removed suspicious instruction from external tool result.] |