llm-as-a-verifier/llm-as-a-verifier
LLM-as-a-Verifier is a general-purpose framework that provides fine-grained feedback for any agent without requiring additional training. It achieves SOTA performance across coding, robotics, and medical agentic benchmarks.
llm-as-a-verifier
是什么 – 一个将大语言模型(LLM)转化为 AI 代理输出验证器的 Python 库。它对候选代理轨迹(代码、命令、机器人动作等)进行细粒度、概率性奖励评分,可选择 best-of-N 候选者,逐步追踪进展,或执行大规模基准测试评估。
核心思想
- 细粒度奖励 – 不是单一的二元判断,而是对一组评分令牌(1–20 或 A–T)的完整对数概率分布进行期望计算。这产生一个 [0,1] 区间内的连续奖励,反映置信度。
- 重复评估与标准分解 – 同一轨迹可在多个用户提供的标准下(如正确性、根本原因分析)多次评估。结果取平均以降低方差。
- 概率性枢轴锦标赛(PPT) – 一种 O(N k) 算法,仅将每个候选者与少量“枢轴”候选者比较,即可对 N 个候选轨迹排序,相比完整成对循环赛,大幅减少 LLM 调用次数。
- 前缀缓存优化 – 验证提示被结构化,使得大而通用的前缀(任务描述 + 两个轨迹)可由 LLM 后端缓存,将未缓存输入令牌减少约 3.4 倍。
- 多模态支持 – 可在任意验证调用中附加图像输入,支持视觉机器人执行或前后截图的验证。
安装
pip install llm-verifier # 从 PyPI 获取稳定版本
# 或从源码安装最新代码
pip install -e .
需要一个能返回对数概率的模型的 API 密钥(例如 DeepSeek‑V4‑Flash、Gemini 2.5‑Flash,或本地 vLLM 服务器)。
快速入门示例
import llm_verifier
problem = "Write a function that reverses a string."
candidates = [
"def rev(s): return s[::-1]",
"def rev(s): return s",
"def rev(s): return ''.join(sorted(s))",
]
# 使用验证器选择最佳候选者
result = llm_verifier.select(
problem=problem,
candidates=candidates,
criteria={"Correctness": "Does the code actually reverse the string?"},
)
print(result.index) # → 0(正确实现)
print(result.scores) # 各候选者得分
其他入口点:
llm_verifier.compare– 返回成对比较的原始细粒度奖励。llm_verifier.track– 在每一步对已完成的轨迹进行评分,生成进度曲线。ProgressTracker– 一种在线版本,可在执行过程中逐步输入。
基准测试与结果 该库附带多个代理基准测试(Terminal‑Bench、SWE‑Bench Verified、MedAgentBench、RoboRewardBench)的可复现脚本。使用 Gemini 2.5‑Flash 作为验证器时,报告的 Pass@1 分数超过原始基线:
| 基准测试 | 基线模型 | LLM‑as‑Verifier | Oracle |
|---|---|---|---|
| Terminal‑Bench V2 (best‑of‑5) | GPT‑5.5 | 86.5 % | 92.1 % |
| SWE‑Bench Verified (best‑of‑3) | Opus 4.5/4.6 | 78.2 % | 84.4 % |
| MedAgentBench (best‑of‑5) | Claude Opus 4.8 | 73.3 % | 75.0 % |
自我验证(同一模型同时生成和验证)在 Terminal‑Bench 2.1 上也优于原始 Pass@1 分数。
内部工作原理
fine_grained_reward.py实现对数概率的期望。pivot_tournament.py包含 PPT 算法。progress.py提供每步评分工具。benchmarks.py注册每个基准测试,并从data/加载对应的代理轨迹。- 缓存存储在
cache/;结果保存在results/。
扩展至自定义任务
- 将代理轨迹放在
data/<task_name>_trajs/下。 - 复制
criteria/TEMPLATE.md到新文件(如criteria/mytask.md),编写你关心的评估标准。 - 使用
llm_verifier.select并传入problem、candidates和criteria=your_criteria_file;或使用 Claude Code 插件(TurboAgent)让 Claude 自动生成标准并自动调用验证器。
Claude Code 插件(TurboAgent) 一个即插即用的代理,可让 Claude Code 自动调用验证器,生成多个候选补全并使用 PPT 选择最佳者。安装方式:
pip install git+https://github.com/llm-as-a-verifier/TurboAgent
然后启动代理(turbo-agent),并将 Claude Code 指向 http://localhost:8888。
资源
- 文档: https://llm-as-a-verifier.com/docs/
- 网站: https://llm-as-a-verifier.com
- 论文(arXiv): https://arxiv.org/abs/2607.05391
- Slack 社区、Twitter/X,以及 TurboAgent 仓库(用于 Claude Code 集成)。
引用 若在研究中使用该框架,请引用 README 中提供的 arXiv 论文。
写过它的文章
相关
- 项目
- 项目
- 项目
- 项目
- 项目