Lab 27: who decides each step
- Approved by
- Panaversity ·
You write down who decides each step of Dave Kowalski's month-end review, before you build anything. Then you build the review twice, as a workflow and as an orchestrator with subagents, and measure both against that table. Last, you find three faults from their traces alone. The lab takes 3 sittings, and a free plan can spread them over days.
| Sitting | Do it after | Tasks |
|---|---|---|
| Sitting 1 | 27.1 to 27.5 | Setup, Task 1 |
| Sitting 2 | 27.6 | Tasks 2 and 3 |
| Sitting 3 | 27.7 | Task 4 |
Before you start
Important
The lab's files are not published yet. The download link for brightline-lab-ch27.zip and the answer keys below will work once they are. Until then, read the tasks with the chapter.
The download. Everything starts from brightline-lab-ch27.zip (download it here). It holds the brightline-ap repository at its tag ch26, with this lab's files added, so you need not have done Lab 26.
What you need. Node, Python with uv, git, the GitHub CLI, and Claude Code and Codex, each signed in. Your staging key for the Claude API goes in .secrets/anthropic.env. No key passes through a chat.
The job. It is Wednesday, May 5, 2027, 9:15 a.m. Monday's review passed its check. Now Brightline's outside auditors ask, through Dave, about one invoice, INV-8342. Which steps led the review to call it "a problem"? And would it go through the same steps next month? Dave's three needs for the review are in the kit's README.md. Task 1 reads them with you.
How a task works. Start a fresh session with the named coding agent in brightline-ap/, and give it the task's prompt in plan mode. Write your prediction before the agent shows the result. Check the evidence against What good looks like, then download the answer key. End with a line in ports/ch27.md.
Sitting 1: the table, then two builds
Before you start, answer in a line each: Which three tests decide who owns a step (27.1)? What does code still hold for a step the model keeps (27.1)? After this sitting, you can: read from a trace who decided each step of a run, write an architecture as a table before building, build a workflow whose order code holds, and build an orchestrator whose limits code holds.
New words in this sitting's prompts.
| Word in a prompt | What it means |
|---|---|
| Replay | Read a run from its recorded trace, with no request to the model |
| Scripted session | The file sessions/month-end.md: the same request and the same invoices each time, so two live runs can be compared |
| The table | docs/architecture.md: one row for each step of the review, then four rows for the whole run |
| Run row | One of the four rows for the whole run: when the run stops, what a helper sees, whose notes the run may read, what stays in the window |
| Span | One timed line of a trace: one call to the model or to a tool (21.10) |
| The review check | The check by code in src/hosted/check-triage.ts. It fails a review if an open invoice has no entry, or a problem has no policy line that search_policy returned |
| Owned file | A file only you may change. The agent proposes a change and waits. docs/architecture.md and the worker's instructions are owned files |
settingSources | The setting that says which settings files the worker loads. It is empty here, so no instruction file reaches a subagent (26.5) |
Set up (Claude Code). Unzip the folder, then give the agent this prompt.
Read
README.mdandAGENTS.md. Put this folder under git with a main branch, in one first commit, "Start from the end of Chapter 26", and tag itlab27-start. Install the packages for both languages, asREADME.mdsays. Run every test that needs no key. Then replay Monday's recorded run fromtraces/month-end-pass.jsonl, with no key and no network, and run the review check on it. Show me the request word for word, the number of turns, the number of open invoices, the run's cost and the check's result. Finish by showing me that git tracks nothing in.secrets/.
What good looks like: one commit at the tag lab27-start, and every test passing. The replay shows Dave's sentence, "Tell me which open invoices are a problem, and why, with the policy line for each." The check passes, and the cost is under the $1.00 budget. docs/chapter-27/ holds the concepts as text for your agents.
Note
No run is recorded yet. Monday's run, traces/month-end-pass.jsonl, is not in the kit, so its replay stops and says there is no recorded run. The setup's replay and Task 1's step 1 wait for it. The three broken traces of Task 3 and the fixtures of Task 4 are not recorded either, so those two tasks have nothing to read yet. No file in this lab stands in for a run. Every other step can be done now.
Replay and live runs. npm run replay reads a run back from its trace, and npm run check:review runs the review check on it, with no key and no network. A live run is one run of a build: npm run month-end:workflow or npm run month-end:orchestrator, with npm run connector:month-end running in another terminal. Each prints its limits and its $1.00 budget, and sends nothing until you add --yes. Each refuses to start while its build is still the kit's stub. The tests you write in Tasks 1 and 3 run with npm run test:architecture, and the port's with npm run test:port:py. Your agent runs these commands, and you approve each live run.
Task 1. Build both (Claude Code)
Goal: the table, filled before any code. Then the review as a workflow, and the review as an orchestrator with its limits. Each ends with the review check.
Where: docs/architecture.md first. Then src/workflows/month-end.ts, which is your own code calling the Messages API. Then src/agents/month-end-orchestrator.ts, on the Claude Agent SDK, with the worker in src/sdk/. Step 1 of the first prompt reads Monday's run, which is not recorded yet.
Predict: Monday's worker took the open invoices one at a time. In Monday's trace, what made it do so: a line of your code, or the model?
In plain words. You cannot answer the auditors until you know who decided each step. So you read that from Monday's trace, and write it down. Then you choose each step's owner for the workflow, before the workflow exists. The orchestrator's column is different: the model decides its split, so you fill that column from its trace afterward.
Give the agent the first prompt. It ends with the workflow.
Read 27.1 and 27.2 in
docs/chapter-27/.
- Replay
traces/month-end-pass.jsonl. List each step of the review in the order it ran: list the open invoices, take the next invoice, look up the vendor, look up the purchase order, find the policy line, decide, write the decision, check. Stop there and wait for my prediction. Then mark each step as a call my code started or a tool call the model chose, with the span that shows it.- Open
docs/architecture.md. It is an owned file. Write one row for each step, and fill the column for Monday's run from step 1.- Show me Dave's three needs from
README.md. Then ask me three questions for each step, one step at a time, and write only what I answer. Does this step change with what the worker finds? What does a wrong choice cost, and what would catch it? Must the path be the same every time, or is a record enough?- Ask me who decides each step in the workflow: code, the model or a person. Where I say a step is both known and dependent on what is found, ask me how to split it, and add the rows. For each step I leave to the model, ask me for its own stop, its tools and its check.
- Ask me for the owner and the value of each of the four run rows, for the workflow.
- Now build
src/workflows/month-end.tsfrom its stub, to match my column and nothing else. My code makes every call that I gave to code. It calls the connector's read tools itself. Each step I left to the model is one Messages API call for one invoice, on the model the kit pins, with only the tools and the turn limit I wrote. An invoice that no branch of my code covers is markedneeds_review, with no model call. Keep the stub's spans, one for each call to the model and to the connector.- Tell me the budget and how many requests you expect. Then run
sessions/month-end.mdlive on the workflow, and run the review check. Show me the spans in order, and the cost.
Then give it the second prompt, for the orchestrator.
Read 27.3 and 27.4.
- Build
src/agents/month-end-orchestrator.tsfrom its stub, on the Claude Agent SDK, withsettingSourcesstill empty. The orchestrator gets Dave's request and a short list of subagent definitions.vendor-lookupis one. Propose the others, and for each ask me for its description, its own prompt, and the only tools its step needs. Do not tell the orchestrator when to use a subagent, or how many.- Ask me for each value, then set its limits in code, and show me the line for each: a turn limit, the $1.00 budget, how deep subagents may go, how many may run at once, the built-in
general-purposesubagent turned off, and forks denied. Say whether the orchestrator waits for a subagent's report before it writes a decision, and how you made sure.- Tell me the budget and how many requests you expect. Then run
sessions/month-end.mdlive, and run the review check.- From the run's trace, list each step and who decided it. Mark every step that ran inside a subagent, by the id of the parent's call that started it. Show me each brief the orchestrator wrote, word for word.
- Fill the orchestrator's column in
docs/architecture.mdfrom that trace, and its four run rows from the limits in step 2. Show me the diff and wait.- Add to
ports/ch27.md: my prediction, and each build's check result and cost.
What good looks like: in Monday's column, the model decided every step but the check. Each was a tool call it chose, or its own choice of which invoice to take next. Your workflow column gives code the steps that are known before the run: listing the invoices, taking the next one, and the two lookups by id. The model keeps the step of finding the policy line and deciding, with search_policy as its only tool, a turn limit and the review check. The table has six columns, with "who decides" written three times, and four run rows under the steps. The workflow's spans show your code's calls in the order your code fixed. The orchestrator's trace shows a split that you did not write: the model chose when to start a subagent and what to tell it.1 The built-in subagent is off and forks are denied, so the list of subagents is yours.1 Both runs pass the check, under $1.00 each. Your prediction: the model. The instructions asked for every open invoice, and no line of code made it happen.
Checkpoint: docs/architecture.md has three "who decides" columns filled, and each build passed the review check once.
Saves: the table in docs/architecture.md, src/workflows/month-end.ts, src/agents/month-end-orchestrator.ts with its subagent definitions and limits, and your first lines in ports/ch27.md.
Check it now. Download Task 1's answer key.
Checkpoint 1: the table before the code. Before Sitting 2, check that you can do these without looking back.
- Say who decided each step on Monday, and how the trace shows it.
- Say which steps you gave to code in the workflow, and which test decided each.
- Name the limits your code holds on the orchestrator, and the two decisions the model has there that it does not have in the workflow.
Sitting 2: measure, choose, diagnose
Before you start, answer in a line each: What two things can "audit" mean (27.1)? What are the three steps of a diagnosis (27.6)? After this sitting, you can: compare two designs on measured runs, justify a choice against a business's audit needs and say its price, and name a fault's row and its pattern from a trace before reading any code.
New words in this sitting's prompts.
| Word in a prompt | What it means |
|---|---|
| In the same place | A step that ran at the same position in the order, in both runs of one build |
| The unusual vendor | One invoice from a vendor that no branch of your workflow covers: INV-8344, in data-unusual-vendor/. The kit's README.md says how to run it |
needs_review | The status of a result that code would not accept. It waits for Ana Morales and is never posted as done |
| Limit stop | A run that ended because it reached a turn limit or a budget, not because the model finished (22.6) |
| Missing or misapplied | A pattern is missing when nobody chose the row's owner. It is misapplied when the row has an owner and the wrong value (27.6) |
Task 2. Compare and choose (Claude Code)
Goal: two runs of each build on the same invoices, their results in the table, the audit need answered row by row, and your choice written with its price.
Where: both builds, then docs/architecture.md.
Predict: you run the workflow twice on the same invoices. Inside the step where the model finds the policy line, will its searches be the same both times?
In plain words. One run shows what a design did once. The auditors asked about next month. So you run each build a second time, and compare the order of steps, not the wording of the answers. Then you give each build an invoice that nobody planned for.
Read 27.1 and 27.5.
- Tell me the budget and how many requests you expect. Then run
sessions/month-end.mdlive once more on each build, so that each has two runs. Run the review check on both.- For each build and each step of the table, say whether the step ran in the same place in both runs. Stop there and wait for my prediction. Then show me, for one invoice, the workflow's spans from both runs side by side, with each
search_policyquery.- Add those results to
docs/architecture.md: for each step, one cell for each build.- Run each build once on the unusual vendor's invoice. It is served by its own connector,
npm run connector:unusual, and each build takes that connector's address with--connector, as the kit'sREADME.mddescribes. Each build then reviews that one invoice only. Show me what each build did with it, step by step, and what the review check said about that invoice.- Under the table, write one line for each build: the check's result, the unusual vendor's result, and the cost of each run.
- Now the audit need, as two questions. For each build, and for the invoice the auditors asked about, which
README.mdnames: did the same steps run in the same order in both runs? Is there a record of each step, with the values it used? Answer from the traces, and quote the spans.- The hosted worker gets no build here. For each row of the table, tell me whether my code could hold that row if the review ran as one hosted session, and which sentence of 27.5 says so.
- Ask me for my choice between the two builds, and for its price in my own words. Write both at the end of
docs/architecture.md, as a diff for my approval. Then ask me for my answer to the auditors' two questions, and add it toports/ch27.mdwith my prediction.
What good looks like: four live runs, and each passes the check. The workflow's code steps ran in the same place both times, because your code fixed their order. Inside the model's step the search queries can differ, and its one tool, its turn limit and the check still limit it. Your table says whether the orchestrator's two runs took the same path. A different path is not a failure: both of its runs are recorded. A record answers the auditors' first question for either build. Only steps that code holds answer their second. The workflow marks the unusual vendor's invoice needs_review, and it waits for Ana. The review check passes that entry, because the invoice has one, and a person decides it. The orchestrator handles it by a path of its own. Your choice names its price. For the workflow, the price is every case no branch covers. For the orchestrator, it is a higher cost and a path that nothing promises. Your prediction: not always. A model's wording changes from run to run, so the step the model keeps cannot promise the same searches.
Checkpoint: the table has a result for each step and each build, one line of results under it for each build, and your choice with its price.
Saves: the finished docs/architecture.md, the four runs' traces, and your answer to the auditors in ports/ch27.md.
Check it now. Download Task 2's answer key.
Task 3. Diagnose three broken traces (Claude Code)
Goal: each of three faults named from its trace and placed on a run row of your table, before you read any code. Then the same row set in your own two builds, with one test for each fault.
Where: the three traces in traces/broken/, trace-1.jsonl to trace-3.jsonl, with no key and no network. Their names say nothing of the fault. Then your own builds. The kit has no broken code. The three traces are not recorded yet, so this task waits for them.
Predict: a builder starts a run on the Claude Agent SDK and sets no limits at all. The model repeats one tool call again and again. What ends the run?
In plain words. A broken run is one where a decision about the whole run had no owner, or the wrong value. The trace shows the symptom. Your table has the row. You make the diagnosis from those two alone, and you open the code only to fix it.
Read 27.6. Do not open any source file until step 4.
- Replay the first trace in
traces/broken/. Show me its spans as a table, with each tool call's name and input, but not yet how the run ended. Stop there and wait for my prediction. Then show me how it ended, ask me four things and wait: the failure's name, if 24.7 has one for it. Where it began (24.8). Which run row of my table it belongs to. And whether the pattern is missing or misapplied. Tell me only whether the trace supports each answer, and quote the spans.- Do the same for the second trace. Show me the first request that the subagent received, part by part, and mark what in it came from the parent's conversation.
- Do the same for the third trace. Show me each fact in the final answer, and beside it the tool result of this company that holds it, or "none".
- Now open my two builds. For each of the three run rows, show me the line in each build that sets it, or tell me that no line does.
- Set every row that has no owner, as a diff for my approval. Then write one test for each fault. First: a run whose tool never gives a final result ends at my turn limit, with a limit stop. Second: a subagent's first request holds nothing from the parent's conversation. Third: a run for one company never reads another company's memory folder.
- Run every test that needs no key, and run the review check on both builds once more.
- Write the three faults into
docs/architecture.md, each beside its run row, with the pattern that corrects it. Add my four answers for each trace toports/ch27.md, as I gave them, with my prediction.
What good looks like: you named each fault before step 4. The first trace repeats one call, and it has no limit stop. Its row is "when the run stops", and its pattern is tool-use loop termination. The second trace shows a subagent whose first request holds the parent's conversation. Its row is "what a helper sees", and its pattern is subagent isolation (26.5). The third trace shows a note saved for Cedar Ridge in a Brightline run, so the answer holds a fact that no Brightline tool result holds. Its row is "whose notes the run may read", and its pattern is memory, with one store for each person and company (26.6). The third has a name in 24.7's list, hallucination. The first two have none, and you invented none. In your own builds, the memory handler already kept one folder for one person and one company, so the new test there is for a company. All three tests pass, and both builds still pass the check. Your prediction: nothing ends it. On that SDK, the turn limit and the budget are both "No limit" unless you set them.2
Checkpoint: three faults named from their traces, three tests passing, and both builds still passing the review check.
Saves: the three faults beside their rows in docs/architecture.md, three new tests, any limit you added, and your answers in ports/ch27.md.
Check it now. Download Task 3's answer key.
Checkpoint 2: the row nobody decided. Before Sitting 3, check that you can do these without looking back.
- Say what the auditors asked, and which half a record answers for either build.
- Say what each build did with the unusual vendor's invoice, and who decides it now.
- For each broken trace, say what the trace showed, its run row, and the pattern that corrects it.
Sitting 3: the port
Before you start, answer in a line each: On the OpenAI Agents SDK, which keeps control of the conversation, an agent used as a tool or a handoff (27.7)? What does the next agent see after a handoff with no filter? After this sitting, you can: rebuild an orchestrator on a second SDK with every limit passed by your own code, and show from a request what a second agent received.
New words in this sitting's prompts.
| Word in a prompt | What it means |
|---|---|
| Fixture | A saved response that a test feeds to the code, so the test needs no key |
| Manager | The agent that keeps control of the conversation and calls other agents as tools. It is this SDK's form of an orchestrator |
| Agent as a tool | One agent offered to another as a tool. Only its answer comes back (22.4) |
| Handoff | Passing the conversation to another agent, which takes over (22.4) |
Task 4. The port (Codex)
Goal: the orchestrator on the OpenAI Agents SDK, with agents as tools and a turn limit your code passes. Then one handoff, and what the second agent received.
Where: the port's folder, ports/openai/month_end/, in Python, run from the fixtures in tests/fixtures/openai/month-end/, with no key. The folder holds the kit's replay model, which answers from a fixture and keeps every request it receives, with two tests. The fixtures are not recorded yet, so this task waits for them.
Predict: you change one specialist from a tool into a handoff, and set no filter. What does that agent's first request hold?
In plain words. The table does not change when the SDK does. You rebuild the same column, "the orchestrator", with another vendor's parts. Then you make one change on purpose, and read in a request what it did to one run row.
Read 27.7. Use only the fixtures in
tests/fixtures/openai/month-end/. Send no live request.
- Build the month-end orchestrator on the OpenAI Agents SDK. One manager agent gets Dave's request. Each subagent from Task 1 becomes a specialist agent that the manager calls as a tool, with the same prompt and the same tools.
- Pass the turn limit yourself on every run, with the value from my table. Do not rest on the SDK's default. Write a test from a fixture: a run that passes the limit ends with the SDK's own error for it, and my code records a limit stop.
- Run the port on the fixtures. Run the review check on its answer. From the SDK's trace, list each step and who decided it.
- Show me the first request one specialist received, part by part. Mark anything that came from the manager's conversation.
- Now change that one specialist into a handoff, with no filter, in a copy of the port. Run it on the same fixture. Stop there and wait for my prediction. Then show me the first request the second agent received, beside step 4's.
- Delete the copy. Add a table to
ports/ch27.md, with one row for each of the two forms: the SDK and its version, today's date, who kept control of the conversation, and what the second agent received.
What good looks like: the manager calls each specialist as a tool and keeps control of the conversation.3 Your code passes max_turns, and the test shows the SDK's MaxTurnsExceeded error recorded as a limit stop.4 The review check runs on the port's answer unchanged, because it reads the answer and the tool results, and never the SDK. As a tool, the specialist's first request holds what the manager passed. After the handoff, the second agent's first request holds the earlier conversation.5 That is the second broken trace's fault, on another vendor's SDK. Your prediction: the whole conversation so far. A handoff shares it unless you set an input_filter.5
Finish: the pull request and the tag.
Update
README.mdanddocs/deploy.mdwith the workflow, the orchestrator and its limits, and the three new tests. Run/code-reviewand/security-reviewon the branch, and fix or answer every finding. Open the pull request, wait for its checks, and show me both reviews. I will merge. Then tag the mergech27, push the tag, and from a clean clone of the tag run every test that needs no key.
Checkpoint: the tag ch27 passes from a clean clone, and ports/ch27.md has both rows of the port.
Saves: the port and its test, the port's table in ports/ch27.md, and the tag ch27.
Check it now. Download Task 4's answer key.
Checkpoint 3: the same table on another SDK. Check that you can do these without looking back.
- Say which form on the OpenAI Agents SDK matches an orchestrator, and why.
- Say what the second agent received after the handoff, and which run row that is.
- Say which limit your code passed on both SDKs, and why you did not depend on a default.
Required and optional
Required: the setup and Tasks 1 to 3. Practice: Task 4, on the fixtures.
Apply it to your vertical (optional)
Pick one job that your own business would give a worker, such as a week of claims or a day of orders. Write its steps as rows. For each step, answer the three questions. Does it change with what the worker finds? What does a wrong choice cost, and what would catch it? Must the path be the same every time? Then write who decides each step. Add the four run rows, and mark every row whose owner you cannot name.
If something goes wrong
| What you see | Why | What to do |
|---|---|---|
| Monday's column says "code" for a lookup | The step ran, but the model chose the call | Read the span: a tool call in the model's turn is the model's decision (Task 1) |
| The workflow's spans are missing a step | The call was made without the stub's span | Write one span for each call to the model and to the connector (Task 1) |
| The orchestrator starts a subagent you did not define | The built-in general-purpose subagent is still on | Turn it off, as the second prompt's step 2 says (Task 1) |
| The orchestrator writes a decision before a subagent reports | The subagent ran in the background | Make the orchestrator wait for the report, and say so in its instructions (Task 1) |
| Two runs of the workflow differ in wording | A model's wording changes from run to run | Compare the order of steps and the check's results, not the text (Task 2) |
| The test for the first fault never ends | The test's own run has no turn limit | Pass the limit in the test, and assert the limit stop (Task 3) |
| The port's check fails on an invoice the Claude build passed | The specialist's prompt or tools differ from Task 1's | Compare the two definitions line by line (Task 4) |
Artifact checklist
-
docs/architecture.md: every step and the four run rows, three "who decides" columns, a result for each step and each build, and your choice with its price -
src/workflows/month-end.ts, with a span for each call -
src/agents/month-end-orchestrator.ts, with its subagent definitions and its limits in code - Two recorded runs of each build, each with the review check's result and its cost
- Three new tests, one for each broken trace's fault
- The port on the OpenAI Agents SDK, with its turn-limit test
-
ports/ch27.md, with every prediction, your answer to the auditors, your four answers for each broken trace, and the port's two rows - The tag
ch27
Exam notes
Sources
- Owner
- Panaversity