Capstone - Milestone 1: brief and design of the agent testing framework

Study time
≈ 4 h (estimate)
Needs
L3-M07-L05
Updated
2026-11-05

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L3-M08 (capstone) · Duration: ~4 hours (estimate) · Previous: L3-M07-L05 · Next: Milestone 2

1. Introduction

The seven modules of Level 3 each teach one piece of testing an agent: the architecture and risk map (M01), tools as a contract and a sandbox with an effect log (M02), task scenarios and the end state (M03), trajectories (M04), state and session isolation (M05), fault injection, idempotency, pass^k and budgets (M06), indirect injection, permissions and approval (M07). The capstone puts them together into one real job: build an agent testing framework and use it to provide evidence for a release decision.

The product is the NhaKhoa Mini booking assistant (a fictional dental clinic; the agent is simulated with Vietnamese sentence rules, no real model), in the folder capstone-projects/project-03-ai-agent-testing-framework/. The assistant understands a few sentence patterns, calls ten tools (Vietnamese "công cụ": search for slots, book, cancel, send a message, read a referral note, request approval and refund a deposit) and then replies. The stable build is in production; the rc build is about to be released. The question of the capstone: does rc keep clauses C1-C11 the way stable does, and what trace-level evidence supports the answer?

At the first milestone, you do not write a single line of framework code. This milestone answers three questions: what to test (clauses and risks across five layers), how to test it (which oracle reads where: the world, the trace or the reply) and what to build (the data flow, what is deterministic, the decision policy). The output is a reviewed design document and notes from exploring the product as a black box.

2. Objectives

  1. Read clauses C1-C11 and requirements R1-R20, and state for each clause which layer (end_state, trajectory, state, reliability, security) can see it being violated.
  2. Explore the product as a black box with explore.py, to understand the conversation format and the tool calls, not to take expectations from it.
  3. Build a prioritised risk table that covers all five test suites, and a traceability table from C1-C11, R1-R20 to modules, oracles and planned scenarios.
  4. Design the framework's data flow and write in advance the decision policy: what the gate does, when it HOLDs, who decides.
  5. Defend the design in a short review session, with questions for the product owner.

3. Prerequisites

  • L3-M01 to L3-M07. What you most need to remember: risks attached to nodes and edges of the map (L3-M01-L05), the append-only effect log and idempotency keys (L3-M02-L04), the side-effect ledger that only records effects actually applied (L3-M06-L02), the end state read from the environment and not from the reply (L3-M03-L04), pass^k (L3-M06-L03) and a gate that recomputes from the runs (L3-M06-L05).
  • Read the capstone's README.md, requirements.md (sections A to F), data/README.md, data/policy.json, rubric.md, design-doc.template.md and starter/README.md, as well as product/README.md (how a harness drives the assistant).
  • Python 3.14 or 3.12 and pytest==9.2.0 in a virtual environment (see the project README).
  • Disambiguation. In the capstone, a trial (Vietnamese "lần chạy") is one complete run of one scenario on one build with one seed, as in the "lần chạy" of L3-M06-L03; k = 5 trials are the five seeds. It differs from an attempt ("lần thử"): one send of one tool call, for example a call made again after a transient error (L3-M06-L02). The sandbox's side-effect ledger ("sổ tác động") only records successful writes that changed something (the meaning of L3-M06-L02), unlike the effect log of L3-M02-L04, which records every call. Tools ("công cụ") are the tools of the earlier modules.

4. How to do this milestone

4.1 The question and the shape of the evidence

Your framework does not answer "is the agent good". It answers a narrower question that can be checked: for each clause C1-C11, is there a scenario that passes on every seed on stable and fails on rc, and which event in the trace shows it? A good finding points at a specific run file (out/runs/rc/<mã kịch bản>/<seed>.json), at event indices in trace and at effect ids in effects (the rubric calls this trace-level evidence). The grader opens that file and must see exactly what you say.

Two ideas come from earlier modules. Anthropic's article on agent evaluation distinguishes the transcript (the complete record of a trial, including tool calls and intermediate results) from the outcome (the final state in the environment): a flight-booking agent may say "booked" while the outcome is whether or not a reservation exists in the database [R1]. τ-bench grades by comparing the final database state with the annotated goal state [R2]. In the capstone, the outcome is the sandbox's final snapshot and side-effect ledger; the transcript is the trace that the Recorder writes. The assistant's reply is only secondary evidence: every scenario must have at least one check that reads the world or the trace (R2).

4.2 Expectations come from the clauses, and the black-box rule

stable is the build in production, not the correct build. If you take stable's behaviour as the expectation, the framework can only detect "different from stable". Every expectation must trace back to C1-C11 (requirements.md section A) or to data/ (the clinic, the tool contracts, the policy). stable has two legitimate roles: the gate's baseline (a scenario that stable fails is the reason BASELINE_FAILS) and a test of your scenario: if stable fails a scenario, suspect the scenario first (wrong oracle, wrong setup, wrong check parameters), and only then the product.

The project's black-box rule: everything you need to drive the assistant is in product/README.md; do not read the code in product/nhakhoa_agent/ and do not unpack builds.dat to look for problems. This is a rule, not a lock: the code can be read if you try. The reason is not only fairness. The skill being graded is designing scenarios that find problems from the clauses; a problem found by reading the source code does not count (rubric.md). You may read the code after a scenario has found something, to explain the cause in the report.

4.3 Risks first, checks second, across five layers

The risk table tells you where to put the effort, and it must cover all five suites of data/policy.json (end_state, trajectory, state, reliability, security; AC1.3 requires at least six rows, each with the priority cao, trung bình or thấp). For each clause, ask: where would this violation show? Some violations only show in the end state; some leave the end state looking right while the path is wrong (L3-M04-L01); some only show at a late turn of a long conversation or in the second session (L3-M05); some only show under a transient error or on one seed in five (L3-M06); some only show when the data contains instructions or when the user asks for something beyond their rights (L3-M07).

Three example rows, deliberately chosen as risks of the framework itself and not of rc (that part is your job):

Risk Clause Suite Priority How it is detected (oracle)
A scenario that only reads the reply passes when the assistant says "Đã đặt lịch" (booked) and no appointment exists C1 end_state cao appointments reads the final snapshot; scenario.validate returns NO_WORLD_ORACLE for a scenario with only reply checks
An injected fault never fires, so a reliability scenario passes without testing anything C6 reliability cao the record's faults.unfired must be empty; lint and the gate (FAULT_NOT_FIRED) block it
no_leak scans with an empty canary list and is therefore always clean C5 state trung bình automatic canaries from the records and appointments of every other patient; a synthetic record with a leak must make the check fail

"We will be careful" is not a detection method. A detection method is something that runs and can produce a fail.

4.4 Traceability and architecture

The traceability table (section 3 of the template) has one row for each of C1-C11 and each of R1-R20; each row has the suite or module, the oracle (where the expectation comes from, where it is read), the planned scenario and a note (AC1.2 checks that no cell is empty). A C row says how you will test the product; an R row says how your framework meets the requirement. Three example R rows:

ID Suite or module Oracle Planned scenario Note
R1 scenario.py the error codes of requirements.md D1; a bad spec is rejected, not repaired the broken specs in my tests load_dir rejects both files with the same id
R5 trace.py faults.fired has the event of each fault; unfired is empty ex-03-search-unavailable and my fault-injection scenarios the timeout_after_commit fault is only for write tools
R16 report.py (gate) the reason codes of D3; HOLD on broken data hand-edited records in tests the gate never raises

The project has already chosen most of the architecture (pipeline.py connects the steps, you write the functions). Section 4 of the design describes the flow in your own words:

scenarios/*.json --scenario.load_dir--> spec hợp lệ (spec lỗi: scenario_errors)
spec + phiên bản + seed --harness.run_scenario--> World (sandbox) + Recorder (trace, lỗi tiêm) + Assistant
                        --> bản ghi lần chạy --trace.lint_trace + checks.evaluate--> out/runs/<phiên bản>/<mã>/<seed>.json
mọi bản ghi --pipeline.run_all--> out/results.json (rows, reliability, budget)
out/runs + results --report.build_report + report.gate--> out/report.json, out/gate.json, out/report.md
out/report.md --> người quyết định --> deliverables/decision.md

State clearly what is deterministic (everything, per (scenario, build, seed): a logical clock instead of the real clock, no timestamps, out/ rebuilds byte for byte; R20) and what is simulated (latency, tokens and cost are exercise numbers).

4.5 A decision policy written in advance

Write it before you see the results of rc (L2-M07-L01 on pre-registered plans), because after seeing the results it is very hard to stay objective when setting thresholds. Section 6 of the design needs three points:

  • The gate only reports HOLD or READY_FOR_REVIEW. READY_FOR_REVIEW does not mean "release": it means the evidence is consistent enough for a person to read. The gate never records a release decision.
  • The gate fails closed. A missing run file, a record that fails lint, a fault that never fired, a check that gives a different result when re-run, a report that does not match the run files, a scenario set below the minimum: all of these are HOLD, and the gate never raises (R16).
  • A person decides. A named person reads the report and writes Quyết định: as KHÔNG PHÁT HÀNH, PHÁT HÀNH or PHÁT HÀNH CÓ ĐIỀU KIỆN (R17). A decision that goes against a HOLD needs a Ghi đè cổng: line with a written reason.

The thresholds are in data/policy.json: five seeds s1-s5 (k = 5 trials per scenario), budgets p95_turn_ms 4000 and mean_turn_cost 2000, min_scenarios 20, min_per_suite 3, min_adversarial 4. The design says why those thresholds are reasonable or worth questioning; changing them needs a written reason and the decision maker's signature (rubric.md). That is the place for questions to the product owner, for example: "Are five seeds enough to see a failure that happens once in ten trials, and who decides the number of seeds?".

5. Hands-on: exploring the product

From the root of the repository, go into starter/ (the folder you work in for the whole capstone) and run:

cd academy-content/capstone-projects/project-03-ai-agent-testing-framework/starter
python ../explore.py stable --patient P01 "chỉ đặt với bác sĩ Bình" "giờ mở cửa thế nào?" "đặt lịch ngày 2026-12-03 buổi sáng"
python ../explore.py stable --patient P03 "xem lịch hẹn của tôi"
python ../explore.py stable --patient P02 "hoàn cọc lịch A0002"

Output (copied from a real run, 2026-11-05, Python 3.14.6 and 3.12.3 on Linux, identical):

> chỉ đặt với bác sĩ Bình
< Tôi đã ghi nhận yêu cầu của bạn.
  (1 bước model, 394 ms model và chờ, mô phỏng)
> giờ mở cửa thế nào?
< Phòng khám mở cửa từ 8:00 đến 17:00, thứ Hai đến thứ Bảy.
  (1 bước model, 299 ms model và chờ, mô phỏng)
> đặt lịch ngày 2026-12-03 buổi sáng
    công cụ get_patient {"patient_id": "P01"} -> ok
    công cụ search_slots {"date": "2026-12-03", "period": "sáng", "dentist": "D2"} -> ok
    công cụ book_appointment {"patient_id": "P01", "slot_id": "SL-1203-D2-0900", "idempotency_key": "P01-S1-t3-SL-1203-D2-0900"} -> ok
    công cụ send_sms {"to": "0900010001", "text": "NhaKhoa Mini: lịch hẹn mã A0006 ngày 2026-12-03 lúc 09:00 với bác sĩ Bình."} -> ok
      (SMS giả, chỉ in ra, không gửi đi) tới 0900010001: NhaKhoa Mini: lịch hẹn mã A0006 ngày 2026-12-03 lúc 09:00 với bác sĩ Bình.
< Đã đặt lịch A0006 ngày 2026-12-03 lúc 09:00 với bác sĩ Bình.
  (5 bước model, 1599 ms model và chờ, mô phỏng)
> xem lịch hẹn của tôi
    công cụ get_patient {"patient_id": "P03"} -> ok
    công cụ list_appointments {"patient_id": "P03"} -> ok
< Lịch hẹn của Lê Thu Hà: A0003 ngày 2026-12-02 lúc 10:00 với bác sĩ An.
  (3 bước model, 1032 ms model và chờ, mô phỏng)
> hoàn cọc lịch A0002
    công cụ get_appointment {"appointment_id": "A0002"} -> ok
    công cụ request_approval {"action": "refund_deposit", "appointment_id": "A0002"} -> ok
< Tôi đã gửi yêu cầu hoàn cọc lịch hẹn A0002 cho lễ tân duyệt (mã AP-demo).
  (3 bước model, 1006 ms model và chờ, mô phỏng)

What you can read from it, and which clause it touches:

  • The preference stated at turn 1 is used at turn 3: search_slots has "dentist": "D2" (C4). The filler turn "giờ mở cửa" (opening hours) calls no tool (requirements.md section B).
  • Doctor Bình's 08:00 slot on 2026-12-03 already has appointment A0004 in data/clinic.json, so the earliest free slot is 09:00 (C1). The confirmation SMS goes to the number 0900010001 in P01's record (C3).
  • The idempotency key has the shape P01-S1-t3-<khung> (khung = slot): patient, session, turn, slot. That is an observation of the format; the mechanism that keeps the key is the job of your sandbox (R4).
  • Listing P03's appointments only mentions P03's data (C5). The refund only reaches the approval request; request_approval returns pending, so there is no refund_deposit (C10).

Three things to note alongside. One: explore.py uses an in-memory demo environment (product/nhakhoa_agent/demo_env.py), not the test sandbox: it does not check arguments, does not keep keys, does not inject faults (which is why the approval id is AP-demo). Two: one run with one seed proves nothing yet; try --seed s2 ... s5. Three: AC1.8 requires you to explore both builds. Run your own commands on rc; this lesson deliberately does not print any rc output: that observation, and the risk hypotheses you draw from it, are your part of the work. Write each command as one line in deliverables/explore-notes.md, with the clause it touches, in the form AC1.8 reads:

- `python ../explore.py stable --patient P03 "xem lịch hẹn của tôi"`: chỉ thấy A0003 của chính P03 (C5); 2 công cụ, đều là lệnh đọc (C11)

(run from starter/, so the command has ../explore.py). Then look at the map of work for milestones 2 to 4, still in starter/:

python -m pytest

With an untouched starter, the last line is 150 failed, 2 passed, 14 errors in 0.52s (Python 3.14.6, Linux; 3.12.3 gives the same counts; the time depends on the machine) and every failure has a message starting with TODO(M1) ... TODO(M4), for example TODO(M1): write deliverables/design.md from design-doc.template.md. Milestone 1 only needs tests/test_m1_design.py to be green.

6. QA perspective

  • What can go wrong at this milestone: writing the framework before knowing the risks; expectations copied from stable's output; a risk table with only end_state risks; a traceability table with rows whose oracle cell only says "check the result"; a decision policy written after seeing rc; forgetting that every number is simulated; reading the product's code "to save time".
  • Design for blind spots. In each line of section 5 (the strategy per layer), write one sentence "this check does not see ...". An example is already in a docstring: order passes when the after tool is never called, so it must be paired with a state check. Level 3 of the rubric's suites requires every check to have a recorded blind spot and a control scenario.
  • Design review: ask someone to read it for 20 minutes, and write their comments and how you handled them into section 8 of the template (AC1.6).

7. Real-world scenario

Scenario (fictional): "the test suite stayed green for a whole quarter". A team has a reliability suite for a customer-support agent: each scenario injects a timeout into the payment tool. The suite stayed green for a whole quarter. After an incident, someone noticed that the tool name in the fault configuration had a one-letter typo: the fault had never fired, and the gate only counted "did any check fail". Nobody misread the results; the design had never asked "how do we know the check actually reached the thing it wants to test". In the capstone, that question has an answer in the requirements: R5 records which fault fired at which event, pipeline.run_record treats an unfired fault as a fail, and the gate has the reason FAULT_NOT_FIRED. Your design should ask questions of the same kind for each suite: are the canaries really in the data, does the trajectory check see a blocked call, does the budget have data.

8. Milestone 1 deliverable

  1. starter/deliverables/design.md following design-doc.template.md: scope, risks, traceability for C1-C11 and R1-R20, architecture, strategy per layer, decision policy, questions for the product owner, review result.
  2. starter/deliverables/explore-notes.md: at least four bullet lines, each with the exact `python ../explore.py ...` command you ran and one clause C1-C11; with commands on stable and commands on rc.

Criteria: pass tests/test_m1_design.py (AC1.1-AC1.8): all eight sections ## 1. to ## 8. in order; section 3 has one row for each of C1-C11 and R1-R20, with no empty cell; section 2 has at least six risks, each with a priority, and names all five suites; the design mentions HOLD, READY_FOR_REVIEW, "người quyết định" (the person who decides), sandbox, simulation ("mô phỏng") and seed; section 7 has at least two questions ending in ?; section 8 has one fully filled review row; no TODO is left, no <...> phrase at all (also when you copy a sample path such as out/runs/rc/<mã>/<seed>.json: write the real name or MÃ, SEED), and no empty template line (a line with only - or a bullet line ending in :). The tests only check structure; the grader reads the content (the rubric's design dimension).

9. Self-check questions

0/11 done · Results are kept in this browser only.

P02 · True or false

One of your new scenarios fails on seed s3 on stable. According to §4.2, the first conclusion should be: stable has a bug, and you record it as a finding.

P03 · Select all that apply

The example scenario starter/scenarios/ex-01-book-morning.json has three checks. Select every check that reads the world (the sandbox's snapshot or side-effect ledger), in the sense of §4.1 and R2.

P04 · Fill in the blank

According to data/policy.json (§4.5): each scenario runs with ___ seeds; the scenario set needs at least ___ scenarios, of which at least ___ are adversarial; the p95 latency budget per turn is ___ ms.

P05 · Match

Match each test suite with the kind of violation that §4.3 says it can see.

P07 · Put in order

Put the framework's data flow in order according to §4.4, from the scenario files to the person who decides.

  1. report.build_report and report.gate recompute from the run files and write out/report.md
  2. scenario.load_dir reads scenarios/*.json and rejects bad specs
  3. trace.lint_trace and checks.evaluate check the run record, then the record is written into out/runs/
  4. A person reads the report and signs deliverables/decision.md
  5. harness.run_scenario runs a spec in a fresh World and Recorder with one build and one seed
  6. pipeline.run_all writes out/results.json with rows, reliability and budget

P08 · Recall

Lesson: L3-M01-L05

L3-M01-L05 §5.3: the example map has test_coverage equal to 5/8. What does that number tell you?

P09 · Essay

The product owner asks: "Are five seeds enough to see a failure that only happens about once in ten trials, and who decides the number of seeds?" Write a 5-8 sentence answer for section 7 of the design.

P11 · True or false

According to §5, explore.py is not the test sandbox: it does not check arguments, does not keep idempotency keys and does not inject faults, so the approval id it prints (AP-demo) is not the id your sandbox will issue.

10. Summary

  • Milestone 1 answers "what to test, how to test it, what to build" before writing the framework.
  • Trace-level evidence is a run file, event indices and effect ids; the assistant's reply is only secondary evidence.
  • Expectations come from C1-C11 and data/; stable is the baseline and a test of your scenarios; the product is a black box.
  • Risks cover five layers; the decision policy (the gate only reports HOLD or READY_FOR_REVIEW, fails closed, a person decides) is written before seeing rc.

11. References

The capstone mostly reuses the sources of L3-M01 to L3-M07; the module's new sources: references.md.