Lesson 11 Multi-Agent Systems
Theme:

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.

📥 Lab Notebooks

⬇ lab.pdf ⬇ lab_answer.pdf

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

Agent instances

AgentToolsRole
Researchersearch, read_urlFind 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 orchestrate(task, agents)

Build an orchestrator that:

  1. Sends the task to the Researcher agent with an instruction to gather facts
  2. Passes the researcher’s output to the Writer agent with an instruction to produce a summary
  3. 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

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.”