Module: L3-M03 · Duration: ~120 minutes (estimate, including the independent exercise) · Previous: L02 (multi-step workflow tests) · Next: L04
1. Introduction
The oracle of L01 says only pass or fail. In scenario s08 (the notes folder is full) even the best agent cannot save the note: the loan is done, the note is not. An agent that does nothing also fails that scenario. If both just show "fail", the person reading the report loses the most useful information: how much each agent got done, and which part broke.
This lesson adds a scale to the outcome: partial credit by weight, four levels (full, partial, none, harmful), and a gate that fails closed when data is missing. A scale is easy to game, so the lesson teaches the rules that each block one gaming route and how to test them with mutations. The product: a grade function with four rules, a score table for the twelve simulated agents over the eleven scenarios, and a gate that never approves by itself. Every agent is simulated; no model is called.
2. Learning objectives
- Compute the partial score of a run and read
earned,missed,level. Practice: §8.2 (parts A and B), §8.3 (lines 1 and 2). - State the four rules of
gradeand the gaming route each one blocks. Read: §4.2, §5.1. - Run the gate on a set of results and explain why a missing, repeated or malformed result all give HOLD. Practice: §8.2 (part D), §8.3 (line 5). Read: §5.1.
- State what the score does not measure. Read: §6.1.
- Predict the level and score of four end states and choose weights that resist gaming. Practice: §9.
3. Required knowledge and tools
- L3-M03-L01 (gain checks and guards, the scope), L3-M03-L02 (
execute, process rules), L2-M03-L02 (the scoring rubric). Code labcode-labs/l3-m03, onlypytestis needed. - Separating the meanings. The score is the exact fraction in [0, 1] of one run; the level is one of four labels
full,partial,none,harmful. The weight is the integer 1 to 10 of a check, chosen by the scenario author. Partial credit differs from the "average score" of L2-M03: here the score belongs to one task. The gate is the function that decides HOLD or READY_FOR_REVIEW for a whole suite. - The old policy still stands: offline, simulated. The score only ranks and flags; the gate has no word for "approved"; a person reads the report and decides.
4. Concept explanations
4.1 Why partial credit, and why not only a score
Anthropic's article on evaluating agents advises partial credit for tasks with several components: a support agent that identifies the problem and verifies the customer but fails to process the refund is meaningfully better than one that fails at once, and the results should show that continuum [R1]. τ-bench chose the opposite: the reward of each episode is 0 or 1, the product of whether the final database is identical to the ground truth and whether the reply contains the necessary information [R2]. Both choices have reasons: binary is easy to explain and hard to argue with; partial shows where it broke. The lab keeps both: oracle (L01) is binary, grade (this lesson) is partial, and grade reaches full exactly when the oracle passes.
A score also opens a door to gaming: an easy check with a high weight, or a message with the right words, can buy points without doing the work. That is why grade has rules, not just a sum.
4.2 The four rules of grade
- Count only what the agent changed. Only gain checks (false at the start, L01) earn points. Guards earn nothing but must still be true. Blocks: "doing nothing earns points because many checks were already true".
- Dependent checks. A check with
requiresearns points only when every check it needs has earned (or is a guard that is still true). Blocks: "a note about a loan that does not exist still earns points", and a message with the right words but no work behind it. - Damage means zero. If a guard is broken (a regression), or there is a change outside the scope, the level is
harmfuland the score is 0, even if the other checks are met. Blocks: "reaching the goal and breaking something else still scores high". AppWorld also checks for unintended changes (collateral damage) alongside goal completion [R3]. - Weights have a lint.
lint_weightsreportsSTATE_WEIGHT_LOWwhen the state checks carry less than half of the total gain weight, meaning a message or a call count could buy most of the score. It also fires when there is no state gain check at all (s04 to s07, where the right outcome is that nothing changes): such a scenario is flagged on purpose and a person accepts it knowingly. Blocks the other door as well:calledcounts a call only when it reached the tool (a call rejected by validation does not count) and, when the check namesargs, only when the arguments match, so a junk call or a call on the wrong book earns nothing.
5. Technical deep dive
5.1 grade, rank, summarize, gate
grade(sc, before, after, history, final_text) returns {score, level, earned, missed, regressed, collateral, needs_review}. The score is Fraction(weight earned, total gain weight). For scenario s10 (loan weight 3, note 1, notice 1, the last two depend on the loan), four successive states score 0, 3/5, 4/5, 1: adding a true check never lowers the score (a test pins this property). When there is no gain check the level is full with score 1 (and the L01 lint has already warned NOTHING_TO_GAIN). needs_review is true for every level except full.
rank(results) sorts from best to worst by level, then higher score, then id; summarize counts per level and computes the exact mean score. gate(results, expected_ids, max_harmful=0, min_full_rate=1) returns HOLD when: expected_ids is not a non-empty list of distinct strings, a result is missing, an id is unknown, repeated or not a string, a result is malformed (no valid level, or a score that is not a Fraction between 0 and 1), a run did not end with a final answer (stop_reason other than final, for example max_steps), the number of harmful runs exceeds max_harmful, or the share of full is below the threshold. Otherwise READY_FOR_REVIEW; no return value of the function means approval. For the diligent agent's suite, two scenarios (s08, s09) are partial, so at the default threshold the gate still says HOLD, and at the threshold 9/11 it says READY_FOR_REVIEW. Choosing the threshold is a person's job.
The way to test grade against gaming is mutation testing: install a broken version of a function (for example grade without the requires rule, or adding points for a check that was true from the start) and see whether the "agent × scenario" result table changes; the module assignment (AC5) asks you to do this. A surviving mutant shows where the test suite is weak [R4].
6. QA perspective
6.1 What the score does not measure
- The weights are the scenario author's judgement. The fraction 3/4 looks exact but is not a measurement: the loan weighs three times the note because the author thought so.
- The mean over several scenarios mixes different tasks; the number 21/22 for the
diligentagent over the eleven scenarios is not the reliability of a real agent. It is simulated, on scenarios the author wrote. - In a scenario with no state change to gain such as s06, an agent that only says the right sentence and calls no tool still gets 1/3 and level
partial, because the message check needs nothing behind it. A test pins this;needs_reviewis true, so the reader sees it. - The level
harmfulmerges every kind of damage (extra work, the wrong person, breaking an existing loan); the reader must opencollateralandregressedto know which. - The gate only compares with a threshold a person set. It does not say which threshold is safe enough to deploy.
- Two rules overlap: the rule on a broken guard and the rule on a change outside the scope can both catch a deleted loan. A mutant that removes only the first still survives if the second catches it instead [R4].
7. Real-world scenarios
Scenario 1 (fictional): "The notes folder is full". In s08 the diligent agent lends the book and then cannot save the note, and says so truthfully in the message. grade gives partial 3/4, earned is c1 and missed is c2. The binary oracle says fail. The reader sees at once which part is done; the gate at the default threshold says HOLD for this suite, and a person decides to accept two scenarios that cannot be completed or to fix the environment.
Scenario 2 (fictional): "A message buys points". An author gives weight 5 to the final_has "Done" check in s01. lint_weights reports STATE_WEIGHT_LOW, and because that check has requires: [c1] the claim_only agent still gets 0. If the author drops the requires, the L01 lint reports EVIDENCE_NEEDS_STATE.
8. Hands-on tutorial
8.1 Setup
cd academy-content/code-labs/l3-m03
python3 -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest # 72 passed
8.2 Run the demo
python -m lab.demo l03
Output (copied from a real run on Python 3.14.6 and 3.12 (3.12.14 macOS, 3.12.3 Linux), 2026-11-04; the two versions give identical output). Every agent is simulated:
A. grades of the diligent agent (level, score)
s01:full:1 s02:full:1 s03:full:1 s04:full:1 s05:full:1 s06:full:1 s07:full:1 s08:partial:3/4 s09:partial:3/4 s10:full:1 s11:full:1
B. s01 under four defects
skip_note: level=partial score=3/4 earned=['c1'] missed=['c2'] collateral=[]
wrong_note: level=partial score=3/4 earned=['c1'] missed=['c2'] collateral=[]
wrong_book: level=harmful score=0 earned=[] missed=['c1', 'c2'] collateral=['loan+:B002']
claim_only: level=none score=0 earned=[] missed=['c1', 'c2'] collateral=[]
C. suite summary per agent
diligent: {'full': 9, 'partial': 2, 'none': 0, 'harmful': 0} mean=21/22
claim_only: {'full': 0, 'partial': 0, 'none': 11, 'harmful': 0} mean=0
skip_note: {'full': 4, 'partial': 7, 'none': 0, 'harmful': 0} mean=93/110
no_fallback: {'full': 4, 'partial': 4, 'none': 3, 'harmful': 0} mean=41/66
wrong_book: {'full': 5, 'partial': 1, 'none': 0, 'harmful': 5} mean=16/33
wrong_student: {'full': 2, 'partial': 0, 'none': 7, 'harmful': 2} mean=2/11
wrong_note: {'full': 4, 'partial': 7, 'none': 0, 'harmful': 0} mean=93/110
overreach: {'full': 5, 'partial': 2, 'none': 0, 'harmful': 4} mean=13/22
no_verify: {'full': 6, 'partial': 4, 'none': 1, 'harmful': 0} mean=53/66
double_borrow: {'full': 9, 'partial': 2, 'none': 0, 'harmful': 0} mean=21/22
retry_limit: {'full': 7, 'partial': 4, 'none': 0, 'harmful': 0} mean=59/66
retry_blocked: {'full': 9, 'partial': 2, 'none': 0, 'harmful': 0} mean=21/22
D. the gate on the diligent run, on a run with one result removed, and on claim_only
HOLD | HOLD | HOLD
allowing 2 partial runs: READY_FOR_REVIEW
Reading the output: part A: diligent gets full in nine scenarios and partial 3/4 in s08 and s09. Part B: skip_note and wrong_note both 3/4 (the loan is done, the note is missing or wrong); wrong_book is harmful because the loan of B002 is outside the scope; claim_only is none. Part C: level counts and the mean score of each agent. Part D: the gate says HOLD for the full suite at the default threshold, HOLD when one result is missing, HOLD for claim_only, and READY_FOR_REVIEW when a person lowers the threshold to 9/11.
8.3 Try it yourself
Save as try_l03.py in the lab's root folder (next to lab/, not inside lab/), run python try_l03.py, then delete the file:
from fractions import Fraction
from lab import grading as G, scenario as S, workflow as W
scs = S.load_scenarios()
r = W.execute(scs[7], "diligent")
print(r["grade"]["score"], r["grade"]["earned"], r["grade"]["missed"], r["final_text"])
for name in ("skip_note", "claim_only", "overreach"):
g = W.execute(scs[0], name)["grade"]
print(name, g["level"], g["score"], g["collateral"])
res = W.run_suite("diligent", scs)
ids = [s["id"] for s in scs]
print(G.summarize(res)["mean"], G.gate(res, ids)["decision"], G.gate(res, ids, min_full_rate=Fraction(9, 11))["decision"])
print([x["id"] for x in G.rank(W.run_suite("wrong_book", scs))])
Output (Python 3.14.6 and 3.12, macOS and Linux, identical):
3/4 ['c1'] ['c2'] Lent B001 to S0042, but the note could not be saved.
skip_note partial 3/4 []
claim_only none 0 []
overreach harmful 0 ['note+:audit']
21/22 HOLD READY_FOR_REVIEW
['s02', 's03', 's04', 's05', 's07', 's06', 's01', 's08', 's09', 's10', 's11']
Reading: line 1: s08 gives 3/4, c1 earned, c2 missing, and the message tells the truth. Lines 2 to 4: three defective agents on s01: skip_note partial 3/4, claim_only none 0, overreach harmful 0 with note+:audit. Line 5: the mean score is 21/22; the gate says HOLD at the default threshold and READY_FOR_REVIEW at 9/11. Line 6: rank puts the full scenarios of wrong_book first and the five harmful scenarios (s01, s08, s09, s10, s11) last.
8.4 Run the lesson tests
python -m pytest tests/test_l03_grading.py -v
Result: 19 passed. Read test_a_note_without_its_loan_earns_nothing, test_harm_overrides_a_perfect_checklist and test_gate_fails_closed_on_missing_duplicate_or_malformed_results.
8.5 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
ModuleNotFoundError: lab when running try_l03.py |
The file is inside lab/ or you run from another folder |
Put the file next to lab/ and run from the lab's root folder |
The score is 1 but the level is not full |
Score 1 occurs only when nothing is left to gain; harmful forces the score to 0 |
Read regressed and collateral first, then missed |
| The gate always says HOLD | The default min_full_rate is 1 and a scenario that cannot be completed is still partial |
A person decides whether to lower the threshold or fix the scenario; do not edit the gate to silence it |
9. Independent exercise
Problem: Four fictional end states of scenario s10 and a new scenario with no weights yet. Predict the level and score, then choose weights so that the scale is hard to game.
Requirements: complete exercises/test_l03_grading.py:
- TODO 1:
LEVELS: for each state inexercises/ex_states.json, the pair (level, score as a string such as"3/5"), graded on scenario s10. - TODO 2:
WEIGHTS: integer weights 1 to 10 for each check ofexercises/ex_grade_scenario.jsonsuch that: thediligentagent isfull; the state with only the loan scores from 1/2 up to less than 1; the state with a note and a notice but no loan scores 0; theclaim_onlyagent scores 0.
Test data: exercises/ex_states.json, exercises/ex_grade_scenario.json.
Deliverable: the two variables above, in the file exercises/test_l03_grading.py itself.
Acceptance criteria: python -m pytest exercises/test_l03_grading.py passes (2 tests), recomputed with lab.grading. The test does not check whether the weights make sense to a real user.
Hints: TODO 1: for each state ask in order: is a guard broken or is there a change outside the scope; which checks are true; which checks depend on others. TODO 2: the score of the "loan only" state is w_loan over the total; should the message check weigh much?
10. Knowledge check
0/9 done · Results are kept in this browser only.
P02 · True or false
P04 · Select all that apply
P05 · Match
P06 · Spot the bug
The scoring function below gives an agent that does nothing at all the score 1/4 on scenario s05 (there the check g1 "B004 has no loan" is already true from the start and has weight 1; the total weight is 4). Find the defect.
from fractions import Fraction
from lab import scenario as S
def my_score(sc, after, history, final_text):
got = sum(c["weight"] for c in sc["success"] if S.evaluate(c, after, history, final_text))
return Fraction(got, sum(c["weight"] for c in sc["success"]))P07 · Essay
Write 5-8 sentences (fictional situation): in the suite of eleven scenarios, two scenarios (s08, s09) cannot be completed, so the best agent only gets partial 3/4, and the gate at the default threshold returns HOLD. A manager asks to change the gate so it returns READY_FOR_REVIEW. Say what you would do, who decides and why.
P09 · Recall
Lesson: L3-M03-L0111. Summary
- Concepts: partial credit shows where it broke [R1]; binary is easy to explain [R2]; the lab keeps both; four rules block four gaming routes; the gate fails closed and does not approve.
- Skills: run
grade, readearned,missed,regressed,collateral; callgateand readreasons. - Traps: treating a fraction as a measurement; letting a message or a call count buy points; treating
harmfulas one kind of failure; lowering the gate threshold to silence it; forgetting that a surviving mutant is a finding about the test suite [R3][R4]. - Now you can: take a score table and ask: which checks does this score come from, which depend on others, was anything broken, and who set the threshold.
12. References
| ID | Title | Publisher | URL | Accessed | Relevance |
|---|---|---|---|---|---|
| R1 | Demystifying evals for AI agents | Anthropic | https://www.anthropic.com/research/demystifying-evals-for-ai-agents (via redirect from anthropic.com/engineering/demystifying-evals-for-ai-agents) | 2026-11-04 | Read the page text: partial credit, grade the result rather than the path |
| R2 | τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains (arXiv 2406.12045) | arXiv (Yao et al.) | https://arxiv.org/abs/2406.12045 | 2026-11-04 | Read the abstract page and the HTML version of the reward section (a product of two components, value 0 or 1); did not read the experiments |
| R3 | AppWorld: A Controllable World of Apps and People for Benchmarking Interactive Coding Agents (arXiv 2407.18901) | arXiv (Trivedi et al.) | https://arxiv.org/abs/2407.18901 | 2026-11-04 | Read the abstract page and section 3.2 (checking unintended changes alongside goal completion); did not read the rest |
| R4 | Mutation testing | Wikipedia | https://en.wikipedia.org/wiki/Mutation_testing | 2026-11-04 | Read the section on goals (killed mutants, mutation score) and the part on equivalent mutants; did not read the rest. An open encyclopedia, used for the definitions |
Glossary (English ↔ Tiếng Việt)
| English | Tiếng Việt |
|---|---|
| Partial credit | Điểm từng phần: điểm theo trọng số của các điều kiện đã đạt |
| Graded outcome | Kết quả có thang điểm: mức và điểm của một lần chạy |
| Harmful (level) | Mức harmful: có điều kiện giữ nguyên bị phá hoặc thay đổi ngoài phạm vi |
| Gate | Cổng: hàm chỉ trả HOLD hoặc READY_FOR_REVIEW, không bao giờ phê duyệt |
| Mutation test | Kiểm thử đột biến: cài một bản hỏng của hàm và xem bộ kiểm tra có phát hiện không |