best-of-n
它能做什么
这个技能让 AI 为一项重要任务生成若干候选方案,用相同的评分标准打分,并在验证后使用最佳方案。适合高风险或含糊不清、值得花费额外精力比较选项的决策。
适用场景
- ✓当某个设计或实现有多种可行方案需要比较的时候。
- ✓当某个调试或解释任务风险较高,值得检查多个答案的时候。
- ✓当你希望在选择方案前应用清晰的评分标准的时候。
技能链接
https://github.com/codewhale-hq/Codewhale/blob/main/crates/skills/assets/skills/best-of-n/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请用三种不同的方式设计这个缓存层,为它们打分,并且只在通过测试后应用最好的一个?”
每周 5 个新技能,1 分钟读完。
工作原理
AI 用相同的任务和评分标准启动若干独立候选方案,收集结果并进行评判,只有在验证通过后才应用获胜的方案。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Best of N
Use this skill when a consequential design, implementation, explanation, or debugging task has several plausible solutions and comparison is worth the extra model work. In Operate mode this is the preferred ensemble pattern for high-stakes or ambiguous approaches. Do not use it for a tiny change or when the user has already chosen the approach.
Set The Tournament
- Define one task, one evidence packet, and one explicit scoring rubric before launching candidates. Include correctness, fit to the request, simplicity, risk, and verification.
- Choose
Nfrom 2 to 4 for a quick comparison (default 3). For an explicit experimental search, use the Workflow search option: 2–16 live candidates, with larger validated populations queued at the Workflow host's 16-worker concurrency gate rather than launched at once. - Give every candidate the same task and rubric. Add only a candidate number; do not steer candidates toward different conclusions unless diversity is an explicit part of the request.
- Prefer a session goal (
create_goalor active/goal) when the tournament spans more than one parent turn.
Generate Independently
Start the candidates as parallel background agent workers and return agent_ids
immediately so the parent stays free. For proposals, reviews, or research, keep
them read-only:
{
"action": "start",
"name": "candidate_1",
"prompt": "Produce candidate 1 for the task below. Return the proposal, evidence, risks, and rubric self-score. Do not edit files.\n\n<TASK AND RUBRIC>",
"type": "worker",
"model_strength": "same",
"write_authority": "read_only"
}
Launch the remaining candidates with the same contract, then use agent wait
or completion events to collect every result. Do not show one candidate another
candidate's answer before generation finishes.
When candidates must implement code, give each one:
type: "builder"worktree: truewrite_authority: "worktree_write"- the same bounded
write_rootsorexact_files
Never run parallel writers in the parent checkout. Each builder must return the structured candidate contract (candidate id, hypothesis, paths, commands, self-verdict, risks, and artifact references). A self-verdict is evidence to inspect, not a hard-gate result.
Optional diversity: pin different model / Fleet fleet_profile values when
the project has multiple capable routes; otherwise keep model strength same.
Judge Once
Use one read-only reviewer worker, or the parent when the result is small, to score all candidates against the original rubric. The judge must:
- cite evidence from each candidate rather than vote by style;
- reject candidates that violate authority, scope, or verification gates;
- treat candidate-reported commands and PASS claims as untrusted until replay;
- name the winner and the decisive reasons;
- identify useful pieces worth combining, if any;
- say when the candidates are tied or all fail.
Do not ask candidates to vote for themselves. Do not silently merge incompatible approaches into a new unreviewed solution.
Integrate Only After PASS
For proposal-only work, return the winning answer with a compact score summary. For code work:
- Freeze the baseline, evaluator, hard gates, score rule, and authority before a larger search admits candidates. Any evaluator change starts a revision.
- After a worker loses write authority, apply its patch to a clean baseline and let the runtime—not that worker—run hard gates and scoring.
- Inspect the winning worktree diff and independently replay it on the clean baseline. A different read-only model may look for gaming, but deterministic tests remain the authority.
- Present the verified winner for review. Applying or merging is a separate,
explicit user action;
NONEis valid when every candidate fails. - Preserve losing and failed candidate receipts as useful negative results.
The checked-in operate_best_of_n.workflow.js recipe supports
strategy: "search" for structured 2–16 candidate generation and review. It
does not yet turn prompt-listed commands into hidden runtime gates. Do not
advertise those gates until a runtime evaluator host consumes a frozen search
spec.
Stop early when one candidate reveals a hard constraint that invalidates the tournament. Report the negative result rather than spending the remaining budget to manufacture variety.
常见问题
会使用多少个候选方案?
默认是三个,技能允许两到四个用于快速比较。
对于小改动它会浪费资源吗?
技能说明,不应用于微小改动,或方案已经确定的情况。
候选方案可以修改文件吗?
方案、评审和调研都保持只读,而实现类候选方案在独立的工作树中进行。
详情
作者的原始描述
Generate a small set of independent candidate solutions in worktrees, judge them against one explicit rubric, and apply the winner only after PASS verification.
repo: codewhale-hq/Codewhale
热度
- GitHub 星标
- 41k
- 排名
- #6520
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …