Module 08D: Projects
Starter projects are guided step by step and suit freshers. Stretch projects are open-ended, add production concerns, and suit experienced readers.
One project, and it is an optional stretch: the orchestrator and subagent research system (08D.P1). It runs keylessly. The orchestrator, the subagents, the scripted fake models, the nested trace and the cost accounting are all pure Python over in-memory fake data, so you can finish the "Done when" checklist without a single API key. Hosted providers are the stretch goal once you have keys; lesson 08D.3 shows where they plug in.
What the fakes can and cannot tell you. Scripted models replay canned replies, so your tests prove the plumbing (delegation, isolation, termination, trace shape, cost totals) deterministically. They cannot tell you how real models will split the work or how often a live run fails. Every "expected output" below is labelled illustrative. That gap is what the repeated-run reliability numbers and failure injection in the project are for.
First time? The project needs no shared setup: multi_agent.py and test_multi_agent.py from 08D.3 are self-contained and use only the standard library. Make a fresh folder, for example uv init multi-agent --bare --python 3.13 && cd multi-agent, and run scripts with uv run python file.py and tests with uv run pytest -q. The single-agent projects are in Module 08A.
You will reuse lesson files rather than reinvent them. Copy these from 08D.3 exactly as printed there: multi_agent.py and test_multi_agent.py.
Stretch (optional): Orchestrator–subagent research system#
Goal: Take 08D.3's from-scratch orchestrator–subagent research system and push it toward production: a third worker spec, a readable nested trace, real cost accounting, repeated-run reliability numbers, and deliberate failure injection — the multi-agent counterpart of the workflow agent above.
What you'll practise:
- The orchestrator–subagent architecture: lead plans, bounded parallel workers with isolated context, condensed results returned, synthesis with citations (lesson 08D.3, 2.1, 6.2)
- Delegation briefs a subagent can't misread — the five required elements (lesson 08D.3, 3.1)
- Nested traces:
agent_start/agent_endpairs,delegationevents withbrief_sha, per-agent usage (lesson 08D.3, 3.8) - Cost accounting across agents and the four taxes (lesson 08D.3, 1.2, 3.7)
- Failure containment: worker budget exhaustion and model errors must not sink the run (lesson 08D.3, 3.6)
- When multi-agent earns its place — and the decision table for saying no (lesson 08D.3, 1.3, 2.11)
Setup: stdlib only — multi_agent.py and test_multi_agent.py from 08D.3 are self-contained (they re-implement the loop in multi-agent-aware form; nothing imports 08A.2's files). uv add pydantic only if you add structured outputs.
Steps:
- Run the lesson's build.
python multi_agent.pythenpython test_multi_agent.py. Read the trace output against 08D.3, 6.2's walkthrough: three agent runs (lead + two workers), nestedmodel_call/tool_callevents,delegationevents carryingbrief_sha. - Extend the cast. Add a third subtask — e.g.
s3, "quantization trade-offs" — to the lead's planned JSON inSCRIPT["lead"][0]and toLEAD_PROMPT's example plan, and give it a"worker-s3"entry inSCRIPT(worker names areworker-<subtask id>). Runmain()and confirmreport["results"]has three entries; then constructResearchOrchestrator(runtime, max_parallel=2)and check the third worker waits for a free slot (the defaultmax_parallel=3lets all three run at once, so it would not show the bound). - Make delegation briefs explicit. Write the bad brief ("research vector databases") and the good brief (all five elements from 3.1) for one subtask; diff what each worker's
brief_shahashes and predict which failure modes each produces — then check against the lesson's reported Anthropic bugs. - Cost accounting.
ScriptedModelbills zero, so compute a shadow cost: countmodel_callevents per agent in the trace, multiply by an assumed per-call token cost from a price table you write down (label it illustrative, per the 03.7 pattern), and produce the "this run cost ≈ N× a single-agent run" comparison the lesson's exercise 1 asks for. - Failure injection. Do the lesson's exercises 4–5 as tests: give
worker-s1a script calling a nonexistent tool and confirm the run still completes with an error result the model can read; giveworker-s2an endlessweb_searchloop and confirmstatus == "budget_exhausted"while the other worker and synthesis still finish. - Reliability over runs. Run the orchestrator under five scripted variants (clean, one worker fails, plan repair needed, synthesis sees partial results, budget-tight) and tabulate outcomes — the multi-agent version of
pass@kthinking from 08A.14, 4.4. Write two sentences on why "it worked in the demo" is not evidence for a system whose path varies per run. - Decide honestly. Answer in your notes: for your own project idea, single agent vs orchestrator–subagents — using 08D.3's decision table and the four taxes, not enthusiasm.
Verify it, and what you should see:
uv run python multi_agent.py # lead plan -> 2 workers -> synthesis with citations
uv run python test_multi_agent.py # deterministic tests, no key, no packagesThe lesson's own demo output (08D.3, 6.2) is the reference for the unmodified build: a === TRACE === section, a === PLAN === with s1 and s2, then
=== WORKER RESULTS ===
worker-s1: status=ok steps=4 tools=3 sources=4
worker-s2: status=ok steps=4 tools=3 sources=2
...
usage={'input_tokens': 0, 'output_tokens': 0}After your step 2 extension, expect a third line for worker-s3 (with whatever steps, tools and sources your script produces); the usage stays zero because ScriptedModel bills nothing.
Done when:
test_multi_agent.pypasses unmodified, then your extensions (third worker, failure injections) pass as new tests.- The trace shows nested agent runs with per-worker budgets enforced independently.
- Your cost table states its assumptions and compares multi-agent spend to an equivalent single-agent estimate.
- At least two failure-injection tests prove containment: one worker's failure doesn't sink the run.
- Your decision note applies the four taxes and the decision table to a concrete task of your choosing.
Stretch ideas:
- Swap
ScriptedModelfor an 08A.9-stylecall_modeladapter and run live trials; log realUsagesoreport["usage"]is a true bill (08D.3, 3.7). - Implement
run_swarm/agent_as_toolfrom 08D.3, Part 2 overrun_agent— handoffs withmax_handoffs, or calling an agent as a tool. - Feed worker artefacts (not transcripts) between stages per 08D.3, 3.3, and measure context-size differences.
- Sketch the A2A
AgentCardfor your orchestrator per 08D.3, Part 4 — awareness level only; say what you would not expose.
Common problems:
- Duplicated work: workers re-research the same subtopic — tighten the plan's
subtasksand the delegation briefs; checkbrief_shavalues actually differ. - Vague delegation: a brief without objective/output-format/boundaries produces a worker that asks clarifying questions or rambles — the five elements in 3.1 are the fix.
- Runaway spawning: the lead delegates forever —
max_subtasks,max_paralleland the per-workerbudgetsare the brakes; verify exhaustion returnsbudget_exhausted, not a hang. - Lost context: the synthesis sees worker chatter instead of findings — enforce the condensed-result contract (structured
{"finding", "sources"}replies) and artefact passing. - False economy: you added agents to feel advanced — re-read 08D.3, 1.2; if a workflow from 08A.9 solves it, ship the workflow.