← 返回 2026-05-14

AgentLens: 揭示软件工程智能体评估中的"幸运通过"问题 AgentLens: Revealing The Lucky Pass Problem in SWE-Agent Evaluation

Priyam Sahoo, Gaurav Mittal, Xiaomin Li, Shengjie Ma, Benjamin Steenhoek, Pingping Lin, Yu Hu 📅 2026-05-13 👍 3 2026-07-13 08:36
Prefix Tree Acceptor SWE Agent评估 意图阶段分类 数据标注 过程质量度量

提出AgentLens框架,用PTA参考和意图标注揭示10.7%的SWE-bench通过实为弱过程

前置知识

SWE-bench Verified

由OpenAI和SWE-bench团队合作发布的500个人工验证过的GitHub issue任务集,用于评估AI agent能否自动修复真实Python项目中的bug。任务结果用'patch是否通过所有FAIL_TO_PASS测试'这一个二元信号判断。

本文所有实验都基于SWE-bench Verified,是当前SWE agent评估的事实标准,读者需要理解它只关心最终patch是否过测,不关心agent怎么到达答案

Prefix Tree Acceptor (PTA)

有限状态自动机的一种特殊形式,原始用于语音识别中的词序列接受。本文借用它把同一个任务的k条成功轨迹按前缀合并:共享前缀汇聚到同一节点,分叉处形成DAG分支,每条从根到叶的路径代表一种已知正确的解题策略。

PTA是AGENTLENS的'参考解空间',没有它就只能用单一参考轨迹去比,无法容纳'同一题多种正确解法'的现实

Intent-stage labeling (E/I/V/O)

把agent每一步标注为四个认知阶段之一:Exploration(读文件/grep/ls)、Implementation(编辑源码)、Verification(跑测试/读已编辑文件)、Orchestration(思考/记账)。关键是不能只看工具名,要结合'是否已经改过文件'等轨迹历史。

如果只看工具身份,70-80%的终端命令会塌缩到同一类,时序信号就废了;本文的Fleiss κ=0.933就来自这种context-sensitive标签器

过程奖励模型 (Process Reward Model)

在最终结果奖励之外,为推理/执行的中间步骤单独打分的模型,常用于RLHF和RL fine-tuning,代表工作有Math-Shepherd、PRM800K。

本文和PRM思路相通——都认为'中间步骤信号'和'最终对错'不同——但AGENTLENS是deterministic规则打分,不需要训练reward model

研究动机

SWE-bench只用'最终patch是否过测'这一个二元信号评估agent能力,但这条信号把'精准定位根因、最小修改、跑测试验证'的agent和'反复试错、偶然蒙对'的agent当成一样。具体数据:1136条passing中122条(10.7%)属于Lucky Pass——含regression cycle、blind retry、缺验证、时序错乱;122条里发生blind retry时每次浪费11.4步,而Ideal只浪费2.7步(4.2×差距);整个122条Lucky Pass消耗约5830万token,如都用C1效率只需410万,浪费93% token只换来和Ideal完全相同的binary pass。这种'过程差但结果同'的现象在SWE-Gym、R2E-Gym等数据集做SFT/RL训练时会被pass-rate filter无差别收录,把'蒙对的弱过程'当成和'正确示范'等价的监督信号。

本文的目标是构建过程级SWE agent轨迹评估框架AGENTLENS,对每条passing轨迹给出0-100分并配套发布AGENTLENS-Bench。具体目标:(1) 把1136条passing分成Ideal (229, 20.2%) / Solid (785, 69.1%) / Lucky (122, 10.7%) 三档;(2) 把Lucky Pass分解为可解释的弱过程类别;(3) 提供可比、可复现、不依赖LLM调用的打分管线,并展示process-aware ranking和pass-rate ranking不一致。

与已有工作不同的是,已有过程评估工作各有缺陷:Graphectory独立于任务结果计算图度量但只用单条参考;AgentBoard按sub-goal给分但粒度不够;SWE-RM给标量但没分类;ABC做checklist但无trajectory;MAST在multi-agent场景下κ=0.88低于本工作。AGENTLENS的独特切入是把同一任务所有passing轨迹用PTA合并成DAG参考空间,配合context-sensitive intent labeler把每步分到E/I/V/O,用4个互补信号加权得到deterministic分。

核心方法

AGENTLENS把原始agent log先解析成带'工具/目标文件/行号/内容hash/轨迹位置'的state序列,再用7条规则context-sensitive labeler把每个state打上E/I/V/O四个意图阶段标签;然后把同一任务≥2条passing轨迹用Prefix Tree Acceptor合并成task-level DAG参考图;最后用4个互补信号加权求和得到0-100分。直觉上:'有没有去到对的代码区域'和'是不是以合理顺序经过这些区域'是两个互补问题,前者由结构信号回答($\Phi_{struct}+\Phi_{cov}$,合计权重0.35),后者由行为信号回答($\Phi_{coh}+\Phi_{temp}$,合计权重0.65),分高为Ideal、中为Solid、低为Lucky。

和已有方法最本质的区别是两点:(1) 参考空间用PTA而不是单条gold trace,PTA把同一任务不同agent走出的多条合法路径合并成DAG,共享前缀合并、真实分叉保留为分支,从而既容忍多样化解法又能定位'分叉点';(2) intent labeler是context-sensitive而不是tool-identity-only,例如'实现步骤之后回看test_api.py'算Verification而不是Exploration,'在编辑之前用grep搜'仍算Exploration——靠跟踪'是否已发生source edit'和'目标文件是否已被改过'。这两点合起来使打分完全deterministic(无需LLM调用),并能给出分叉定位和五类浪费归因。

方法步骤详情

管线分四步。Step 1 解析日志:提取(tool, target_file, line_range, content_hash)组成state序列。Step 2 意图标注:7条规则cascade,前4条按工具类型分固定标签(search→E、validation→V、edit→I、orchestration→O),后3条结合context修正。Step 3 构建PTA:同任务k条passing按4级equivalence cascade合并成DAG。Step 4 综合分:$f = 0.20 \cdot \Phi_{struct} + 0.15 \cdot \Phi_{cov} + 0.30 \cdot (100 \cdot \Phi_{coh}) + 0.35 \cdot (100 \cdot \Phi_{temp})$,$\Phi_{coh}$用pivot/backtrack/retry比例,$\Phi_{temp}$用三段阶段分布和PTA做JSD。Step 5 输出tier(≥70 Ideal / 47-70 Solid / <47 Lucky)+ 五类浪费。

技术新颖性

新颖性体现在三个层面。算法层:首次在SWE agent评估中引入'多轨迹合并PTA参考',相比单条gold trace能表达$\binom{k}{2}$级别解空间;state equivalence用4级confidence cascade(content hash 1.0 → tree-sitter AST 0.9 → ≥30% line overlap 0.80-0.95 → semantic terminal 0.70-0.85)处理异构工具集,不需LLM fallback。系统层:context-sensitive 7-rule labeler解决'工具同名不同阶段'歧义,7标注者达成Fleiss κ=0.933、raw 96.0%,heuristic 93.8% acc / macro-F1 0.933。评测层:首次把'Lucky Pass'作为可量化现象系统揭示(10.7% prevalence,46×模型间差距),给出五类机制分解和模型×类别$\chi^2(28)=102.47$、$p<0.0001$的强关联证据。

AGENTLENS workflow.
Figure 2: AGENTLENS workflow.
PTA construction.
Figure 3: PTA construction.
Intent-stage classification decision tree.
Figure 4: Intent-stage classification decision tree.
Scoring signal examples.
Figure 5: Scoring signal examples.

实验结果

在2614条OpenHands轨迹、60个SWE-bench Verified任务中,47个任务有≥2条passing,得到1815条子集(1136 pass + 679 fail)。(1) 异质性:1136条passing中229条(20.2%)Ideal、785条(69.1%)Solid、122条(10.7%)Lucky Pass。(2) Lucky Pass分5类:C2 Brute-Force 42 (34.4%)、C3 Incomplete 41 (33.6%)、C1 Minimal 19 (15.6%)、C5 Divergent 15 (12.3%)、C4 Excessive 5 (4.1%)。(3) blind retry每实例步数:Lucky 11.4步vs Ideal 2.7步(4.2×)。(4) 模型Lucky率46×跨度(0.5%-23.2%)。(5) 8模型QS rank与PR rank全部不一致。(6) 综合分AUROC=0.766、KS p=0.0017;4单独信号p≥0.196。(7) 标签Fleiss κ=0.933。

Lucky Pass taxonomy.
Table 1: Lucky Pass taxonomy.
Frontier model comparison.
Table 2: Frontier model comparison.
Per-signal AUROC.
Table 3: Per-signal AUROC.
Framework comparison.
Table 5: Framework comparison.
Tool registry (abbreviated).
Table 6: Tool registry (abbreviated).
Behavioral profiles among passing trajectories.
Table 7: Behavioral profiles among passing trajectories.
Waste prevalence and per-instance step cost: passing (P) versus failing (F).
Table 8: Waste prevalence and per-instance step cost: passing (P) versus failing (F).
Inter-annotator agreement on intent-stage labels (200 states, 7 annotators).
Table 10: Inter-annotator agreement on intent-stage labels (200 states, 7 annotators).
Heuristic classifier versus annotator consensus (192/200 states with ≥67% agreement).
Table 11: Heuristic classifier versus annotator consensus (192/200 states with ≥67% agreement).
Baseline comparison on the full 1,815-trajectory evaluation set.
Table 12: Baseline comparison on the full 1,815-trajectory evaluation set.
Waste metrics by Lucky Pass category.
Table 13: Waste metrics by Lucky Pass category.
Lucky Pass categories by model.
Table 14: Lucky Pass categories by model.
Tasks with highest Lucky Pass concentration.
Table 15: Tasks with highest Lucky Pass concentration.
Five passing trajectories for the same SWE-bench task (psf__requests-1724).
Table 16: Five passing trajectories for the same SWE-bench task (psf__requests-1724).
Verification stage coverage by Lucky Pass category.
Table 17: Verification stage coverage by Lucky Pass category.
Signal ablation on the pilot calibration set (n = 278).
Table 18: Signal ablation on the pilot calibration set (n = 278).
Merge-count sensitivity on the pilot set (3 resamples per k per eligible task).
Table 19: Merge-count sensitivity on the pilot set (3 resamples per k per eligible task).
Merge-order study: per-combination AUROC across all 6 permutations (k = 4, astropy__astropy-12907, 60 total runs).
Table 20: Merge-order study: per-combination AUROC across all 6 permutations (k = 4, astropy__astropy-12907, 60 total runs).
Token cost by Lucky Pass category.
Table 21: Token cost by Lucky Pass category.
Association tests for the Lucky Pass taxonomy.
Table 22: Association tests for the Lucky Pass taxonomy.
Passing trajectories are not behaviorally homogeneous.
Figure 1: Passing trajectories are not behaviorally homogeneous.
Failure-mode gallery.
Figure 6: Failure-mode gallery.
Score Density by Outcome.
Figure 7: Score Density by Outcome.
Pass Rate vs. Mean Quality Score.
Figure 8: Pass Rate vs. Mean Quality Score.
Lucky Pass category distribution.
Figure 10: Lucky Pass category distribution.
查看结构化数据
任务指标本文基线提升
Pass/Fail trajectory separation AUROC 0.766 (AGENTLENS, 4-signal composite) 0.805 (Individual match) / 0.701 (Dense embed) / 0.672 (TF-IDF) 比TF-IDF/Dense embed高0.065-0.094;比Individual match低0.039但同时给出divergence定位+五类浪费归因
Pass/Fail separation (pilot, 278 trajectories) AUROC / F1 0.755 / 0.791 (full combined score) 0.739 / 0.731 / 0.724 / 0.718 (ablation去掉单一信号) 行为信号($\Phi_{coh}$、$\Phi_{temp}$)ablation drop 0.031-0.037,结构drop 0.016-0.024,行为维度更重要
Intent-stage labeling Fleiss κ / 7-annotator agreement 0.933 / 96.0% raw agreement (200 states) MAST协议 κ=0.88 in multi-agent 比MAST高0.053;E vs V歧义最强boundary仍达0.939;Orchestration类别全一致(κ=1.0)
Lucky Pass rate estimation (8 models) Share of passing flagged as Lucky 0.5% (Opus 4.5) – 23.2% (GPT-4.1), 46× spread Pass rate alone: 34.9% (GPT-4o) – 87.9% (Opus 4.5) Opus 4.6的77.3% pass掩盖了18.7% Lucky率;pass rate无法显示这种内部异质性
Model ranking consistency Rank position change |PR − QS| GPT-4o: +5位(8→3); GPT-5.2-Codex: −3位(4→7); 8模型全部不一致 Pass rate ranking (binary outcome only) 展示过程质量是独立于结果的'轴',可用于在pass rate趋同的frontier模型间做区分
Waste signal discrimination (Pass vs Fail) Prevalence ratio F/P and per-instance cost Unnecessary exploration F/P=1.58; Cyclic F/P=1.32; cyclic cost 7.8 vs 4.6 steps Regression F/P=1.02, Blind retry 0.98, Redundant 0.94(不区分) 5类浪费中2类(unnecessary exploration和cyclic)在fail组显著富集,可作为fail预测特征

局限与改进

作者承认的局限:(1) Scope仅OpenHands+SWEBench-Verified,推广到AutoCodeRover/Devin需ATIF trace adapter;(2) PTA构建要求每个任务≥2条passing,60个任务中13个(21.7%)被排除;(3) 权重$(0.20, 0.15, 0.30, 0.35)$在pilot grid search得到且固定,不同部署场景(看重验证vs探索效率)可能需重新校准;(4) 94.3% Lucky Pass缺验证但仍有12.3%来自'任务本身允许多解'(C5),结构性差异靠扩PTA只能部分缓解。我自己的观察:(a) 标签器在'实现后read_file'有E/V歧义,heuristic保守选E可能影响tier边界精度;(b) C4仅5例且全来自GPT-4.1,统计不可靠;(c) AUROC=0.766不算高,分数只是过程相似度proxy不能替代语义判断;(d) composite score和pass率相关性未显式报告,可能存在confound。

独立分析的弱点

(1) PTA对'未被任何passing覆盖的合法策略'有偏——C5 Divergent-but-Valid(15条,12.3%)即此类,GPT-5.2-Codex在sphinx-10323上走了不同filter重排序路线,过程完整E→I→V→O但score仅37。改进:k从5升到10或加sampling-based ensemble,并引入人类专家解法作第三个参考来源。(2) 规则系统对未覆盖工具会fallback到Exploration可能错分。改进:升级为learned model用现有93.8% acc heuristic产出弱监督样本做distill。(3) 静态tier阈值(70/47)在不同任务难度上区分度不一致。改进:按task difficulty prior做per-task校准。(4) 5类浪费中regression和blind retry的prevalence在pass/fail两组相近(38.7% vs 39.5%),区分靠per-instance cost,监控易漏报。改进:标准化为per-trajectory expected waste。

未来方向

作者方向:(1) 把quality score当dense reward做RL fine-tuning,鼓励'low-waste+coherent'过程;(2) 按process quality组织curriculum——先学Ideal再引入Solid,把Lucky当反例;(3) longitudinal tracking,对同模型不同版本看pass rate提升是来自'cleaner reasoning'还是'broader exploration'还是'increased retry';(4) 推广到WebArena和OSWorld。可延伸:(a) 把5类Lucky Pass和RL算法绑定——C1加'edit-then-test'约束、C2加'plan-then-act' decoding、C3加'edge-case test generation';(b) 把PTA节点当state abstraction做hierarchical RL;(c) 探索'过程质量'作为self-distillation teacher signal的潜力。

复现评估

可复现性总体良好。(1) 数据:作者声明将开源AGENTLENS-Bench(1815条轨迹、47个ground-truth PTA、五类浪费标注、tier labels)、SDK和web interface,但本文提交时仓库尚未放出。(2) 算力:scoring pipeline CPU-only,作者用11核18GB机器,不依赖GPU;轨迹生成用外部model API和pipeline解耦。(3) Determinism:所有计算不需LLM调用(state equivalence的LLM fallback明确disabled),grid search权重$(0.20, 0.15, 0.30, 0.35)$在pilot 278轨迹上固定,threshold 70/47和Youden-J=46.4都frozen。(4) 跨agent兼容:支持标准ATIF JSON log,其他agent只需lightweight trace adapter。(5) k=5在pilot上AUROC=0.777±0.220标准差较大,merge-order在8/10组合order-invariant。