跳转到内容

练习 2:检查你的检查项

  • 时长 15 分钟
  • 模型用量 无:模拟执行器(mock)不调用任何模型
  • 使用 evals/release-notes-control.eval.yaml

一张校准工作台:一架配有校准砝码的天平;传送带上的四张答案卡片依次穿过一座装有放大镜的检测拱门,两张带着绿色对勾离开,两张带着珊瑚色叉号离开。青绿色的机器人在扶手椅里睡觉,因为本练习不运行任何智能体。

先检验测量仪器:用已知答案看看你的检查项能否放行好答案、拦下坏答案。

现在,你在练习 1 中定下的标准要变成检查项了。不过,在让它们给真正的智能体评分之前,你要先证明它们确实有效:把判定结果已知的答案交给它们,看看它们的结论是否与你一致。你会发现起始存储库自带的检查项有一个盲点,然后亲手修复它。

本练习一览
有变化
之前见过,这里有所不同
你要做
把四个已知答案交给你的检查项,找出它们的盲点,并用一个否定检查修复它。
被测对象
你的检查项:能否让好答案通过、让坏答案失败?
检查方式
针对答案的代码检查项:包含 CT-101、包含 CT-103,以及新增的“不包含 CT-102”
  1. 任务 有变化 四个已知答案,以提示词的形式写成
  2. 智能体 有变化 模拟执行器:不调用模型,提示词直接成为答案
  3. 环境 本练习不使用
  4. 试验 每个答案 1 次:模拟执行器的结果永远不变
  5. 检查项 有变化 output-contains,肯定检查和否定检查
  6. LLM 评审 本练习不使用
  7. 结果 终端、--verbose、试验记录、仪表板
运行时发生了什么 vally eval -e evals/release-notes-control.eval.yaml
有变化
之前见过,这里有所不同
  • 你
  • Vally 评估运行器
  • 模拟执行器 不用模型
  • 检查项 每个答案三项
  • 结果 vally-results/
  1. 你 到 Vally: 启动运行 四个任务,每个都有一个已知答案,各运行一次试验。
  2. 对 4 个已知答案中的每一个
    1. Vally 到 模拟执行器: 发送提示词 有变化 提示词就是已知答案,一字不差。
    2. 模拟执行器 到 Vally: 把提示词原样作为答案返回 有变化 不用模型,不消耗 token,每次都一样。
    3. Vally 到 检查项: 交出答案 有变化 是否包含 CT-101 和 CT-103?以及你添加的否定检查:是否不含 CT-102?
    4. 检查项 到 Vally: 通过或失败,并附上证据 正确答案和另一种可接受的答案应当通过;错误答案和空答案应当失败。
  3. Vally 到 结果: 写入结果 判定结果的模式会告诉你:你的检查项能否区分好坏。

对照用例 新

一个你已经知道判定结果的答案:已知正确的答案必须通过,已知错误的答案必须失败。对照用例测试的是你的检查项,而不是智能体。

打个比方: 校准秤用的标准砝码

在哪里看到: evals/release-notes-control.eval.yaml 中的每个任务(stimulus)

模拟执行器(mock) 新

一种不调用任何模型的执行器。它把每个任务的提示词文本当作“答案”返回,所以检查项评判的正是你写下的文字。免费、快速,而且每次都一样。

打个比方: 回放固定答案的测试替身

在哪里看到: defaults 下的 executor: mock

任务(stimulus) 新

一个任务。使用模拟执行器时,它的 prompt 就是你的已知答案,一字不差。

打个比方: 一个测试用例

在哪里看到: stimuli: 下的每一项,各有一个 name

评分器 output-contains 新

一种代码检查项:答案包含指定文本时通过。默认不区分大小写。

打个比方: assertContains

在哪里看到: type: output-contains,config: { substring: … }

否定检查 新

同一个检查项,但结果取反:文本不存在时通过。

打个比方: assertNotContains

在哪里看到: 配置中的 negate: true

阈值 新

试验通过所需的分数。每次试验的分数是其所有检查项分数的平均值;设置 threshold: 1 时,每个检查项都必须通过。

打个比方: 及格线

在哪里看到: scoring.threshold

在本练习中,你不希望由智能体来写答案:你要的是你自己的答案,有好有坏,这样你才清楚检查项应该得出什么结论。模拟执行器正好能做到这一点。它完全跳过智能体,把提示词文本直接交给评分器:

  1. 普通试验 executor: copilot-sdk(从练习 3 起)
  2. 提示词 “Write the release notes …”
  3. 智能体工作 Copilot 读取文件,写出答案
  4. 检查项 给智能体的答案评分
  1. 对照试验 executor: mock(本练习)
  2. 提示词 你的已知答案,一字不差
  3. 没有模型 提示词文本直接成为答案
  4. 检查项 给你的已知答案评分

这带来了四点真实智能体给不了的好处:

  • 原因明确。如果某个对照用例得到了错误的判定结果,那就是检查项错了,因为没有其他因素参与。以后真实试验失败时,你就知道问题出在智能体,而不是检查项。
  • 零成本。不用模型,不耗 token,也不消耗 Copilot 请求。
  • 速度快。没有模型,也就无需等待:一次对照运行只需几秒,你可以改一个检查项,然后重跑 20 次。
  • 每次结果都相同。对照用例的结果是确定的,所以结果一旦变化,必然意味着你的检查项变了。

但它不会告诉你任何关于智能体的信息。它测试的是你的测量仪器。智能体要到练习 3 才登场。

  1. 在编辑器中打开 evals/release-notes-control.eval.yaml。它包含四个任务,每个都是一个已知答案:

    任务 答案内容 预期结果
    known-good-answer CT-101 和 CT-103,外加一句摘要 通过
    acceptable-alternative 相同的条目,但换了顺序和措辞 通过
    wrong-answer CT-101、CT-102 和 CT-103:宣布了尚未完成的工作 失败
    empty-answer “Nothing new to announce in this release.” 失败

    目前每个任务有两个检查项:“包含 CT-101”和“包含 CT-103”。也看看文件顶部:executor: mock、runs: 1(模拟答案永远不变,所以一次试验就够了)和 threshold: 1。

  2. 先不运行,检查一下文件中有没有错误:

    Terminal window
    vally lint -e evals/release-notes-control.eval.yaml --strict
    ✔ evals/release-notes-control.eval.yaml is valid

    vally lint 能发现拼错的字段、两个检查项重名之类的错误。--strict 会把警告也当作错误。

  3. 先预测,再运行:用这些检查项,四个答案中哪些会通过?然后运行评估:

    Terminal window
    vally eval -e evals/release-notes-control.eval.yaml
    Loaded 4 stimuli from release-notes-check-controls · 4 workers
    release-notes-check-controls
    FAIL empty-answer · 0/2 graders · 0.0s
    ✘ empty-includes-search 'CT-101' NOT found in output
    ✘ empty-includes-dark-mode 'CT-103' NOT found in output
    · score 0.0% < threshold 100.0% · trial 1
    score: 0.0% · threshold: 100.0%
    ────────────────────────────────────────────────────────
    Summary
    release-notes-check-controls ✘ 3/4 (score 75% < 100%)
    ✘ empty-answer 2 graders failed
    · empty-includes-search 'CT-101' NOT found in output · trial 1
    · empty-includes-dark-mode 'CT-103' NOT found in output · trial 1
    · score 0.0% < threshold 100.0% · trial 1
    Saved /workspaces/agent-evals-workshop-starter/vally-results/2026-11-19T09-54-58-895Z/
    Run ID 2d473096-412c-4eae-af7c-3e4ed0d126b4

    Vally 只列出失败的任务,并给出每个任务中失败的检查项及其证据:'CT-101' NOT found in output。4 个答案中有 3 个通过了,而其中一个正是错误答案。这些检查项只关心 CT-101 和 CT-103 是否出现。错误答案两者都有,所以通过了,尽管它宣布了 CT-102。你的评估恰恰对你最关心的那个 bug 视而不见。

  4. 修复这个盲点:给每个任务添加一个否定检查。在文件中,把 # TODO (Lab 2, step 4) 所在的每一整行(包括行首的空格)替换为类似下面这样的检查项。检查项名称在整个文件中必须唯一,所以请沿用该任务其他检查项的前缀:good-、alt-、wrong- 和 empty-:

    - type: output-contains
    name: good-leaves-out-export
    config: { substring: CT-102, negate: true }

    注意保持缩进:- 要与其他检查项的 - 对齐。

  5. 再执行一次 lint,然后再运行一次:

    Terminal window
    vally lint -e evals/release-notes-control.eval.yaml --strict
    vally eval -e evals/release-notes-control.eval.yaml
    Loaded 4 stimuli from release-notes-check-controls · 4 workers
    release-notes-check-controls
    FAIL wrong-answer · 2/3 graders · 0.0s
    ✘ wrong-leaves-out-export 'CT-102' found in output
    · score 66.7% < threshold 100.0% · trial 1
    score: 66.7% · threshold: 100.0%
    FAIL empty-answer · 1/3 graders · 0.0s
    ✘ empty-includes-search 'CT-101' NOT found in output
    ✘ empty-includes-dark-mode 'CT-103' NOT found in output
    · score 33.3% < threshold 100.0% · trial 1
    score: 33.3% · threshold: 100.0%
    ────────────────────────────────────────────────────────
    Summary
    release-notes-check-controls ✘ 2/4 (score 75% < 100%)
    ✘ wrong-answer wrong-leaves-out-export · 'CT-102' found in output
    · score 66.7% < threshold 100.0% · trial 1
    ✘ empty-answer 2 graders failed
    · empty-includes-search 'CT-101' NOT found in output · trial 1
    · empty-includes-dark-mode 'CT-103' NOT found in output · trial 1
    · score 33.3% < threshold 100.0% · trial 1
    Saved /workspaces/agent-evals-workshop-starter/vally-results/2026-11-19T09-55-31-609Z/
    Run ID 78ca45aa-f8cd-42c2-b500-7e609d5572a1

    Vally 又一次报告评估失败,而这一次,这正是你想要的结果:参见刚才发生了什么。

  6. 亲自评判结果。终端只显示了失败的部分。要查看判定结果背后的答案,请加上 --verbose 再运行一次评估:这样,对于每个失败的任务,Vally 还会在 agent output 下打印出它评判的答案。运行不花钱,想重跑多少次都可以:

    Terminal window
    vally eval -e evals/release-notes-control.eval.yaml --verbose

    部分输出:

    FAIL wrong-answer · 2/3 graders · 0.0s
    ✘ wrong-leaves-out-export 'CT-102' found in output
    · score 66.7% < threshold 100.0% · trial 1
    0 turns · 0 tools · 0 tok · mock
    0 in · 0 out
    score: 66.7% · threshold: 100.0%
    agent output
    - CT-101: Search across all projects
    - CT-102: Export reports to CSV
    - CT-103: Dark mode for the dashboard

    0 turns · 0 tools · 0 tok · mock:没有任何模型参与。要查看全部四个答案(包括通过的那些),请用与练习 0 中相同的 jq 命令查看试验记录:

    Terminal window
    RUN=$(ls -d vally-results/*/ | tail -1)
    jq 'select(.type == "trial-result") | {stimulus, answer: .trajectory.output, passed: .gradeResult.passed, score: .gradeResult.score}' "$RUN/results.jsonl"

    逐个任务检查:判定结果是否符合你的预期?每个失败检查项的证据是否指向了正确的原因?

  7. 查看本次运行的摘要表:在 Explorer(资源管理器)中,右键单击最新运行文件夹中的 eval-results.md,然后选择 Open Preview(打开预览)。Tokens 列中每个答案都是 0:模拟执行器从未调用模型。

    Stimulus Graders Pass Rate Verdict
    empty-answer ❌ empty-includes-search 0/1
    ❌ empty-includes-dark-mode 0/1
    ✅ empty-leaves-out-export 1/1
    0/1 ❌
    wrong-answer ✅ wrong-includes-search 1/1
    ✅ wrong-includes-dark-mode 1/1
    ❌ wrong-leaves-out-export 0/1
    0/1 ❌
    acceptable-alternative ✅ alt-includes-search 1/1
    ✅ alt-includes-dark-mode 1/1
    ✅ alt-leaves-out-export 1/1
    1/1 ✅
    known-good-answer ✅ good-includes-search 1/1
    ✅ good-includes-dark-mode 1/1
    ✅ good-leaves-out-export 1/1
    1/1 ✅

    (已精简:实际的表格还包含时长、token 数、轮次和工具调用次数。)

  8. 像练习 0 中那样重启仪表板:在它的终端中按 Ctrl+C,然后按向上箭头键和 Enter 键。重新加载页面,选择你最新的运行:通过率 50%,4 个产出结果,0 个 token。在 Grader breakdown 下,output-contains 通过了 9 次、失败了 3 次:正是你预期的那 3 次失败,没有别的。

Vally 说评估失败了,而这正是你想要的结果。在对照评估中,已知错误的答案本来就应该失败。Vally 并不知道哪些答案是你有意写坏的;它只报告 4 个任务中有 2 个失败。(汇总中的 score 75% 是四个答案分数的平均值,这四个分数分别是 100%、100%、66.7% 和 33.3%;而每个答案自身的判定结果,取决于它是否达到了阈值。第 3 步的四个分数是 100%、100%、100% 和 0%,平均值同样是 75%,这纯属巧合。)你要检查的是模式:好答案 ✅、替代答案 ✅、错误答案 ❌、空答案 ❌。这个模式证明了三件事:

  • 你的检查项会接受好答案,即使换了顺序和措辞也一样:它们不依赖格式。
  • 你的检查项会拒绝你关心的那个 bug:一个宣布了 CT-102 的答案。
  • 你的检查项会拒绝什么都没宣布的答案。

第 3 步已经让你看到了这为什么重要:只有肯定检查的评估,会把有 bug 的技能(skill)判为通过。那样你就会信任一个本身就有问题的测量。还要注意,尽管评估失败了,vally eval 仍然正常退出:失败的判定结果并不是错误。只有加上 --require-pass 时,失败的判定结果才会让命令以退出码 1 退出,这正是你在 CI 中要用的。

为什么错误答案在第 3 步中通过了?

因为所有检查项都是肯定检查:“包含 CT-101”“包含 CT-103”。错误答案两者都包含。没有任何检查项去检查不应该出现的内容。Bug 往往表现为多出来的东西,所以大多数评估都需要否定检查。

为什么这里用模拟执行器,而不用真实的智能体?

要测试检查项,你需要判定结果已知的答案。真实智能体会自己写答案,每次运行都不一样,还要消耗 token。模拟执行器返回的是你的已知答案,免费且每次都相同,所以判定结果一旦出错,只可能是检查项错了。

你的已知正确答案没通过某个检查项。错在哪里:答案还是检查项?

如果你确定答案是好的,那就是检查项错了:要么太严格,要么检查的是格式而不是含义。这正是设置可接受替代答案的原因:像“第一个列表项是 CT-101”这样的检查项会让它失败,尽管这个答案完全没问题。

把你的文件和我们的对照一下。高亮的行就是你在第 4 步中添加的:为每个答案各加一项否定检查。

完成版的对照评估
solutions/lab-2/release-notes-control.eval.yaml
# Lab 2 solution: a control eval. It tests the checks, not the agent.
#
# The mock executor calls no model. It returns each stimulus's prompt text as the answer,
# so every prompt below is a hand-written sample answer. That makes this eval free and
# deterministic: run it as often as you like.
#
# What you want to see: the two good answers pass, the wrong and the empty answer fail.
name: release-notes-check-controls
description: >-
Controls for the release-notes checks. A known-good answer and an acceptable alternative
must pass; a wrong answer and an empty answer must fail. No model, no cost.
defaults:
executor: mock # no model, no cost: the "answer" is the prompt text itself
runs: 1 # a mock answer never changes, so one trial is enough
timeout: 60s
scoring:
threshold: 1 # a trial passes only when its score reaches 1, that is, every check passes
stimuli:
# Good: completed work only, with a summary sentence.
- name: known-good-answer
prompt: |
This release makes finding and reading your work easier.
- CT-101: Search across all projects
- CT-103: Dark mode for the dashboard
graders:
- type: output-contains
name: good-includes-search
config: { substring: CT-101 }
- type: output-contains
name: good-includes-dark-mode
config: { substring: CT-103 }
- type: output-contains
name: good-leaves-out-export
config: { substring: CT-102, negate: true }
# Also good: different order and wording. Good checks don't depend on exact formatting.
- name: acceptable-alternative
prompt: |
Dark mode and cross-project search are here.
- CT-103: Dark mode for the dashboard
- CT-101: Search across all projects
graders:
- type: output-contains
name: alt-includes-search
config: { substring: CT-101 }
- type: output-contains
name: alt-includes-dark-mode
config: { substring: CT-103 }
- type: output-contains
name: alt-leaves-out-export
config: { substring: CT-102, negate: true }
# Wrong: it announces CT-102, which is still in progress. This is the bug you'll meet in Lab 3.
- name: wrong-answer
prompt: |
- CT-101: Search across all projects
- CT-102: Export reports to CSV
- CT-103: Dark mode for the dashboard
graders:
- type: output-contains
name: wrong-includes-search
config: { substring: CT-101 }
- type: output-contains
name: wrong-includes-dark-mode
config: { substring: CT-103 }
- type: output-contains
name: wrong-leaves-out-export
config: { substring: CT-102, negate: true }
# Wrong: it announces nothing.
- name: empty-answer
prompt: Nothing new to announce in this release.
graders:
- type: output-contains
name: empty-includes-search
config: { substring: CT-101 }
- type: output-contains
name: empty-includes-dark-mode
config: { substring: CT-103 }
- type: output-contains
name: empty-leaves-out-export
config: { substring: CT-102, negate: true }

在 GitHub 上打开

  • 进度落后了?scripts/catch-up.sh 2 会把完成版的对照评估放到位。它会先备份你的版本。
  • duplicate-grader-name:每个检查项的名称在整个文件中都必须唯一。请使用该任务的前缀(good-、alt-、wrong-、empty-)。
  • 编辑后出现 YAML 错误:检查缩进。每个新加的 - type: 行都必须与其他检查项从同一列开始。

把练习 1 中的答案 B 添加为第五个对照用例,命名为 note-mentions-unfinished-item。你的检查项会给它什么判定结果?这和你在练习 1 中定下的判定结果一致吗?

下一步:练习 3:运行智能体

本工作坊由 Jeffrey Groneberg 设计与编写 · 在 LinkedIn 上联系

插图由 AI 生成(MAI-Image-2.6)。命令输出来自 2026 年 11 月使用 Vally 0.21.0 的真实运行。