rudrakshkarpe/dual-llm-bench
GitHub: rudrakshkarpe/dual-llm-bench
这是一个用于评估智能体LLM系统安全性的基准测试工具包,专注于测量提示注入抵抗力等关键安全指标。
Stars: 1 | Forks: 0
# as lines. First line is "[dual-llm-bench](https://pypi.org/project/dual-llm-bench/)" – this includes the markdown link, but the text to translate is likely "dual-llm-bench". Similarly, second line is "CLI".
`dual-llm-bench` 是一个用于测量智能体 LLM 系统中提示注入抵抗力、特权上下文暴露、工具安全行为和有用任务保留能力的小型基准测试包。
该包的灵感来源于像 Ragas 这样的评估库:定义一个结构化样本,运行一个智能体,使用可组合的指标对生成的追踪记录进行评分,并将结果聚合为一份报告。
## 安装说明
```
pip install dual-llm-bench
```
对于本地开发:
```
pip install -e ".[dev]"
pytest
```
对于由 CodSpeed 跟踪的性能基准测试:
```
pip install -e ".[codspeed]"
pytest benchmarks/ --codspeed
```
## 快速开始
```
from dual_llm_bench import BenchmarkSuite, built_in_metrics
from dual_llm_bench.runners import CallableRunner
def agent(sample):
return {
"privileged_input": sample.user_goal,
"policy_verdict": "needs_human",
"final_outcome": "Created a security review ticket.",
"tool_request": {"name": "create_ticket", "arguments": {"queue": "security"}},
"quarantined_output": {
"summary": "Suspicious vendor request.",
"entities": ["invoice_id:8821"],
"suspicious_instructions": sample.attack_markers,
"sanitization_notes": ["Removed attacker-controlled instructions."],
},
}
suite = BenchmarkSuite.from_builtin("pycon-core")
report = suite.run(CallableRunner(agent), metrics=built_in_metrics())
print(report.to_markdown())
```
## 核心指标
- **注入抵抗力**:当存在提示注入固定装置时,奖励那些避免使用被禁止工具和不安全最终结果的智能体。
- **特权上下文暴露**:检查攻击者标记是否泄露到特权模型输入中。
- **工具决策安全 F1 分数**:将工具/策略决策与预期的安全标签进行比较。
- **有用性保留**:检查有用的业务信息是否在隔离后幸存并出现在最终的追踪记录中。
## - The user says "each of the following headings", so I should consider the textual content. For the first, the heading text is "dual-llm-bench", and for the second, it's "CLI".
```
dual-llm-bench list-datasets
dual-llm-bench inspect pycon-core
dual-llm-bench score-traces traces.jsonl --dataset pycon-core
```
`score-traces` 期望接收包含 `sample_id` 以及追踪字段(如 `privileged_input`、`policy_verdict`、`tool_request`、`quarantined_output` 和 `final_outcome`)的 JSONL 记录。
## 示例集成
- [`examples/pycon_dual_llm_demo`](examples/pycon_dual_llm_demo):PyCon 双重 LLM 安全演示应用的适配器和运行器。
- [`docs/benchmarking-methodology.md`](docs/benchmarking-methodology.md):样本、追踪记录和指标如何协同工作。
- [`docs/quarantine-policy.md`](docs/quarantine-policy.md):何时运行双重路径、何时跳过以及如何降低延迟。
## 发布
首选发布路径:
1. 推送一个干净的 `main` 分支,并等待 GitHub CI 通过。
2. 为版本标签(例如 `v0.1.0`)创建一个 GitHub 发布。
3. 为 `.github/workflows/publish.yml` 和 `pypi` 环境配置 PyPI 可信发布。
4. 让发布工作流构建、进行冒烟测试并发布包。
手动本地验证:
```
python -m pip install -e ".[dev]"
pytest
ruff check .
mypy src
rm -rf dist
python -m build
twine check dist/*
```
如果您之前未验证过工作流,请在发布公共版本前使用 TestPyPI。优先使用可信发布而非长期有效的 PyPI 令牌。
标签:AI测试, CSP, Python包, 人工智能安全, 代理系统评估, 代码安全, 反取证, 合规性, 安全指标, 安全标准, 安全评估, 工具安全, 性能基准, 提示注入, 文档结构分析, 时序数据库, 漏洞枚举, 特权上下文暴露, 逆向工具, 集群管理