Lesson 11 Multi-Agent Systems
Theme:

Homework

Three tasks extending the multi-agent pipeline with a critic, parallelism, and error retry.

Complete all three lab exercises before starting the homework. These tasks build on the orchestrator pipeline from the lab.

📥 Reference Solution

⬇ lab_answer.pdf

Task 1 — Add a Critic Agent

Objective

Add a third agent — a Critic — that reviews the Writer’s output and provides feedback.

Instructions

  1. Create a Critic agent with a system prompt: “You are a technical reviewer. Evaluate the given text for accuracy, clarity, and completeness. Provide specific, actionable feedback.”
  2. Extend the orchestrator pipeline: Researcher → Writer → Critic
  3. If the Critic flags issues, send the feedback back to the Writer for a revision (one revision loop)
  4. Compare the quality of the final output with and without the Critic step

Deliverable

A notebook showing the extended pipeline, the Critic’s feedback, the revised output, and a brief comparison.

Self-check: The Critic provides specific feedback, and the revised output addresses the feedback points.

Task 2 — Parallel Fan-Out

Objective

Implement parallel execution of sub-agents using asyncio.gather.

Instructions

  1. Create an async version of the Agent’s run() method: async def run_async(task)
  2. Modify the orchestrator to fan-out multiple research tasks in parallel:
    topics = ["Python async", "Python type hints", "Python decorators"]
    results = await asyncio.gather(*[
        researcher.run_async(f"Research: {t}") for t in topics
    ])
  3. Measure wall-clock time for parallel vs sequential execution
  4. Feed all gathered research into the Writer as a single combined brief

Deliverable

A notebook with async agents, parallel fan-out, timing comparison, and the merged final output.

Self-check: Parallel execution is measurably faster than sequential. All research results are included in the final output.

Task 3 — Error Retry Logic

Objective

Make the orchestrator resilient to sub-agent failures with retry logic and circuit breakers.

Instructions

  1. Modify the Researcher agent to randomly fail 50% of the time (simulate with random.random() < 0.5 raising an exception)
  2. Add retry logic to the orchestrator: retry a failed agent up to 3 times
  3. Implement a circuit breaker: if an agent fails 3 times in a row, skip it and continue with partial results
  4. Log all attempts and failures in the trace
  5. Test by running the pipeline 5 times and showing the different outcomes

Deliverable

A notebook with error injection, retry logic, circuit breaker, traces showing retries, and a summary of outcomes across 5 runs.

Self-check: The pipeline never crashes. It either succeeds after retries or gracefully degrades with partial results.

Submission Checklist