AlgoMaster Logo

Exercise: Multi-Agent Systems

3 min readUpdated June 22, 2026
Listen to this chapter
Unlock Audio

Exercise 1: Route Tasks to Specialist Agents

Build a coordinator that sends each task to the right specialist agent. A router classifies the task, then the matching specialist (each just a model call with its own system prompt) handles it.

A single general-purpose prompt does many things adequately and nothing excellently. The multi-agent pattern splits work across specialists, each with a focused role, and uses a coordinator to route. The router is the key piece: it reads the task and picks the specialist, the same way a team lead assigns work to the right person.

Requirements

  • Define two specialists with distinct system prompts, for example a code expert and a writing expert.
  • Write a router that classifies each task as code or writing.
  • Send each task to the chosen specialist and collect the response.
  • Print which specialist handled each task and its answer.
main.py
Loading...

Expected Output

The coding task goes to the code specialist; the rewrite goes to the writing specialist.

Solution

main.py
Loading...

The coordinator splits one decision (route) from the work (handle), so each specialist can have a tightly focused prompt instead of one prompt trying to cover everything. Routing with a cheap classification call keeps the system simple and cheap, and the design scales by adding entries to the specialists map. This same shape underlies larger multi-agent systems, where specialists may themselves use tools or hand work to one another.

Exercise 2: Plan, Delegate, and Synthesize

Routing sends a whole task to one specialist; a manager pattern goes further by breaking a task into subtasks, handling each, and combining the results. Build a planner that splits a task in two, a worker that completes each subtask, and a synthesis step that merges them into one result.

Requirements

  • Write plan(task) that asks the model for two subtasks.
  • Write do_subtask(subtask) that completes a single subtask.
  • Plan, run each subtask, then synthesize the parts into one final result. Print the subtasks, their results, and the synthesis.
main.py
Loading...

Expected Output

The task splits into writing the announcement and the example, each is done separately, and the synthesis merges them.

Solution

main.py
Loading...

Decomposition lets each subtask get the model's full attention with a focused prompt, instead of one prompt juggling everything. The synthesis step is where the parts become a coherent whole, and giving the synthesizer the original task plus all the parts keeps the result on target. This plan-delegate-synthesize loop is the backbone of manager-style multi-agent systems, where the subtasks might themselves go to different specialists or use tools.