Build an Evaluation Task

A verifier that only checks that the output exists passes all 5 of our agent’s attempts. Only 2 are correct. Most of building a task is building its verifier.

Switch checks on and off. Watch the red rings, which mark wrong verdicts, and the agent’s pass rate below them. Then we build the rest piece by piece: the task folder, Docker, runs, trajectories, difficulty, fidelity and the five attempts.

You need some Python and a terminal. We build the rest from zero. Each chapter ends in a workbook block of exercises.

A lesson and workbook for Assignment 2 of Stanford CS 329Z: Engineering AI Agents (Fall 2026). John Yang designed and built the assignment, with feedback from Michael Ryan, Diyi Yang, Shreyas Sharma and Anantharaman Iyer. Starter repo: cs329z/assignment2-evals (MIT licence), with the handout inside. The toy task and every exercise here are our own. Nothing on this page solves a problem from the handout.

Tune the verifier

paid-totals and its seven candidate scripts are a toy made for this page. Each check runs the candidates for real in your browser. A filled letter marks a correct script.

Workbook progress
0 / 37 exercises (0%)
0
Day streak
Best: 0

Chapter 0

The Map: What You Build

See the parts of a task, follow one run through them, and meet the toy task we use on every page

You build one task that a coding agent fails for a good reason. A task is a folder with four parts: a problem statement, a starting environment, a verifier that scores the agent’s work, and a reference solution. Harbor is the framework that runs it, Docker holds the environment, and the agent under test is mini-SWE-agent with Gemini 3.8 Flash.

PartFileWho reads itChapter
Instructioninstruction.mdThe agent1, 6
Environmentenvironment/DockerfileDocker, before the run2
Run settingstask.tomlHarbor3
Verifiertests/test.shHarbor, after the agent stops7
Solutionsolution/solve.shThe oracle run only4

The files never call each other. Harbor uses each one at a fixed stage of a run. Pick who runs the task and step through the five stages.

Trace one run

The lit line shows which file feeds the current stage. Try the hard-coder: it looks fine until stage 4.

An illustrative toy of a Harbor run on paid-totals. Stage 4 runs each script for real in your browser on a fresh CSV.

The toy task on every page

Every example and exercise here uses one small task of our own, paid-totals. It is too easy to use as a real benchmark, which is the point: it shows each idea in a few lines.

instructionWrite /app/totals.py. Run it as: python /app/totals.py <csv path>.
Print a JSON object that maps every customer to the total cents of their paid orders.
A customer with no paid orders maps to 0. Your script must work on any file in this format.
orders.csvcustomer,cents,status
ana,1200,paid
ben,500,refunded
ana,300,paid
cy,800,pending
ben,700,paid                  # correct output: {"ana": 1500, "ben": 700, "cy": 0}

The common failure: the verifier reads the sample file the agent can see. Then a script that prints the sample answer as a constant scores 1. In the toy above, agent E does that, and only the fresh CSV at stage 4 catches it.

The road

  1. What a task is: instruction, environment, verifier, solution.
  2. Docker: the same result on any machine.
  3. The task folder: each file of the example, and what it is for.
  4. Run and read: the oracle, an agent, the job folder, three benchmarks.
  5. Trajectories: label the steps and count the effort.
  6. Hard for the right reason: capability or defect.
  7. Fidelity: false passes and false fails, the hero’s two errors.
  8. Five attempts: what a pass rate can and cannot say.
  9. Field guide: audit a task, the checklist, the numbers.
Which two parts stay out of the agent’s container while it works?

Workbook

Exercise 0.1: Order the work on your task Design
Put the steps of building a task in the order you do them.
?
→
?
→
?
→
?
→
?
→
?
→
?
run 5 attemptsoracle scores 1report all five rewardspick a capabilityread each trajectorywrong solutions score 0write the four parts
Show why
You test the verifier with the oracle and with wrong solutions before any agent runs. The five attempts come once the task is final, and the trajectories explain the rewards you report.
Exercise 0.2: Count the containers Derive
Before you trust a pass rate, you run the oracle, a do-nothing agent and 3 shortcut scripts. Then the agent makes 5 attempts. Each run starts a fresh container. How many containers start?
containers
Show derivation
1 oracle + 1 do-nothing + 3 shortcuts = 5 checks of the verifier
5 checks + 5 agent attempts = 10 containers
Half the runs test the task, not the agent. A fresh container each time means no run sees files from the one before.
Exercise 0.3: What do 4 passes say? Trace
Your oracle scores 1. In five attempts, the agent passes 4. What is the most likely reading?
Show why
4 of 5 says the agent mostly has the skill. A task built to find a weakness wants few passes, and a clear reason for each fail.

Chapter 1

What a Task Is: Instruction, Environment, Verifier, Solution

Split a task into its four parts and see what breaks when one is missing

An agent gets one paragraph: total the paid orders. It lists files, reads the CSV, writes a script and runs it. Then it stops. Did it succeed? You need a fixed request, a fixed world and a fixed judge, or you cannot say.

PartIn paid-totalsIts job
InstructionThe paragraph in Chapter 0Say what done means
EnvironmentA container with orders.csv and a stub totals.pyGive every attempt the same start
VerifierRuns the script on a fresh CSV and compares totalsTurn the end state into a reward in [0, 1]
SolutionA correct reference scriptProve the task is solvable through that verifier

The run that uses the reference solution in place of an agent is the oracle. Remove a part below and read what you lose.

Remove one part

The agent reads the instruction, acts in the environment, and the verifier scores the end state. The oracle path runs the solution through the same verifier.

Worked example: do the instruction and verifier agree?

This match is called task-verifier fidelity: the instruction states every behaviour the verifier checks, and the verifier checks every stated rule. List both sides for paid-totals.

  1. Stated: paid orders only, zero customers listed, works on any file.
  2. Checked: paid totals match, every customer present, run on a fresh file.
  3. Each check maps to one stated rule, and each rule has a check. No gaps.

Now add a check that keys come out sorted. The instruction never asks for that. A correct script that prints keys in file order now scores 0.

The failure: correct-looking attempts score 0. To measure it, list every check and find the sentence that states it. To fix it, state the rule in the instruction or delete the check.

Your verifier checks that output keys are sorted, and the instruction does not say so. What goes wrong?

Workbook

Exercise 1.1: Remove the solution Trace
You delete the solution folder from paid-totals. What can you no longer show?
Show why
The oracle runs the reference solution through the same verifier. A reward of 1 shows the task can be solved and the verifier accepts a solution.
Exercise 1.2: Find the gaps between instruction and verifier Build
Each requirement is a short string. stated lists what the instruction says. checked lists what the verifier tests. Return {unstated, unchecked} in that key order: unstated holds checks the instruction never states, unchecked holds stated rules that no check tests. Keep the input order.
Show solution
javascriptfunction fidelityGaps(stated, checked) {
  const unstated = checked.filter(c => !stated.includes(c));
  const unchecked = stated.filter(s => !checked.includes(s));
  return { unstated, unchecked };
}
The same idea in Python:
pythonunstated  = [c for c in checked if c not in stated]
unchecked = [s for s in stated if s not in checked]
Exercise 1.3: A check the instruction never asks for Debug
The paid-totals instruction asks for a JSON object of totals. It says nothing about key order. Click the line that fails correct solutions.
out = json.loads(run_script(fresh_csv))want = reference_totals(fresh_csv)assert isinstance(out, dict)assert list(out) == sorted(out)assert out == want
Show why
Line 4 demands sorted keys. A correct script that prints keys in file order fails: a false fail, and a rule the agent could not know.

Chapter 2

Docker: The Same Result Twice

Pin the environment so that your laptop, a friend and a CI server see the same world

Your oracle scores 1 on your MacBook. A friend runs the same folder and gets 0. Maybe their Python is newer, a library moved, or a file lived only in your home folder. Docker fixes this: each attempt runs inside a container, a closed workspace with a set operating system, set packages and set starting files.

TermWhat it isAnalogy
DockerfileThe text recipe for the environmentA recipe card
ImageThe built result; once built, it never changesA frozen meal
ContainerOne running copy of an image; its changes stay inside itOne plate, heated up

Rebuild on three machines

Each column builds the task on a different day. Switch on the pins and watch the oracle’s reward on each machine.

An illustrative toy. The three failure causes are the ones the handout names: a different OS, different versions, a missing file.

Worked example: two pins in the starter repo

The example task’s Dockerfile pins its base image by digest, a hash of the exact image. Docker’s docs say a tag can move to a new image, but a digest always gives the same one.

dockerfileFROM python:3.12.16-slim-bookworm@sha256:e697c818...   # tag + digest
WORKDIR /app
COPY humaneval_0.py /app/humaneval_0.py

The second pin is a real failure. The repo’s notes say Harbor installs mini-SWE-agent without pinning its dependencies. So each run could get a different litellm, and litellm 1.106.x crashes on import without mcp. So pinned_agent.py installs exact versions: mini-swe-agent 2.4.6 and litellm 1.105.7.

Two commands on our toy:

shelldocker build -t paid-totals environment/         # -t names the image
docker run --rm -it paid-totals python --version
# --rm deletes the container on exit
# -i keeps input open, -t gives a terminal

The failure: the oracle passes for you and fails on a CI server. To measure it, build from a clean checkout on a second machine. To fix it, pin the base by digest and every package by version, and copy every asset in the Dockerfile.

Why pin the base image by digest and not only by tag?

Workbook

Exercise 2.1: One image, ten containers Trace
You build the paid-totals image once and start ten containers from it. The agent in container 3 deletes orders.csv. What happens?
Show why
An image never changes once built. Each container starts from the same files and changes only its own copy.
Exercise 2.2: The line that drifts Debug
This Dockerfile builds on your laptop today. Which line can give a CI server a different environment next week?
FROM python:3.12.16-slim-bookworm@sha256:<digest>WORKDIR /appCOPY data/orders.csv /app/data/orders.csvCOPY totals.py /app/totals.pyRUN pip install pandas
Show why
Line 5 installs whatever pandas version is newest on the day of the build. Pin it (pandas==X.Y.Z). Line 1 is pinned by digest.
Exercise 2.3: Chance of drift Derive
Your Dockerfile installs 4 packages without versions. Between your build and the CI server’s, each one has a 10% chance of a new release. Assume they are independent. What is the chance that at least one differs?
%
Show derivation
P(one package unchanged) = 0.9
P(all 4 unchanged) = 0.94 = 0.6561
P(at least one differs) = 1 − 0.6561 = 0.3439 = 34.39%
Each unpinned package adds risk. With 20 of them the chance passes 87%.
Exercise 2.4: The life of an environment Design
Put these in order, from the recipe to the cleanup.
?
→
?
→
?
→
?
→
?
docker run: start a containerthe container exits and is removedwrite the Dockerfilethe agent works insidedocker build: make the image
Show why
The Dockerfile is the recipe, the image is the built snapshot, and a container is one run of it. With --rm, Docker removes the container when it exits.

Chapter 3

The Harbor Task Folder, File by File

Open each file of the example task and learn what it is for

Harbor gives the four parts a fixed layout on disk. Once your task has that layout, Harbor can start an agent attempt, run the verifier, and save the reward and the artifacts. The starter repo ships one example, tasks/humaneval-0/, a local port of a HumanEval problem.

Open the task folder

Each file has the colour of its part. Tap a file, or step through with the arrows.

The roles are the handout’s own labels (section 3.1). The example notes describe the starter repo.

Worked example: task.toml

The example’s task.toml sets these run settings. Your task can change any of them.

Table and keyExample valueMeaning
[verifier] timeout_sec60.0Time the verifier may run
[agent] timeout_sec600.0Time the agent may work: 10 minutes
[environment] network_mode"public"The container’s network setting
[environment] build_timeout_sec600.0Time the image build may take

A Harbor task folder needs instruction.md, task.toml, tests/test.sh, solution/solve.sh and environment/Dockerfile. The Dockerfile can be left out if task.toml names a docker_image.

The failure: an attempt passes in two steps. To measure it, list what the image contains and read the trajectory for a file the agent should not have. To fix it, keep reference code with the solution or the tests, never in environment/.

Where does the problem statement the agent reads live?

Workbook

Exercise 3.1: Where the timeout lives Trace
Your verifier needs 120 seconds, not 60. Which file do you edit?
Show why
task.toml holds metadata and run settings. The example sets timeout_sec = 60.0 under [verifier].
Exercise 3.2: The answer key in the image Debug
This environment Dockerfile hands the agent something it must never see. Click that line.
FROM python:3.12.16-slim-bookworm@sha256:<digest>WORKDIR /appCOPY data/orders.csv /app/data/orders.csvCOPY totals.py /app/totals.pyCOPY reference_totals.py /app/reference_totals.py
Show why
Line 5 copies the reference answer into the agent’s world. The agent can read it and copy it. Keep reference code with the solution or the tests.
Exercise 3.3: List the missing files Build
A task needs instruction.md, task.toml, tests/test.sh, solution/solve.sh and environment/Dockerfile. The Dockerfile is optional when task.toml names a docker_image. Return the missing paths in that order, joined by commas, or "" if none.
Show solution
javascriptfunction missingFiles(paths, tomlText) {
  const need = ["instruction.md", "task.toml", "tests/test.sh", "solution/solve.sh"];
  if (!tomlText.includes("docker_image")) need.push("environment/Dockerfile");
  return need.filter(p => !paths.includes(p)).join(",");
}
The same idea in Python:
pythonneed = ["instruction.md", "task.toml", "tests/test.sh", "solution/solve.sh"]
if "docker_image" not in toml_text:
    need.append("environment/Dockerfile")
missing = [p for p in need if not (task / p).is_file()]

Chapter 4

Run an Agent and Read the Result

Run the oracle and an agent, read the job folder, and compare three benchmarks

Two runs come before any claim about your task. The oracle must score 1. An agent that does nothing must score 0. Then the real agent runs, and its reward means something.

shelluv run harbor run --path tasks/paid-totals --agent oracle \
  --n-attempts 1 --n-concurrent 1 --job-name paid-totals-oracle \
  --jobs-dir tasks/paid-totals/artifacts --yes
uv run harbor view tasks/paid-totals/artifacts     # browse the results

For a model run, swap --agent oracle for --agent-import-path pinned_agent:MiniSweAgent --model <MODEL> --env-file .env.

Run three kinds of agent

Pick who works, then press Run. The dot moves through the four stages of each attempt.

Toy runs on paid-totals with a faithful verifier. The five agent attempts are the hero’s five.

What a job folder holds

These files are a good map of a job:

Three benchmarks, oldest first

BenchmarkThe agent getsChecked by
HumanEval (2021)One self-contained function to writeUnit tests on that function
SWE-bench VerifiedA real GitHub issue and a snapshot of the repoThe project’s tests, run on the patch
Terminal-Bench 2.1Any job done in a terminal: admin, security, ML, data, scienceHidden tests on the container

Harbor rates the Terminal-Bench example task as hard: about eight hours for an expert. The SWE-bench image is x86_64 only, so Apple Silicon needs export DOCKER_DEFAULT_PLATFORM=linux/amd64 first.

The failure: an attempt has no reward. The checker marks it, or warns that an attempt ended with an error. To measure it, open the attempt in harbor view. To fix it, make sure the cause is the agent, not your setup.

Which pair of results must you see before you trust any agent result on your task?

Workbook

Exercise 4.1: The oracle scored 0 Trace
You run the oracle on paid-totals and the reward is 0. What do you fix?
Show why
The oracle is not a model. A 0 means the reference solution and the verifier disagree, or the environment does not build as you think.
Exercise 4.2: Mean reward with partial credit Derive
Your verifier gives partial credit. Five attempts return 1, 0, 0.5, 0 and 1. What is the mean reward?
reward
Show derivation
Sum = 1 + 0 + 0.5 + 0 + 1 = 2.5
Mean = 2.5 ÷ 5 = 0.5
A mean of 0.5 can hide two full passes. Report all five rewards, not only the mean.
Exercise 4.3: Summarize a job Build
Each trial is {reward}, where reward is a number or null when the verifier did not run. Return [attempts, passes, missing]: the trial count, the trials with reward 1 or more, and the trials with a null reward.
Show solution
javascriptfunction summarize(trials) {
  const passes = trials.filter(t => t.reward !== null && t.reward >= 1).length;
  const missing = trials.filter(t => t.reward === null).length;
  return [trials.length, passes, missing];
}
The same idea in Python:
pythonrewards = [trial_reward(t) for t in trials]      # None when reward.txt is absent
summary = [len(rewards),
           sum(r is not None and r >= 1 for r in rewards),
           sum(r is None for r in rewards)]
Exercise 4.4: Which benchmark? Trace
Which benchmark gives the agent a real issue and a snapshot of a codebase, then grades its patch with the project’s tests?
Show why
SWE-bench links real GitHub issues to the pull requests that fixed them. HumanEval grades one self-contained function. Terminal-Bench grades any terminal task with hidden tests.

Chapter 5

Read a Trajectory

Label each step of an agent run and count where the effort went

A reward is one number. A trajectory is the full record of the run: each action and what came back. The agent, mini-SWE-agent, has a single bash tool, so every action is one shell command. Read the commands and you see how the agent worked.

Scrub a trajectory

Each block is one step, coloured by its label. Drag through the run and watch the counts.

5

A toy run of our own on paid-totals, not an assignment trajectory.

Worked example: count the effort

Label each step with four rules, in this order. A write to a file is an edit. A python command is a run. A look such as ls or grep is an inspect. The rest is other.

LabelStepsCount
inspect1, 2, 3, 74
edit5, 8, 103
run4, 6, 9, 114
other121

The first edit, step 5, marks the switch from exploring to building. Step 6 prints a wrong total for ben. Step 7 looks at the data again, and step 8 fixes the filter. That run, look, fix loop is the multi-turn work a good task asks for.

Make three figures. For each, say what you measured, how you computed it and what you conclude. Your labels are a choice, so the rule goes in the caption.

The failure: a figure nobody can read without the raw files. To measure it, show the figure alone to a classmate. To fix it, name the unit, the rule and the run on each axis.

mini-SWE-agent writes a file with printf ... > /tmp/t.csv. Under our four rules, which label does that step get?

Workbook

Exercise 5.1: Count the effort Build
Label each command, in this order of rules: (1) edit if it starts with sed -i or has a > that starts a word; (2) run if it starts with python; (3) inspect if its first word is ls, cat, head, tail, wc, grep or find; (4) other. Return the counts as [inspect, edit, run, other].
Show solution
javascriptfunction effort(cmds) {
  const look = ["ls", "cat", "head", "tail", "wc", "grep", "find"];
  const n = [0, 0, 0, 0];
  for (const c of cmds) {
    if (c.startsWith("sed -i") || /(^|\s)>/.test(c)) n[1]++;
    else if (c.startsWith("python")) n[2]++;
    else if (look.includes(c.split(" ")[0])) n[0]++;
    else n[3]++;
  }
  return n;
}
The same idea in Python:
pythonLOOK = {"ls", "cat", "head", "tail", "wc", "grep", "find"}
def label(cmd):
    if cmd.startswith("sed -i") or re.search(r"(^|\s)>", cmd): return "edit"
    if cmd.startswith("python"): return "run"
    if cmd.split(" ")[0] in LOOK: return "inspect"
    return "other"
Exercise 5.2: Share of steps that edit Derive
In the 12-step trajectory above, the agent edits at steps 5, 8 and 10. What fraction of its steps are edits?
of steps
Show derivation
Edits = 3 (steps 5, 8, 10)
Fraction = 3 ÷ 12 = 0.25
Say how you counted. Step 10 writes a test file, and a different rule would call it a run.
Exercise 5.3: A grep that counts as a run Debug
This labeller calls grep python requirements.txt a run. Click the line at fault.
function category(cmd) {  if (cmd.startsWith('sed -i') || /(^|\s)>/.test(cmd)) return 'edit';  if (cmd.includes('python')) return 'run';  if (LOOK.includes(cmd.split(' ')[0])) return 'inspect';  return 'other';}
Show why
Line 3 matches the word anywhere in the command. Test the first word: cmd.startsWith('python').
Exercise 5.4: From exploring to building Trace
With the rule “the first edit marks the switch”, at which step does the paid-totals agent stop exploring?
Show why
Steps 1 to 4 look and run the stub. Step 5 is the first edit. State your rule in the caption, because a different rule gives a different step.

Chapter 6

Hard for the Right Reason

Tell a failure that measures a skill from a failure that measures a defect

Five attempts fail. That is good news only if each one failed for lack of the skill you meant to test. The handout counts a failure as evidence of difficulty only when the task is well specified, solvable, and failed for a reason tied to the capability.

The requirements, in short:

Sort the failures

Read each report from a paid-totals run. Decide: did the agent lack the skill, or is the task at fault?

We invented the six reports for this page. The handout warns against ambiguity, hidden assumptions, contrived constraints and fragile infrastructure.

Worked example: two versions of paid-totals

VersionWhy the agent failsVerdict
v1: “Sum each customer’s orders.”Counts refunds, because nothing says not toDefect: ambiguous
v2: orders spread over monthly files, a README defines each statusReads one file, or never opens the READMECapability: exploration

Both versions fail often. Only v2 fails for the right reason, so only v2 tells you something about the agent.

The failure: all five attempts stall on the same unclear sentence. To measure it, mark where each trajectory first leaves the path you meant. To fix it, rewrite that sentence and keep the hard part.

Two of five attempts crash because the Dockerfile downloads the CSV and the site is down. How do you read those two?

Workbook

Exercise 6.1: Spot the leak in the instruction Debug
This instruction.md gives away more than the task. Click the line.
# Paid totalsWrite /app/totals.py. Run it as: python /app/totals.py <csv path>.Print a JSON object that maps every customer to the total cents of their paid orders.A customer with no paid orders maps to 0.The tests use /tests/fresh.csv; its answer is {"gus": 500, "hal": 50}.Your script must work on any file in this format.
Show why
Line 5 hands over the hidden input and its answer. An agent can print that object and pass. Line 6 is fine: it tells the agent the test uses other files.
Exercise 6.2: Capability or defect? Trace
In 4 of 5 attempts the agent counts refunded orders. The instruction says “paid orders”, and the sample file shows the status column. How do you read these failures?
Show why
The rule is stated and the evidence is one head away. That is the skill the task tests, so the failure counts.
Exercise 6.3: Make it multi-turn for the right reason Trace
Which change makes paid-totals need exploration, not one shot, without making it unfair?
Show why
The agent must find the files and read the README, and everything it needs is in the environment. The other choices add ambiguity, fragile infrastructure or a contrived limit.

Chapter 7

Verifier Fidelity: False Passes and False Fails

Feed your verifier wrong and right answers on purpose, and count its two kinds of error

A verifier can be wrong in two ways. A false pass gives reward 1 to a wrong answer. A false fail gives 0 to a right one. The handout asks you to test incorrect and incomplete solutions, and correct ones that differ from your oracle.

Write each shortcut as a small script, then run it through the verifier. Each such wrong script is a mutant. A test input that makes a mutant fail kills it.

Kill the mutants

Rows are the seven candidates; columns are test inputs. Add inputs until every wrong row fails, then try exact text.

Every verdict comes from running the toy candidates on the four CSV files in your browser.

Worked example: how much a lax verifier overstates

overstatement
How far the reported count sits above the truth, as a fraction of the truth.
reported
Attempts the verifier passed.
true
Attempts that are correct, by reading them.
⁄ true
Scales the gap, so 1.0 means the score is double the truth.

In the hero, a verifier that checks only that output exists passes all 5 attempts. Two are correct. So the overstatement is (5 − 2) ⁄ 2 = 1.5: the score is 150% too high. Switch on the fresh-file check and it falls to 0.

pythondef verify(stdout, want):                   # want: the totals for a CSV made at verify time
    try:
        out = json.loads(stdout)
    except json.JSONDecodeError:
        return 0                              # a crash is a fail, not an error in the verifier
    return int(isinstance(out, dict) and out == want)   # dict equality ignores key order

The failure: a correct script fails because its spaces differ from the oracle’s. To measure it, write a second correct solution in another style. To fix it, compare the parsed values, not the text.

The verifier runs the script only on the sample file the agent can see. Which candidate slips through?

Workbook

Exercise 7.1: Write a fair verifier Build
Return 1 if stdout parses as a JSON object with exactly the keys of want and the same values, else 0. Key order and spaces must not matter. Text that is not JSON returns 0 and must not throw.
Show solution
javascriptfunction verify(stdout, want) {
  let out;
  try { out = JSON.parse(stdout); } catch (e) { return 0; }
  if (out === null || typeof out !== "object" || Array.isArray(out)) return 0;
  const a = Object.keys(out), b = Object.keys(want);
  if (a.length !== b.length) return 0;
  return b.every(k => out[k] === want[k]) ? 1 : 0;
}
The same idea in Python:
pythondef verify(stdout, want):
    try:
        out = json.loads(stdout)
    except json.JSONDecodeError:
        return 0
    return int(isinstance(out, dict) and out == want)   # dict equality ignores key order
Exercise 7.2: Count the two errors Build
truth[i] says whether candidate i is correct. verdict[i] says whether the verifier passed it. Return [falsePasses, falseFails].
Show solution
javascriptfunction errors(truth, verdict) {
  let fp = 0, ff = 0;
  truth.forEach((t, i) => {
    if (!t && verdict[i]) fp++;
    if (t && !verdict[i]) ff++;
  });
  return [fp, ff];
}
Exercise 7.3: The line that passes everything Debug
A toy verifier script in the shape of a test.sh (the reward file name here is ours). Every attempt scores 1, even the empty stub. Click the line that lets wrong solutions through.
#!/bin/bashset -uo pipefailcd /testspython check.pyecho 1 > "$REWARD_FILE"
Show why
Line 5 writes 1 whatever check.py returned. Branch on the exit code: if python check.py; then echo 1; else echo 0; fi.
Exercise 7.4: The do-nothing stub passes Debug
With this check, the starter stub that prints {} scores 1. Click the line at fault.
def check(out, want):    if not isinstance(out, dict):        return 0    for name in out:        if out[name] != want.get(name):            return 0    return 1
Show why
Line 4 loops over the keys the script printed. An empty object has none, so nothing fails. Loop over want, or compare the two dicts.
Exercise 7.5: How much the score lies Derive
A lax verifier passes 4 of 5 attempts. Only 2 are correct. By what percent does the reported pass count overstate the true one?
%
Show derivation
Overstatement = (reported − true) ÷ true
= (4 − 2) ÷ 2 = 1.0 = 100%
The score doubles with no change in the agent. Only the verifier moved.

Chapter 8

Five Attempts: What a Pass Rate Can and Cannot Say

Read two passes in five as a wide range, and see how luck moves the count

You run five attempts together and keep every artifact, not only the good ones. Anyone who reruns five fresh attempts with the same agent, model and settings should see a similar count.

A common target for a hard task is at most two passes in five. But five is a small sample. Pick a true pass rate and see how often luck lands on each count.

Roll five attempts

Bars show the chance of each pass count. The shaded bars meet the “at most two” target. The ruler shows the interval for the count you observed.

40%
2 of 5

Binomial chances and the 95% Wilson interval, computed live. The model treats attempts as independent.

Worked example: two passes in five

The Wilson interval gives a range of true pass rates that fit an observed count. It behaves well for small n and for counts near 0 or n.

interval
The low and high ends of the likely true pass rate.
k
Passes you observed.
z
1.96 for a 95% interval.
± z√…
The half-width: wide when n is small.
k(n−k)⁄n
The spread of a pass count; largest when k is half of n.
n
Attempts: 5 here.
n−k
Fails you observed.
⁄ n
Turns the spread into a per-attempt scale.
n + z²
Pulls the centre a little toward one half.
  1. n + z² = 5 + 3.84 = 8.84.
  2. Centre = (2 + 1.92) ⁄ 8.84 = 0.443.
  3. Half-width = (1.96 ⁄ 8.84) × √(1.2 + 0.96) = 0.222 × 1.470 = 0.326.
  4. Interval = 0.443 ± 0.326, so 11.8% to 76.9%.

So two in five fits an agent that solves the task one time in eight, or three times in four. It shows the task is not easy. It cannot give a precise rate, and it never says why attempts failed. The trajectories say that.

The failure: you rerun until you see two passes. To measure it, count every run you made. To fix it, run all five together once and report all five, as the handout asks.

An agent truly solves your task 60% of the time. About how often do five attempts still give at most two passes?

Workbook

Exercise 8.1: A coin-flip agent Derive
An agent truly solves your task half the time. What is the chance that five independent attempts give at most 2 passes?
probability
Show derivation
P(k passes) = C(5,k) · 0.55 = C(5,k) ÷ 32
k = 0, 1, 2: C = 1, 5, 10, sum 16
P = 16 ÷ 32 = 0.5
The same agent lands on either side of the “at most two” line half the time. Five attempts are a small sample.
Exercise 8.2: The interval for 2 of 5 Derive
Two of five attempts pass. Use the Wilson interval with z = 1.96. What is its upper end, in percent?
%
Show derivation
n + z² = 5 + 3.8416 = 8.8416
centre = (2 + 1.9208) ÷ 8.8416 = 0.4434
half = 1.96 ÷ 8.8416 × √(2·3÷5 + 0.9604) = 0.2217 × 1.4697 = 0.3259
upper = 0.4434 + 0.3259 = 0.7693 = 76.93%
The lower end is 11.8%. Two of five fits a true rate anywhere from about 12% to 77%.
Exercise 8.3: Code the Wilson interval Build
Return [lo, hi], the 95% Wilson interval for k passes in n attempts, with z = 1.96. Use the form in the equation above.
Show solution
javascriptfunction wilson(k, n) {
  const z = 1.96, d = n + z * z;
  const c = (k + z * z / 2) / d;
  const h = (z / d) * Math.sqrt(k * (n - k) / n + z * z / 4);
  return [c - h, c + h];
}
The same idea in Python:
pythondef wilson(k, n, z=1.96):
    d = n + z * z
    c = (k + z * z / 2) / d
    h = z / d * math.sqrt(k * (n - k) / n + z * z / 4)
    return c - h, c + h
Exercise 8.4: Zero of five Trace
None of five attempts pass. What can you claim?
Show why
The Wilson interval for 0 of 5 runs from 0% to 43.5%. Zero passes in a small sample does not prove zero, and it does not prove the task is sound.

Chapter 9

Field Guide: Audit, Check, Remember

Audit a verifier with the sanity suite, run the checklist, and keep the numbers on one page

Before you trust a task, audit it. That holds for your own task and for one from a public benchmark. The audit is a sanity suite: a list of scripts, each with the reward the verifier must give it.

Run the sanity suite

Pick a verifier. Each row runs one script for real and compares the reward with the one it must get. Find the verifier with no red row.

The seven scripts are the toy candidates from the hero, run in your browser. Each verifier adds checks to the one before it.

The checklist

Terms and numbers

Term or numberMeaning
OracleThe run that uses the reference solution; it must score 1.
VerifierThe code that turns the end state into a reward in [0, 1].
False pass, false failA wrong answer scored 1; a right answer scored 0.
FidelityInstruction and verifier describe the same task.
TrajectoryEvery action of a run and what came back.
DigestA hash that names one exact image.
At most 2 of 5The hard-task target: the agent passes at most two of five attempts.
11.8% to 76.9%The 95% Wilson interval for 2 passes in 5.

The core as code

pythondef sanity(run_task):                          # run_task(agent) -> reward in [0, 1]
    assert run_task("oracle") == 1             # solvable through the same verifier
    assert run_task("do-nothing") == 0         # the starting state earns nothing
    for shortcut in ["hard-code", "drop-edge-case", "skip-rule"]:
        assert run_task(shortcut) == 0         # every mutant dies
    assert run_task("other-correct-style") == 1  # no false fail

def wilson(k, n, z=1.96):                       # k passes in n attempts
    d = n + z * z
    c = (k + z * z / 2) / d
    h = z / d * math.sqrt(k * (n - k) / n + z * z / 4)
    return c - h, c + h                          # wilson(2, 5) = (0.118, 0.769)

Keep going

The takeaway. A task is a claim about a skill. The oracle shows it can be done, the mutants show the verifier cannot be fooled, and five honest attempts show roughly how hard it is.
Your verifier gives the oracle 1 and every shortcut 0. A correct script that prints compact JSON gets 0. What is wrong?

Workbook

Exercise 9.1: Which sentence is evidence? Trace
You audit a paid-totals task. Which note gives evidence the task’s author can act on?
Show why
It names a file, a check and a trajectory event. Anyone can open them and confirm the flaw.
Exercise 9.2: A score with broken tasks in it Derive
A benchmark has 40 tasks. Your audit finds that the oracle scores 0 on 6 of them, so no agent can pass those. An agent scores 17 of 40. What is its pass rate on the 34 solvable tasks, in percent?
%
Show derivation
Reported rate: 17 ÷ 40 = 42.5%
Solvable tasks: 40 − 6 = 34
Rate on solvable tasks: 17 ÷ 34 = 50%
Broken tasks pull every agent down by the same share. The benchmark measures its own defects as well as the agent.
Exercise 9.3: Order an audit Design
Put the steps of auditing one task in order.
?
→
?
→
?
→
?
→
?
→
?
examine the 5 trajectories and rewardswrite a note that cites a file or eventread the instructionrun do-nothing and shortcuts: want 0run the oracle: want 1inspect environment, verifier and solution
Show why
You learn what the task claims, then check that the verifier can be trusted, and only then read what the agent did. The note comes last, so it can cite what you found.
Exercise 9.4: The line that helps nobody Debug
An audit note on a toy paid-totals task. One line gives the author nothing to act on. Click it.
Summary: tests whether an agent can total paid orders from a CSV it must inspect.Fidelity gap: tests/test_outputs.py never runs the script on a new file.Evidence: attempt 4 prints the sample totals as a constant and still scores 1.Strongest aspect: the sample file shows every status code.Improvement: make the task better and harder.
Show why
Line 5 is not concrete or actionable. Name the change: “run the script on a fresh CSV made at verify time”.

Now press Present or Teach. Explain from memory: the four parts of a task, why Docker pins, the oracle and do-nothing pair, the two verifier errors, and what two in five can say. Then go back to the hero and find the smallest set of checks with no red ring.

Credit and source

This page teaches the skills behind Assignment 2 of Stanford CS 329Z, Engineering AI Agents (Fall 2026), taught by Diyi Yang, Michael Ryan and John Yang. John Yang designed and built the assignment, with feedback from Michael Ryan, Diyi Yang, Shreyas Sharma and Anantharaman Iyer. It uses the MIT licence and lives in cs329z/assignment2-evals, which holds the handout. The benchmarks are from Chen et al. (HumanEval), Jimenez, Yang et al. (SWE-bench) and Merrill, Shaw et al. (Terminal-Bench). The toy task, the devices and the exercises are ours. The assignment is still open, so this page holds no solution and no write-up answer.

CS 329Z Assignment 2: Building an Evaluation Task (Lesson + Workbook)
Starter repo and handout · The course site · Lecture 13 · Back to Gleams