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.pdfTask 1 — Add a Critic Agent
Objective
Add a third agent — a Critic — that reviews the Writer’s output and provides feedback.
Instructions
- 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.”
- Extend the orchestrator pipeline: Researcher → Writer → Critic
- If the Critic flags issues, send the feedback back to the Writer for a revision (one revision loop)
- 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
- Create an async version of the Agent’s
run()method:async def run_async(task) - 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 ]) - Measure wall-clock time for parallel vs sequential execution
- 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
- Modify the Researcher agent to randomly fail 50% of the time (simulate with
random.random() < 0.5raising an exception) - Add retry logic to the orchestrator: retry a failed agent up to 3 times
- Implement a circuit breaker: if an agent fails 3 times in a row, skip it and continue with partial results
- Log all attempts and failures in the trace
- 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
- Task 1: Critic agent; extended pipeline; before/after comparison
- Task 2: Async agents; parallel fan-out; timing comparison
- Task 3: Error injection; retry + circuit breaker; 5-run summary
- All code runs without error after kernel restart + run all