Lab Guide — Multi-Agent Systems
Three exercises building a multi-agent pipeline with an orchestrator, researcher, and writer.
Setup: Open
lab.pdf in Jupyter. Run the setup cell — it loads your API key and provides mock data. You will reuse the mock search/URL databases from Lesson 10.
Exercise 1 — Agent Class + Two Agents
EX 1
Build an Agent class and create Researcher + Writer
Create a reusable Agent class that encapsulates a system prompt, tool definitions, and a ReAct loop. Then instantiate two agents:
Agent class requirements
name: str— identifier for logging and message passingsystem_prompt: str— the agent’s role descriptiontools: list— tool schemas for Claude’s APIexecute_tool(name, input) -> str— tool dispatcherrun(task: str, max_steps=10) -> AgentResult— ReAct loop returning structured result
Agent instances
| Agent | Tools | Role |
|---|---|---|
| Researcher | search, read_url | Find and summarise facts |
| Writer | (none — text generation only) | Turn research into polished prose |
Checkpoint: Both agents can run independently. Researcher returns facts; Writer produces text from a given brief.
Exercise 2 — Orchestrator Function
EX 2
Implement
Implement orchestrate(task, agents)
Build an orchestrator that:
- Sends the task to the Researcher agent with an instruction to gather facts
- Passes the researcher’s output to the Writer agent with an instruction to produce a summary
- Returns the final written output along with a trace of all agent calls
Trace format
# Each entry in the trace:
{"agent": "researcher", "instruction": "...", "status": "success", "steps": 4}
{"agent": "writer", "instruction": "...", "status": "success", "steps": 1}
Checkpoint: orchestrate() returns a final answer and a trace list showing which agents ran and how many steps each took.
Exercise 3 — End-to-End Test
EX 3
Run the full pipeline and inspect traces
Test with these tasks and compare the orchestrator’s output quality versus a single-agent approach:
tasks = [
"Write a technical overview of Python async programming.",
"Explain the differences between Python lists and tuples for a beginner audience.",
"Create a guide to choosing a Python web framework.",
]
What to record
- Total steps across all agents per task
- Message flow trace (who called whom and with what)
- Quality comparison: does the multi-agent output read better than a single-agent attempt?
Checkpoint: All 3 tasks complete successfully. You have traces showing the orchestrator-researcher-writer flow for each.
Tip: If the Writer agent produces generic text, make its system prompt more specific: “You are a technical writer. Use the provided research to write clear, accurate prose. Include specific details and examples from the research.”