Module 08D: Projects

Agents & multimodal1 projects0 of 1 complete

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)

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_end pairs, delegation events with brief_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:

  1. Run the lesson's build. python multi_agent.py then python test_multi_agent.py. Read the trace output against 08D.3, 6.2's walkthrough: three agent runs (lead + two workers), nested model_call/tool_call events, delegation events carrying brief_sha.
  2. Extend the cast. Add a third subtask — e.g. s3, "quantization trade-offs" — to the lead's planned JSON in SCRIPT["lead"][0] and to LEAD_PROMPT's example plan, and give it a "worker-s3" entry in SCRIPT (worker names are worker-<subtask id>). Run main() and confirm report["results"] has three entries; then construct ResearchOrchestrator(runtime, max_parallel=2) and check the third worker waits for a free slot (the default max_parallel=3 lets all three run at once, so it would not show the bound).
  3. 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_sha hashes and predict which failure modes each produces — then check against the lesson's reported Anthropic bugs.
  4. Cost accounting. ScriptedModel bills zero, so compute a shadow cost: count model_call events 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.
  5. Failure injection. Do the lesson's exercises 4–5 as tests: give worker-s1 a script calling a nonexistent tool and confirm the run still completes with an error result the model can read; give worker-s2 an endless web_search loop and confirm status == "budget_exhausted" while the other worker and synthesis still finish.
  6. 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@k thinking 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.
  7. 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:

bash
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 packages

The 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

text
=== 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.py passes 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 ScriptedModel for an 08A.9-style call_model adapter and run live trials; log real Usage so report["usage"] is a true bill (08D.3, 3.7).
  • Implement run_swarm/agent_as_tool from 08D.3, Part 2 over run_agent — handoffs with max_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 AgentCard for 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 subtasks and the delegation briefs; check brief_sha values 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_parallel and the per-worker budgets are the brakes; verify exhaustion returns budget_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.
Esc
02.2Tokens and TokenizationHow LLMs Work · 21k wordsLesson
02.3EmbeddingsHow LLMs Work · 18k wordsLesson
07Retrieval-Augmented Generation (RAG)11 lessons · Everyone who will build LLM features that must answer from knowledge the model doesn't have in its weights: internal handbooks and help centres, contracts, ticket histories, product docs, or any corpus that changes faster than a training run. The module covers the full RAG stack — architecture, retrieval strategy, query understanding, grounded generation, citations, conversation, managed services, advanced patterns, evaluation, debugging and production operation — and shows where each major provider's managed retrieval and citation features fit (OpenAI, Anthropic, Google Gemini and OpenRouter). All code is Python.Overview
08E.1The Model Context Protocol (MCP)Protocols and Extensibility · 12k wordsLesson
↑ ↓ navigate↵ openesc close