Module: L3-M03 · Duration: ~120 minutes (estimate, including the independent exercise) · Previous: L03 (partial success and graded outcomes) · Next: L3-M04-L01 (trajectories: what to record and why)
1. Introduction
L01 to L03 grade a run by its end state. But "reading the state" is itself a job that must be done right. The message can say something the environment does not have, the environment can change without the message mentioning it, the check can accidentally change the thing it measures, and the state can be edited outside the tool layer without anyone knowing.
This lesson splits verifying the environment into four small techniques with tests: a read-only observation, comparing the claims in the message with the real changes, finding the changes the message does not mention, and checking that the effect log still matches the state. The product: a "message versus state" report for five simulated agents, and two runs you write yourself that expose two kinds of mismatch. Every agent and environment is simulated; no model, network or API is called.
2. Learning objectives
- Tell apart the four relations between message and environment: confirmed, unsupported, unreported and silent. Read: §4.1.
- Observe the environment with a read-only function and explain why reading through the agent's own tool is the wrong way. Practice: §8.2 (part B). Read: §4.2.
- Run
compareand readunsupportedandunreported. Practice: §8.2 (part A), §8.3 (lines 1 to 3). - Detect a change made outside the tool layer with
environment_consistent. Practice: §8.2 (part C). - State what comparing the message with the state does not prove. Read: §6.1.
- Predict the flags of four runs and write two runs that expose two kinds of mismatch. Practice: §9.
3. Required knowledge and tools
- L3-M03-L01 (the end-state oracle,
diff_state), L3-M03-L03 (grade), L3-M02-L04 (the hash-chained effect log,reconcile). Code labcode-labs/l3-m03, onlypytestis needed. - Separating the meanings. A claim is what the message says happened, such as "lent B001 to S0042". Verification is comparing a claim with the environment. Unsupported: the message says it, the environment does not show it. Unreported: the environment changed, the message does not say so. A read-only observation takes a snapshot of the state without changing the state or the log. It differs from the
traceof L3-M01-L04: a trace is the agent's own record; here we read the environment. - The old policy still stands: offline, simulated. The comparison only flags; a person reads the flags and decides, even when the message is "clean".
4. Concept explanations
4.1 Message and environment have four relations
For each claim in the message and each real change in the environment there are four possibilities: the message says it and the environment has it (confirmed); the message says it but the environment does not have it (unsupported, usually the most serious); the environment changed but the message does not mention it (unreported); or neither has anything (silent). Anthropic's article gives the same idea as an example: the words "Your flight has been booked" differ from a reservation existing in the database, and the article notes that for WebArena the backend verification is there to be sure an order was really created, not just that the confirmation page appeared [R1].
The message is not always meaningless. τ-bench computes the reward from two components: the final database must match the ground truth and the replies to the user must contain the necessary information [R2]. When the task is to look up information, WebArena grades the answer with exact_match or must_include; when the task changes content, it checks the content that was posted, for example the URL and the body of a post [R3]. The lab's rule: the message is data to compare, not evidence; it is worth reading when the task asks for information, and always worth comparing with the state.
4.2 Four ways to read the environment
- Read-only observation.
observe(layer)takes a snapshot of the three parts of the state and raisesRuntimeErrorif taking it changed the state digest or the length of the log. The checker must not become a source of change. - Do not read through the agent's own tool.
read_via_toolcallsget_bookto learn whether a book is free. It costs budget, adds entries to the effect log, and sees only what the tool shows. The function is kept for comparison with the right way. - Compare claims with the state.
extract_claimsreads a few fixed phrases in the message;verify_claimschecks each claim on the snapshot after the run;unreportedfinds changes that no claim mentions;comparecombines the three. - The log still matches the state.
environment_consistentis true whenreconcile()reports no problem: nobody changed the state outside the tool layer.
5. Technical deep dive
5.1 What lab/endstate.py does and does not do
extract_claims(text) finds four kinds of claim by fixed English phrases: loan (Lent Bxxx to Syyyy), note (note name saved or saved note name), notice (notice queued) and no_change (nothing was changed). Text that is not a string gives an empty list. Negation is not understood. The sentence "the note could not be saved" gives no note claim only because it does not contain the fixed phrase note NAME saved; "I have not lent B001 to S0042." still gives a loan claim and "No notice queued." a notice claim (a test pins both). A sentence written in other words is read as nothing.
verify_claims(claims, before, after) returns each claim with confirmed or unsupported: loan needs the right book and the right student; note needs the note to exist; notice needs the outbox to have grown; no_change needs an empty diff_state. unreported(claims, before, after) returns the changes that no claim covers, matched by book or note name. compare returns {claims, unsupported, unreported, clean} where clean is true only when at least one claim was found and there is no mismatch. message_oracle (the message starts with "Done") is kept to show what to avoid.
For scenario s01: claim_only has two unsupported claims (the loan and the note); wrong_student has one (the loan went to S0043 while the message says S0042); skip_note has one (the note); overreach has no false claim but one unreported change (note+:audit).
6. QA perspective
6.1 What comparing the message with the state does not prove
cleanbeing true does not mean the run is right. Thewrong_noteagent saves a note with the wrong content but says "note saved": the comparison sees that the note exists and calls it clean, while the oracle's checkc2fails. The comparison is a flag next to the oracle, not a replacement for it.- The claim extractor reads only fixed English phrases. A message worded differently gives empty
claimsandcleanfalse (not "clean"); a negative sentence is skipped only when it happens to miss the fixed phrase, otherwise it is read as a claim. With a real agent the extractor has to be rewritten for the real output, and the lab does not test that part. unreportedmatches by book or note name, not by student: a loan of the same book to the wrong person is not an "unreported" change but an unsupported claim.- The effect log is not a witness for a good effect. With
wrong_studentthe log and the state agree (reconcileis empty) and both show the wrong loan.environment_consistentcatches only changes made outside the tool layer. - A snapshot is one moment, taken after the run ends. The lab does not simulate an environment that changes afterwards, late reads or asynchrony. In a real environment, read permission, latency and the side effects of reading are separate matters. AppWorld computes a small database diff listing the rows added, updated and removed between the start and end states, then checks it against the expected-changes set and the allowed-changes set [R4]; the lab's
diff_stateis a very small version of that idea.
7. Real-world scenarios
Scenario 1 (fictional): "Right book, wrong student". The wrong_student agent borrows B001 for S0043 and then says "Done: lent B001 to S0042". The oracle reports c1 false; compare reports the loan claim unsupported; the log and the state agree. The reader sees three signals at once and knows the defect is in the arguments, not in the log.
Scenario 2 (fictional): "Someone edited it directly". A person (or another piece of code) adds the loan B003 to the loans table without going through the tool layer. The oracle may still pass if that loan touches no check, but environment_consistent is false and reconcile() reports "final state differs from the log". A person decides whether this run can still be trusted.
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 l04
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 and environment is simulated:
A. message versus state, scenario s01
diligent: unsupported=[] unreported=[] clean=True
claim_only: unsupported=['loan', 'note'] unreported=[] clean=False
wrong_student: unsupported=['loan'] unreported=[] clean=False
skip_note: unsupported=['note'] unreported=[] clean=False
overreach: unsupported=[] unreported=['note+:audit'] clean=False
B. a read through the agent's own tool changes the thing it measures
observe: log entries +0, spent +0, state unchanged=True
read_via_tool: log entries +2, spent +2
C. a change made outside the tool layer
consistent before=True
consistent after a direct edit=False problems=['final state differs from the log']
Reading the output: part A: diligent is clean; claim_only has two unsupported claims; wrong_student one; skip_note one; overreach has one unreported change. Part B: observe adds no log entry and costs no budget, and the state is unchanged; read_via_tool adds two log entries and costs two cu. Part C: after a direct edit, environment_consistent is false.
8.3 Try it yourself
Save as try_l04.py in the lab's root folder (next to lab/, not inside lab/), run python try_l04.py, then delete the file:
from lab import endstate as E, scenario as S, workflow as W
s01 = S.load_scenarios()[0]
for name in ("claim_only", "overreach", "wrong_note"):
r = W.execute(s01, name)
c = E.compare(r["final_text"], r["before"], r["after"])
print(name, len(c["claims"]), [x["kind"] for x in c["unsupported"]], c["unreported"], r["oracle"]["pass"])
print(E.extract_claims("Lent B001 to S0042, but the note could not be saved."))
print(E.extract_claims("I put B001 in the hands of S0042 and wrote it down."))
Output (Python 3.14.6 and 3.12, macOS and Linux, identical):
claim_only 2 ['loan', 'note'] [] False
overreach 2 [] ['note+:audit'] False
wrong_note 2 [] [] False
[{'kind': 'loan', 'book': 'B001', 'student': 'S0042'}]
[]
Reading: lines 1 to 3: for s01, claim_only has two claims, both unsupported, and the oracle fails; overreach has no false claim but an unreported note+:audit; wrong_note raises no flag in the comparison while the oracle still fails. Line 4: the sentence "could not be saved" gives only the loan claim; the note part is skipped because it misses the fixed phrase, not because the extractor understands "not". Line 5: a message worded differently gives an empty list.
8.4 Run the lesson tests
python -m pytest tests/test_l04_endstate.py -v
Result: 13 passed. Read test_reading_through_the_agents_own_tool_changes_the_thing_it_measures, test_a_wrong_note_text_passes_the_claim_comparison_but_not_the_oracle and test_the_effect_log_is_not_a_witness_of_a_good_effect.
8.5 Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
ModuleNotFoundError: lab when running try_l04.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 |
compare gives clean false with no flag |
The extractor found no claim in the message | Read claims; the message has no claim the extractor understands, so nothing was confirmed |
observe raises RuntimeError |
Something changed the state or the log while reading | Find the source of the change during the read; do not catch the error to carry on |
9. Independent exercise
Problem: Four fictional recorded runs (start state, end state, message). Predict what the comparison flags, then write two runs of your own that expose two kinds of mismatch.
Requirements: complete exercises/test_l04_endstate.py:
- TODO 1:
FLAGS: for each run inexercises/ex_runs.json, the pair (list of unsupported claim kinds in order, list of unreported changes in order) thatcomparereturns. - TODO 2:
MY_RUNS: two runs you write,{id, before, after, final_text}. The first has at least one unsupported claim and no unreported change; the second has at least one unreported change and no unsupported claim. Both messages must contain at least one claim the extractor can read. Do not copy a run fromRUNS.
Test data: exercises/ex_runs.json.
Deliverable: the two variables above, in the file exercises/test_l04_endstate.py itself.
Acceptance criteria: python -m pytest exercises/test_l04_endstate.py passes (2 tests), recomputed with lab.endstate. The test does not check that your two runs resemble the behaviour of a real agent.
Hints: TODO 1: for each run, list the claims in the message, then the diff_state of the start and end states, then compare. TODO 2: the first run needs a message that says something the end state does not have; the second needs a change (a note, a loan or a notice) that the message does not mention, while every claim in the message is true.
10. Knowledge check
0/9 done · Results are kept in this browser only.
P02 · True or false
P04 · Select all that apply
P05 · Put in order
P06 · Spot the bug
A colleague verifies "the loan of B004 exists" with the function below. The function returns True even when there is no loan at all, on a fresh ToolLayer. Find the defect.
import json
def loan_exists(layer, book_id):
res = layer.call("get_book", json.dumps({"book_id": book_id}))
return res["structured"]["available"] is FalseP07 · Essay
Write 5-8 sentences (fictional situation): a colleague proposes grading runs only with message_oracle (the message starts with "Done") "because it is quick and easy to read". State two reasons the lab gives for not doing so, and one thing that comparing the message with the state still cannot do.
P09 · Recall
Lesson: L3-M03-L0311. Summary
- Concepts: four relations between message and environment; the message is data to compare, not evidence [R1][R2]; the checker must not change what it measures.
- Skills:
observe,extract_claims,compare,environment_consistent; readunsupportedandunreported. - Traps: treating
cleanas correct; reading the environment through the agent's tool; treating the effect log as a witness for a good effect; forgetting that the extractor reads only fixed phrases [R4]. - Now you can: take a run and ask: what does the message say, what does the environment have, did the reading step change anything, and does the log still match the state.
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: the definition of outcome, the flight-booking example, WebArena's backend state verification |
| 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 (the final database and the replies to the user); did not read the experiments |
| R3 | WebArena: A Realistic Web Environment for Building Autonomous Agents (arXiv 2307.13854) | arXiv (Zhou et al.) | https://arxiv.org/abs/2307.13854 | 2026-11-04 | Read the abstract page and section 3.2 (exact_match, must_include, checking the posted content); did not read the experiments |
| R4 | 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 (the database diff between the start and end states); did not read the appendix on how the diff is computed |
Glossary (English ↔ Tiếng Việt)
| English | Tiếng Việt |
|---|---|
| Claim | Khẳng định: điều lời nhắn nói đã xảy ra |
| Unsupported claim | Khẳng định không có căn cứ: lời nhắn nói, môi trường không cho thấy |
| Unreported change | Thay đổi không được nhắc: môi trường đổi, lời nhắn không nói |
| Read-only observation | Quan sát chỉ-đọc: chụp trạng thái mà không đổi trạng thái hay nhật ký |
| Environment consistency | Tính khớp của môi trường: nhật ký tác động còn khớp trạng thái thật |