面向任意 SOC Agent 的标准化评测:AiSOC aisoc-benchmark 实战指南
面向任意 SOC Agent 的标准化评测:AiSOC aisoc-benchmark 实战指南
AiSOC 仓库中的 packages/aisoc-benchmark 提供了一套可以跑在任意 SOC Agent 上的评测基线:你只需实现一个 investigate() 方法或暴露一个 HTTP 端点,就能用同一份语料、同一套评分代码得到可比较的数字。本文以该包的 README 为主线,逐层展开适配器协议、评分指标、语料来源标注(provenance)、失败处理,以及从合成语料评分扩展到真实工单回放(replay)评分的实现细节,读完后你可以独立完成"接入自家 Agent → 跑分 → 解读报告 → 判断数字是否可信"的完整闭环。
一、这个基准要解决的问题:自我报告不是基准
README 开篇给出了一句判断标准:
A benchmark a vendor cannot run against their own product is a self-report. This package is the boundary that makes it a standard instead: implement one method, get graded on the same incidents by the same code.
这句话对应一个很现实的结构性问题:如果评测框架只能导入厂商自己的 Agent,那么它产出的数字永远只关于那一个产品;而"只有一个参赛者的排行榜就是一张营销页"。因此该包的设计目标不是"把 AiSOC 自己的 Agent 测得更准",而是把评分器与被测对象解耦。
从源码结构看,这种解耦是物理性的:
- adapter.py 只定义输入/输出数据结构和协议,不导入仓库内任何服务;
- metrics.py 只做纯函数式打分,依赖仅为标准库
re、dataclasses、typing; - runner.py 负责加载语料、并发调度、异常兜底与聚合;
- cli.py 明确写道 "The point of the command is that it does not import AiSOC",它只把语料 POST 到
--agent-url。
包声明见 pyproject.toml:Python >=3.11,唯一运行时依赖是 httpx>=0.27,<0.29,入口点为 aisoc-benchmark = "aisoc_benchmark.cli:main",版本 0.1.0。
二、安装与快速开始
README 中的最小可用流程只有两条命令:
pip install -e packages/aisoc-benchmark # not yet on PyPI; install from source
aisoc-benchmark corpus # what is in the corpus
aisoc-benchmark run --agent-url https://your-agent/investigate \
--agent-name your-product --agent-version 2.1
注意两点事实边界:
- 该包尚未发布到 PyPI,README 明确要求从源码以可编辑模式安装。仓库内也没有
aisoc-benchmark的发布流水线证据,因此不要把pip install aisoc-benchmark当作可用路径。 run子命令的--agent-url是必填项,说明 CLI 路径只支持 HTTP 适配器;进程内直连(自己写asyncio调run_benchmark)需要走 Python API。
CLI 参数完整说明
以下参数表依据 cli.py 的实现整理,包含 README 未展开的默认值:
| 参数 | 适用子命令 | 默认值 | 作用 |
|---|---|---|---|
--agent-url |
run |
必填 | 接收 incident JSON 的 POST 端点 |
--agent-name |
run |
http-agent |
写入报告与 JSON 的 Agent 名 |
--agent-version |
run |
unknown |
写入报告与 JSON 的版本号 |
--corpus |
run / corpus |
corpus/soc-agent-benchmark-v1.json |
语料路径;默认值由包内路径解析得到 |
--header K=V |
run |
空,可重复 | 附加请求头,常用于鉴权 |
--concurrency |
run |
4 |
并发调查数,内部用 asyncio.Semaphore 限流 |
--limit |
run |
None |
只跑前 N 条,用于冒烟测试 |
--json |
run |
关闭 | 输出 JSON 而非人类可读报告 |
--out |
run |
无 | 同时把 JSON 结果写入文件 |
--header 的解析方式是 key, _, value = item.partition("="),且只接受 key 与 value 均非空的对,格式错误的项会被静默跳过而不是报错——这一点在编写 CI 脚本时需要留意(例如 token 为空时请求会退化成无鉴权调用,而不是启动失败)。
对应的完整调用示例:
aisoc-benchmark run \
--agent-url https://your-agent.example.com/investigate \
--agent-name your-product \
--agent-version 2.1 \
--header "Authorization=Bearer $AGENT_TOKEN" \
--concurrency 8 \
--corpus packages/aisoc-benchmark/corpus/soc-agent-benchmark-v1.json \
--json --out /tmp/aisoc-benchmark-result.json
三、适配器协议:一个方法,四个字段进、若干字段出
这是整个包最核心的设计约束。adapter.py 的模块注释把三处"故意不做的事"说得很清楚:
- 不规定工具接口:Agent 怎么拿到证据是它自己的事;
- 不规定 prompt:同上;
- 不给"努力分":调了 40 个工具但结论错误,和瞎猜一样记错。深度(depth)单独报告,因为它解释分数,而不是分数本身。
被规定的只有答案的形状,因为指标依赖它——尤其是必须能区分"自信的错误"与"弃权",以及"引用证据中的指标"与"编造指标"。
输入:BenchmarkIncident
@dataclass(frozen=True)
class BenchmarkIncident:
incident_id: str
title: str
description: str
severity: str
raw_alert: dict[str, Any] = field(default_factory=dict)
telemetry: list[dict[str, Any]] = field(default_factory=list)
def as_dict(self) -> dict[str, Any]:
...
关键点在于 telemetry:它是 Agent 被允许推理的事件集合,"so an agent with no live estate can still be graded — the corpus is the estate"。也就是说,评测不要求你有可连的 SIEM 或数据湖,语料本身就充当环境;同时这也意味着任何被引用却不在 telemetry/title/description/raw_alert 中的指标都会被计为幻觉(见后文)。
输出:AgentVerdict
AgentVerdict 的字段与"每个字段都换来一个指标"一一对应:
| 字段 | 类型 | 默认值 | 参与的指标 |
|---|---|---|---|
disposition |
str |
"unknown" |
处置准确率 |
confidence |
float |
0.0 |
校准度(校准差距 / ECE) |
techniques |
list[str] |
[] |
ATT&CK 召回率、精确率 |
cited_indicators |
list[str] |
[] |
幻觉率 |
proposed_actions |
list[str] |
[] |
遏制准确率 |
narrative |
str |
"" |
不评分,供人复核 |
abstained |
bool |
False |
弃权率(并把该条从准确率分母移除) |
tool_calls / distinct_tools |
int |
0 |
仅报告,不评分 |
latency_ms / tokens / usd_cost |
int/int/float |
0 |
仅报告,不评分 |
from_dict() 的设计值得单独强调:缺失字段一律取默认值,不抛异常。
@classmethod
def from_dict(cls, payload: dict[str, Any]) -> AgentVerdict:
"""Build from a JSON response, tolerating an incomplete one.
Missing fields default rather than raise: an adapter under
development should score badly, not crash the run. A crash is
indistinguishable from a harness bug, and the entrant will assume it
is ours.
"""
这段注释给出了很实用的工程判断:适配器写错时应该"得分难看",而不是"让整轮评测崩掉"——因为崩溃在外部看来和评测框架的 bug 无法区分。同时 disposition 被 .lower() 归一化,techniques 被 .upper() 归一化,所以厂商返回 MALICIOUS、t1059.001 这类大小写不一致的值不会被无谓扣分(行为由 test_benchmark.py 固定)。
进程内实现:二十行的最小适配器
README 给出的示例:
from aisoc_benchmark import AgentVerdict, BenchmarkIncident
class MyAgent:
name = "my-product"
version = "2.1"
async def investigate(self, incident: BenchmarkIncident) -> AgentVerdict:
result = await my_platform.triage(incident.as_dict())
return AgentVerdict(
disposition=result.verdict, # malicious|suspicious|benign|unknown
confidence=result.confidence,
techniques=result.attack_techniques,
cited_indicators=result.indicators, # graded against the evidence
proposed_actions=result.actions,
narrative=result.summary,
)
协议本身是 @runtime_checkable 的 SOCAgent,因此 isinstance(agent, SOCAgent) 可用于运行时自检——test_benchmark.py 就用一个 5 行实现验证了这一点("Twenty lines against a vendor's own API is the bar")。
HTTP 实现:最省事的接入方式
README 的第二条路径是"暴露一个接收 incident JSON、返回同样形状的端点,然后把 --agent-url 指向它"。请求体就是 incident.as_dict():
{
"incident_id": "INC-EVAL-001",
"title": "Spear-phishing email with macro-laden attachment delivered to dave@example.com",
"description": "...",
"severity": "high",
"raw_alert": {"title": "...", "severity": "high", "template_id": "phishing-macro-email"},
"telemetry": [{"source": "m365_audit", "Operation": "Send", "...": "..."}]
}
响应只需是包含 disposition、confidence、techniques、cited_indicators、proposed_actions、narrative、abstained 的子集,缺的字段自动补默认值。HTTPAgent 的内部实现有三个可观察行为(adapter.py):
- 默认超时
timeout_seconds=120.0; - 任何异常(连接失败、HTTP 4xx/5xx、JSON 解析失败)都转换成
AgentVerdict(abstained=True, narrative="adapter error: ..."),而不是抛出; - 若响应不是 JSON 对象(例如返回了数组或纯字符串),同样记为弃权并说明期望类型。
第 2 点有一个重要含义:端点 500 不会中断评测,但会污染你的弃权率。因此在正式跑分前,建议先用 --limit 3 冒烟一次并检查报告里的 abstention rate 是否为 0。
四、测什么:准确率是这里最不重要的数字
README 中" What is measured, and why "一节给出的排序是有价值判断在里面的:
Accuracy is the least interesting number here. Three others are the reason this exists.
1. 幻觉率(Hallucination rate)
定义:Agent 引用的具体指标中,在它被给予的证据里完全不出现的比例。是实测,不是估计。
README 强调了两层理由:
- 一个凭空编造出可信 IP 来支撑结论的 Agent,正在做"分析师替代品"能做的最危险的事,而任何准确率数字都不会暴露它;
- 评分同样覆盖弃权:一边拒绝下结论、一边引用编造地址,依然算编造。
2. 弃权率(Abstention rate)
与准确率并列发布,且准确率只在"已回答"的条目上计算。否则 Agent 可以通过多弃权来抬高分数;而"I do not know"本身是一个正确答案,强制二选一的基准会惩罚它,进而训练 Agent 去猜。
3. 校准差距(Calibration gap)
"答对时的平均置信度"减去"答错时的平均置信度"。接近零意味着置信度不携带任何信息,所有下游基于阈值做门控的逻辑都在对噪声做门控。注意这个差可以是负数——如果 Agent 答错时反而更自信。
4. 其余指标
- 遏制准确率(containment accuracy):与期望动作存在任意重叠即算对。README 解释了为什么不做精确集合匹配:那会变成考核"是否匹配我们的动词表",而不是"是否遏制了事件",而厂商的动词本来就是它自己的。
- 延迟、token、单事件成本:报告,不评分。
- 深度(tool_calls / distinct_tools):报告但明确不评分。"一步得到正确答案的 Agent 不比走了十二步的差。深度解释分数,它不是分数。"
五、评分逻辑的源码级细节
理解实现细节能帮你判断"这个分数为什么是这样",也能避免自己构造语料时踩坑。
哪些字符串才算"可核查指标"
metrics.py 用四条正则判断:
_INDICATOR_PATTERNS = (
re.compile(r"\b(?:\d{1,3}\.){3}\d{1,3}\b"), # IPv4
re.compile(r"\b[a-fA-F0-9]{64}\b"), # SHA-256
re.compile(r"\b[a-fA-F0-9]{40}\b"), # SHA-1
re.compile(r"\b[a-fA-F0-9]{32}\b"), # MD5
re.compile(r"\b[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,}\b"),# 域名
)
也就是说,只有 IP、哈希、域名这三类形状会被核查;"it looked suspicious"、"very bad" 这类自由文本两边都不计入——因为给措辞打分等于在测语言表达。源码注释还记录了一个真实的 bug 修复:早期的域名正则只匹配到 evil.example.com 中的 evil.example,当它只被用作"是不是可核查指标"的布尔判断时不可见,一旦 extract_checkable_indicators 开始返回匹配文本就暴露了出来。
证据如何被展平
def evidence_corpus(incident: Any) -> str:
parts = [
str(getattr(incident, "title", "")),
str(getattr(incident, "description", "")),
repr(getattr(incident, "raw_alert", {})),
repr(getattr(incident, "telemetry", [])),
]
return " ".join(parts).lower()
注意是 repr():字典/列表的键名也会进入证据语料。这带来一个契约要求——telemetry 必须包含完整证据集(build_corpus.py 对此有明确注释),否则真实存在于告警字段中、但没有写进 telemetry 的指标会被误判为幻觉。
单条打分:score_incident
metrics.py 的顺序很关键:
# 幻觉在弃权时也评
for indicator in ...:
if not is_checkable_indicator(text):
continue
score.cited_checkable += 1
if text.lower() not in corpus:
score.hallucinated_indicators.append(text)
if score.abstained:
return score # 弃权:不计算处置/技术/动作
即:先算幻觉,再短路。因此弃权条目的幻觉仍会计入全局幻觉率,但不会进入准确率分母。
技术指标按集合运算:recall = hits / |expected|,precision = hits / |predicted|;期望技术集为空时两者都不计算(保持默认 0.0,aggregate 时也只是把它算进平均,因此构造语料时应保证恶意样本都带 expected_techniques)。遏制判定是 score.containment_correct = bool(expected_actions & proposed),且当 expected_actions 为空时保持 None——"没有期望动作"和"做错了"是两件事,None 不会进入遏制准确率的分母(由 test_benchmark.py 固定)。
聚合:分母的选择决定了激励方向
aggregate() 里几处除法值得逐条看清:
answered = [s for s in scores if not s.abstained]
result.abstention_rate = (len(scores) - len(answered)) / len(scores)
if answered:
result.disposition_accuracy = sum(s.disposition_correct for s in answered) / len(answered)
...
correct = [s.confidence for s in answered if s.disposition_correct]
wrong = [s.confidence for s in answered if not s.disposition_correct]
result.calibration_gap = result.mean_confidence_correct - result.mean_confidence_incorrect
# 幻觉跨全部条目,含弃权
result.indicators_checked = sum(s.cited_checkable for s in scores)
result.hallucination_rate = result.hallucinated_total / result.indicators_checked if result.indicators_checked else 0.0
test_benchmark.py 中的 TestAbstentionCannotBuyAccuracy 正是把这几个不变量钉死:1 条答对 + 1 条弃权 → disposition_accuracy == 1.0 且 abstention_rate == 0.5;全部弃权 → 弃权率 1.0 且报告里必须出现 "abstention rate"。
延迟的分位数用了一个保守的最近秩实现 _percentile:index = min(len-1, int(round(fraction * (len-1)))),空列表返回 0.0。
六、Provenance:拒绝未标注来源的语料
这是 README 中用词最重的一节:
A number computed over synthetic incidents is a synthetic number. A scoreboard that omits that is misleading even when every figure in it is arithmetically correct, and a reader who sees
0.94before they seesynthetichas already formed an impression the caveat will not undo.
合法取值只有四个(runner.py):
| provenance | 含义 |
|---|---|
synthetic |
为本评测生成 |
public-dataset |
CICIDS、AIT-LDS、MITRE Engenuity 等公开数据集 |
real-anonymised |
真实事件,已脱敏 |
adversary-emulation |
Caldera / Atomic Red Team 等对抗模拟输出 |
强制机制有三层,缺一不可:
- 加载即校验:
load_corpus()对每个 incident 读provenance,不在白名单内直接抛CorpusError,且错误信息会解释原因("an unlabelled corpus lets a reader assume otherwise")。 - 随结果传播:
BenchmarkResult.corpus_provenance是结果的一部分,JSON 导出无法把它"忘了"。 - 报告首行呈现:
format_report()的第二行就是Corpus: N incidents (synthetic: 275)这类内容。测试断言report.index("synthetic") < report.index("disposition accuracy")——先看到语料性质,再看到准确率。
另有一个容易被忽略的细节:使用 --limit 截断时,provenance 会按切片重新统计。
kept = {i.incident_id for i in incidents}
provenance = dict(
Counter(r["provenance"] for r in json.loads(...)["incidents"] if r.get("id") in kept)
)
注释说明了原因:"Reporting the full corpus provenance alongside a truncated run overstates what was actually graded, which is the same class of error the labelling exists to prevent."(由 test_limit_recounts_provenance_over_the_slice 固定。)
七、语料:生成而非手工维护
README 指出语料位置与生成方式:
corpus/soc-agent-benchmark-v1.json, generated bybuild_corpus.pyfrom the in-tree eval data rather than hand-maintained — two hand-edited copies of 200 incidents drift within a release, and the published figure then describes a corpus nobody has.
build_corpus.py 的实际构建逻辑是:
- 读取
services/agents/tests/eval_data/synthetic_incidents.json; - 每条打上
provenance: "synthetic",并把raw_alert收敛为{title, severity, template_id}; telemetry原样保留(因为它是幻觉判定的完整证据集);expected_disposition统一置为replay.MALICIOUS(即true_positive);- 把
response_class通过映射表翻译成"厂商可能提出的动作"候选集; - 追加
corpus/benign_cases.py中的良性/误报样本; - 写出带
corpus_id、version、_readme的 JSON。
response_class → 动作动词的映射
RESPONSE_CLASS_ACTIONS: dict[str, list[str]] = {
"block_indicator": ["block_ip", "block_domain", "block_hash", "block_ioc"],
"isolate_host": ["isolate_host", "quarantine_host", "contain_host"],
"disable_account": ["disable_user", "suspend_user", "block_user_signin"],
"reset_credentials": ["reset_password", "revoke_session", "suspend_session", "force_mfa"],
"kill_process": ["kill_process", "terminate_process"],
"quarantine_file": ["quarantine_file", "delete_file"],
"escalate": ["escalate", "create_ticket", "notify"],
"monitor": ["monitor", "no_action", "watchlist"],
}
一个 response_class 对应多个动词,是"任意重叠即算遏制成功"的另一半实现:评分侧只看交集,语料侧尽量把合理的同义词都列上,避免考核命名习惯。
为什么每条 harness 事件都被标为 true_positive
_disposition() 的实现只有一行 return replay.MALICIOUS,但它的 docstring 记录了两次真实错误,非常值得一读:
- 词表错了:语料曾用
malicious | suspicious | benign,而aisoc_benchmark.replay评的是true_positive | benign_true_positive | false_positive | benign——四个标签只重合一个,导致这份语料无法被本包自己的评分器评分,而且没人发现。 - 映射更错:
response_class == "monitor"曾被映射成benign,而那八条是 BloodHound 域枚举、标注 T1087.002、中危——"真实攻击 + 监控响应"不等于"良性事件"。这等于宣称语料有一个良性类而实际没有,于是"对所有事件都答 true_positive"的 Agent 仍能拿 100%。
良性样本:必须"看起来像攻击"
corpus/benign_cases.py 的模块注释定义了合格良性语料的标准:
- 案例必须像攻击:明显的无趣事件只测格式,不测判断。因此每个案例都是"真的触发了检测规则、但正确处置是关闭":变更窗口内 02:00 的 PsExec、部署脚本里的编码 PowerShell、扫描器网段的 Nmap、备份 Agent 的批量读文件。
- 遥测形状必须一致:字段、来源、严重度分布与恶意集相同,模型无法靠格式区分;决定性证据存在于内容中(变更单号、已知服务账号、扫描器自身网段)。
benign与false_positive必须分开:前者是"活动发生了且被授权"(处置是调白名单),后者是"活动并非告警描述的那样"(处置是修规则)。合并成单一的"非恶意"会丢掉动作。
实现上,15 个基础形状(10 个 benign + 5 个 false_positive)各自再展开 4 个变体,只变化主机名、账号、变更单号这类"确实会变化的字段",决定标签的证据永不变化——"a case whose answer moves with its hostname is not the same case"。同时 benign_corpus_records() 会 pop("analyst_rationale"),因为"把答案交给 Agent 的语料测的是阅读理解"。
当前语料的真实构成
我用脚本统计了仓库中已提交的 corpus/soc-agent-benchmark-v1.json:
corpus_id: soc-agent-benchmark-v1 version: 1
incidents: 275
provenance: {"synthetic": 275}
disposition: {"true_positive": 200, "benign": 50, "false_positive": 25}
这里需要与 README 的表述对齐:README 写的是 "The shipped corpus is synthetic: 200",指的是 200 条来自 harness 的恶意事件;当前文件因追加了 75 条良性/误报样本(15 形状 × 5)而共 275 条,provenance 依然全部是 synthetic。这两个数字并不矛盾,但引用时应当说明口径:200 是恶意部分,275 是总量。少数类占比 25/275 ≈ 9.1%,高于 score_replay_set 的 5% 可评分下限。
八、失败处理:崩溃记弃权,时延不采信自报
README 的"Failure handling"一节只有两句,但两句都对应具体实现。
第一句:
An agent that raises, times out or returns nonsense is scored as an abstention with the failure named, never as a wrong answer and never as an exception that ends the run.
runner.py 中的实现:
started = time.monotonic()
try:
verdict = await asyncio.wait_for(agent.investigate(incident), timeout=PER_INCIDENT_TIMEOUT_SECONDS)
except TimeoutError:
verdict = AgentVerdict(abstained=True, narrative=f"agent exceeded {PER_INCIDENT_TIMEOUT_SECONDS:.0f}s")
except Exception as exc:
verdict = AgentVerdict(abstained=True, narrative=f"agent raised {type(exc).__name__}: {exc}")
if not verdict.latency_ms:
verdict.latency_ms = int((time.monotonic() - started) * 1000)
- 单条超时上限
PER_INCIDENT_TIMEOUT_SECONDS = 300.0(5 分钟),保证"一个 Agent 不能挂住整轮评测"; - 并发由
asyncio.Semaphore(max(1, concurrency))控制; asyncio.gather(..., strict=True)保证 incidents 与 ground truth 严格对齐。
需要注意的一个细节:异常与超时都被记为 abstained=True,因此它们会抬高 abstention_rate,但不进入准确率分母。这意味着"接口大面积 500"的表现是"弃权率接近 1、准确率仍是 0",而不是准确率暴跌——读报告时要两个数一起看。
第二句:
Latency is measured by the harness rather than trusted from the agent: it is the one number an entrant has an incentive to shade.
实现即上面那段 if not verdict.latency_ms:Agent 未自报时由 harness 计时;自报时保留自报值(test_a_self_reported_latency_is_kept_when_given 断言了 latency_ms=1234 被原样保留)。所以严格说实现是"缺失时由 harness 补测",而不是"永远覆盖自报值"——引用这条设计意图时应当保持这个精度。
九、报告怎么读
format_report() 输出的结构是固定顺序的(runner.py),可以当作阅读清单:
Agent: your-product 2.1
Corpus: 275 incidents (synthetic: 275)
Accuracy (over answered incidents only — abstaining does not raise it)
disposition accuracy 0.xxx
technique recall 0.xxx
technique precision 0.xxx
containment accuracy 0.xxx
Honesty
abstention rate 0.xxx
hallucination rate 0.xxx (N/M cited indicators absent from the evidence)
calibration gap +0.xxx (confidence when right minus when wrong; ...)
Cost
mean latency ... ms
p95 latency ... ms
total tokens ...
mean USD per incident ...
mean distinct tools ...
三个实用读法:
- 准确率必须与弃权率成对看:
disposition accuracy 0.95配abstention rate 0.60说明它只在容易的 40% 上作答。 - 幻觉率的分母是"可核查引用数":如果
M很小(比如个位数),这个比率本身统计意义有限;一个从不引用具体指标、只写散文的 Agent 会得到 0.0 的幻觉率——这是真实读数,但含义是"没被检查",不是"从不编造"。 - 校准差距为负是明确的坏信号:说明它错的时候比对的更自信。
若需要机器可读结果,用 --json,或 --out 落盘。BenchmarkResult.as_dict() 默认剔除 per_incident("A 200-entry array in every published payload is noise"),需要逐条明细时调用 as_dict(include_per_incident=True)。
十、从合成语料走向真实工单:replay 评分
README 只讲到合成语料这一层,但包里还有 replay.py,它把同一套幻觉判定接到"客户自己的历史工单"上。理解这一层很重要,因为合成语料的类分布是构造出来的,真实队列不是。
复用同一个评分器,而不是写第二个
replay 模块开头明确:幻觉机制直接复用 is_checkable_indicator 与 extract_checkable_indicators,
A second grader would eventually disagree with the first about what "hallucinated" means, and the published numbers would stop being comparable while still looking like they were.
这对使用者是一条硬约束:不要为了"适配我的数据"去改正则,否则你的数字与公开数字不再可比。
三条针对不平衡队列的设计
- 薄语料拒绝给标题准确率:
MIN_MALICIOUS_FOR_HEADLINE = 30。低于 30 条真实恶意样本时,headline_accuracy为None,headline_withheld_reason说明原因——"200 条里 3 条恶意时,把所有东西都叫良性的 Agent 也有 98%"。注意其余指标仍完整输出(恶意召回、混淆矩阵、每类精确率),"拒给一个数字"不等于"什么都不给"。 - 恶意召回优先:这是运营方真正在决策的数字,也是不平衡语料最容易掩盖的数字。报告渲染顺序就是"Recall on malicious"在"Headline accuracy"之前。
- 每个均值都带着它的样本量:两个预测上的 precision 1.00 不等于两百个预测上的 1.00。
"未测"不是"零"
_pct() 的实现把这条写成了代码:
return "not measured" if value is None else f"{value * 100:.1f}%"
理由:精确率列里的 0.0 会被读成"它把这一类全做错了",而"它从未预测过这一类"是另一个事实、另一种补救方式。auto_close_precision、malicious_recall、precision 在无分母时全部为 None 并渲染为 not measured。
补充指标速查
| 字段 | 含义 | 关键实现细节 |
|---|---|---|
malicious_recall |
恶意类召回 | 弃权计为未召回(转人工不等于抓住) |
malicious_recall_ci |
百分位 bootstrap 区间 | 默认 1000 次重采样,种子 20260926;样本 < 5 返回 None |
malicious_recall_wilson |
Wilson 95% 区间 | 闭式解,确定性;在 0/1 处不塌缩为零宽 |
false_negatives / false_negative_rate |
漏掉的攻击数与比例 | 同时给出 false_negative_verdicts:漏的时候它说了什么 |
balanced_accuracy |
各实际存在类的召回均值 | 除以 4 会让两类语料上的完美 Agent 只有 0.5 |
matthews_corrcoef |
多类 MCC | 常量预测器恒为 0.0;无任何行时为 None |
majority_class_accuracy |
常量基线 | 必须与上面两个一起发布 |
auto_close_precision |
置信度 ≥ 阈值时若自动关闭,关对的比例 | 阈值默认 0.9,仅 false_positive/benign/benign_true_positive 可自动关闭 |
escalation_rate |
转人工比例 | 与 abstention_rate 同源,换运营口径命名 |
expected_calibration_error |
10 桶加权校准误差 | 空桶仍输出,以显示"从未表达过该置信区间" |
per_rule / per_source |
按规则、按厂商切片 | 无 rule_id 的归入 unattributed,不丢弃 |
可复现性:只把机器相关的数字排除掉
format_replay_report() 号称"byte for byte"可复现,但延迟是硬件属性。于是 strip_latency() 的存在让这个声明变得精确:
LATENCY_LINE_PREFIX = "- Mean latency:"
LATENCY_LINE_PREFIXES: tuple[str, ...] = (LATENCY_LINE_PREFIX, "- p50:", "- p95:")
def _strip(line: str) -> str:
for prefix in LATENCY_LINE_PREFIXES:
if line.startswith(prefix):
return f"{prefix} excluded from this export (wall clock, not reproducible)"
return line
它按行前缀匹配而不是按单词 "latency" 匹配,因为"未来某个讨论延迟的段落不能被静默删掉";而且是替换而非删除,保证行数不变、diff 指向内容而非偏移。测试 test_two_runs_differing_only_in_latency_are_identical_once_it_is_excluded 在正反两个方向都做了断言。
独立脚本:scripts/score_replay_set.py
仓库还提供了一个门禁式入口,它不只跑分,还会拒绝不可评分的语料:
python3 scripts/score_replay_set.py \
--decisions path/to/decisions.json \
--model your-model-id \
--dataset your-dataset-id \
--commit "$(git rev-parse HEAD)" \
--synthetic
score_replay_set.py 的 assert_gradeable() 有三条硬拒绝:
- 空集合;
- 没有任何
expected_disposition落在GRADED_DISPOSITIONS内("a set without analyst labels can only measure whether the agent answered"); - 只有一个类("对所有事件都答同一标签的 Agent 会拿 100%"),或少数类占比低于
MIN_MINORITY_SHARE = 0.05。
拒绝时以退出码 2 结束并打印 REFUSED — ...;这是抛错而不是警告,理由写得很直接:
A warning in a CI log is read once; a number in
benchmark.mdis read by everyone evaluating this project, and the asymmetry is the whole argument.
一个可直接对照的合格语料样例是 verdict 语料说明:72 条手工构造、36 对"同规则同标题同严重度、只有决定性证据不同"的双胞胎样本,最大类占 50%,最小类 11.1%,36 条恶意满足 30 条标题门槛。
十一、测试如何保证"分数不能被刷"
test_benchmark.py 的模块注释把整份测试的意图总结为"这个基准必须在所有要紧的方向上无法被钻空子",并列出四种"评测框架悄悄送分"的方式:靠弃权抬高准确率、引用不可核查的指标、崩溃被记为答错而非崩溃、自报漂亮的延迟、不说明语料是合成的。对应的测试类正好是这份清单的镜像:
| 测试 | 钉住的不变量 |
|---|---|
TestAbstentionCannotBuyAccuracy |
准确率分母只含已回答条目;弃权率必须出现在报告中 |
TestHallucination |
编造的 IP 被抓;证据内指标不被误判;不可核查断言两边都不计;弃权时的幻觉照样计;零引用返回 0.0 而不是除零 |
TestCalibration |
自信地答错 → 差距为负;良好校准 → 差距为正 |
TestContainment |
任一动作重叠即算对;无期望动作时为 None 而非 False |
TestProvenance |
未标注/伪造 provenance 被拒;provenance 随结果传播;报告里 synthetic 出现在 accuracy 之前 |
TestRunnerRobustness |
抛异常的 Agent → 弃权率 1.0;--limit 不虚报条数 |
TestHTTPAdapter |
不可达端点 → 带原因的弃权;部分响应取默认值;techniques 大写归一 |
test_corpus_can_grade.py 则是"语料能否区分 Agent"的元测试,用四个参照 Agent 固定分数:
- 全答
true_positive→ 标题准确率 ≈ 0.727(曾经是 1.000),恶意召回 1.0,恶意精确率 ≈ 0.727; - 全答
benign→ ≈ 0.182,恶意召回 0.0; - 完美 Agent → 1.0;
- 随机猜 → 落在 0.3~0.9 之间。
它还断言语料中不出现可路由地址(只允许 RFC 5737 文档段与私有段),因为"a corpus that shipped a routable address would eventually have somebody scan it"。
十二、使用边界与落地建议
基于以上实现,可以给出几条明确的使用前提:
- 不是 AoB(排行榜)而是评分器。仓库里没有托管式公开榜单的证据;你得到的是本地算出的、带 provenance 的结构化结果,比较两个 Agent 的前提是语料、
concurrency之外的一切参数一致。 - 四个
disposition词表要选对。合成语料路径用malicious | suspicious | benign | unknown(见AgentVerdict.disposition注释),而 replay 路径用true_positive | benign_true_positive | false_positive | benign。两者不通用——这正是build_corpus.pydocstring 里记录过的坑。 - HTTP 接入要监控弃权率,因为连接失败与超时都会静默转为弃权。
--limit只适合冒烟:它会重算 provenance,但样本量小到一定程度后,准确率与校准差距都失去意义;replay 路径更是直接在恶意样本 < 30 时拒绝输出标题准确率。- 不要手改语料。CI 会在
--check模式下重跑build_corpus.py并用git diff --exit-code拒绝与生成脚本不一致的提交;同时scripts/sync_vendored_benchmark.py --check会双向校验 services/api/app/_vendor/aisoc_benchmark 这份镜像是否与源码一致。
十三、小结
aisoc-benchmark 的技术价值不在"又一个跑分脚本",而在于它把评测中所有容易被悄悄放宽的地方都做成了硬约束:协议只约束答案形状、不约束实现架构,使非 AiSOC 的 Agent 也能参赛;准确率的分母排除弃权,使"我不知道"不被惩罚、也不被利用;幻觉率通过可核查指标的正则与证据展平实测;provenance 白名单让"合成数字"无法伪装成真实成绩;replay 层用 30 条恶意样本门槛、balanced accuracy、MCC 与常量基线,让不平衡队列上的高准确率不再自动等于好 Agent。
如果你要接入自己的产品,最短路径就是三步:实现 investigate() 或用 --agent-url 暴露端点 → --limit 3 冒烟确认弃权率为 0 → 全量跑一次并同时读准确率、弃权率、幻觉率、校准差距四个数。任何只引用其中一个数的结论,都不足以支撑"这个 Agent 可以替代分析师"的判断。