Skip to content
25 min read75 min build
Prerequisites:ch01-minimal-coding-loopch02-tool-registrych03-planner-task-graphch04-memory-contextch05-safe-file-editingch06-approvals-sandboxingch07-worktree-isolationch08-execution-lanes
What You Will Build

A SupervisorAgent that decomposes tasks, delegates to WorkerAgents, and aggregates validated results

Why This Matters

Until now, your system has one agent doing everything: planning, executing, reviewing. That works for small tasks. But when the work involves changing ten files across three packages — tests, implementation, and documentation — a single agent hits limits. Its context window fills up. Its decisions become noisy. It cannot parallelize.

Production systems split the work. One agent plans and delegates; others execute. This is the supervisor-worker pattern. The supervisor understands the big picture, decomposes it into tasks, and assigns each task to a worker. Workers are focused and disposable — they do one thing and report back. The supervisor aggregates results and decides what to do next.

But this creates a trust problem. Worker outputs are untrusted. A worker might be fed malicious instructions through the content it reads (prompt injection). The supervisor must validate every result before acting on it.

What You Will Build

A SupervisorAgent that breaks a high-level goal into sub-tasks, dispatches them to WorkerAgent instances, collects results, validates them, and produces a final summary.

                        User Goal
                           |
                           v
                  +------------------+
                  |   SUPERVISOR     |
                  | decompose task   |
                  | assign workers   |
                  | validate results |
                  +--------+---------+
                           |
            +--------------+--------------+
            |              |              |
            v              v              v
      +-----------+  +-----------+  +-----------+
      | WORKER A  |  | WORKER B  |  | WORKER C  |
      | implement |  | write     |  | update    |
      | feature   |  | tests     |  | docs      |
      +-----------+  +-----------+  +-----------+
            |              |              |
            v              v              v
      +-----------+  +-----------+  +-----------+
      | Result A  |  | Result B  |  | Result C  |
      +-----------+  +-----------+  +-----------+
            |              |              |
            +--------------+--------------+
                           |
                           v
                  +------------------+
                  | VALIDATE & MERGE |
                  | sanitize outputs |
                  | check coherence  |
                  +------------------+
                           |
                           v
                       Summary

Story Mode for this chapter is coming soon

We are crafting a fun, code-free explanation with metaphors and interactive mini-games. In the meantime, switch to Builder Mode to start learning.

What's Next

You have a supervisor that can delegate work and validate results. But right now, it dispatches all workers at once. What if Worker B depends on Worker A's output? What if five workers need to run but you only have capacity for three?

In Chapter 10, you will build a scheduler that understands task dependencies, runs independent tasks in parallel, and respects concurrency limits. The supervisor becomes smarter about when and how to dispatch.