Lesson 24 — Multi-agent: planner and worker
Two agents, two jobs
A multi-agent system splits work between several agents, each with its own system message and its own short message list:
- the planner breaks the goal into small tasks, and later combines the results;
- the worker does exactly one task at a time.
Your code is the orchestrator: it passes the planner's tasks to the worker, collects the answers and sends them back to the planner.
goal -> planner -> [task, task, task] -> worker x3 -> results -> planner -> final
Here both "agents" are fake functions; with a real API they would often be the same model called with different system messages.
Why it matters: small focused prompts are easier to get right than one giant prompt. The cost: more calls, and more places for mistakes — so only split when one agent struggles.
For each task: ask the worker, append its answer to results and print "worker: <answer>". Then send "RESULTS:" + json.dumps(results) to the planner and print its reply.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based AI Agents Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for AI Agents Foundations books — check the publication year so the examples match current versions.
Search Amazon →