BeginnerCoder

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.

Want it another way?
Task

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.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with AI Agents Foundations

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.