ptrnsai

Supervisor-Worker

Intermediate👥 Multi-Agent PatternsCrewAI / Industry practice

Intent

A supervisor agent delegates tasks to specialized worker agents, coordinates their efforts, and synthesizes results.

Problem

Complex tasks require diverse expertise — one agent can't be equally good at coding, research, writing, and analysis. A single agent trying to do everything produces mediocre results. You need specialization, but also coordination.

Solution

Create a hierarchy: a Supervisor agent that understands the big picture and can delegate to Worker agents, each specialized for a particular type of task. The supervisor decides what needs to be done, assigns tasks to appropriate workers, monitors progress, and combines results. Workers can be different models, have different tools, or use different prompts. The supervisor manages the workflow without needing to do the actual work.

Diagram

Task → [Supervisor]
           ├─ delegate → [Research Worker] → findings
           ├─ delegate → [Code Worker] → implementation
           └─ delegate → [Review Worker] → feedback
                                    ↓
        [Supervisor synthesizes] → Final Output

When to Use

  • Tasks requiring diverse expertise (coding + writing + research)
  • When you want centralized control and clear accountability
  • Enterprise workflows with compliance requirements
  • When different subtasks benefit from different models or configurations

When NOT to Use

  • Simple tasks that don't need multiple agents
  • When the supervisor becomes a bottleneck
  • Tasks where all subtasks are identical (use Parallelization instead)

Pros & Cons

Pros

  • Each worker is specialized and optimized for its role
  • Supervisor maintains coherent big-picture view
  • Clear accountability — supervisor owns the outcome
  • Easy to add new worker types

Cons

  • Supervisor is a single point of failure
  • Communication overhead between supervisor and workers
  • Supervisor needs to be smart enough to delegate effectively
  • More complex than single-agent systems

Implementation Steps

  1. 1Define worker roles and their capabilities/tools
  2. 2Design the supervisor prompt: how it analyzes tasks and decides delegation
  3. 3Implement the communication protocol between supervisor and workers
  4. 4Build result aggregation: how supervisor combines worker outputs
  5. 5Add error handling: what happens when a worker fails?
  6. 6Implement monitoring: log all delegation decisions for debugging

Real-World Example

Content Production Pipeline

Supervisor receives 'Write a blog post about AI agents.' Delegates: Research Worker gathers latest developments, Writing Worker creates the draft, SEO Worker optimizes for search, Editor Worker reviews for quality. Supervisor ensures consistency and combines into final output.

PythonSupervisor Routing to Specialized Workers
from openai import OpenAI
import json

client = OpenAI()

WORKERS = {
    "researcher": "You are a research specialist. Gather and synthesize information.",
    "coder": "You are a senior engineer. Write clean, production-ready code.",
    "reviewer": "You are a code reviewer. Find bugs and suggest improvements.",
}

def supervisor(request: str) -> dict:
    routing = client.chat.completions.create(
        model="gpt-4o",
        response_format={"type": "json_object"},
        messages=[{"role": "user", "content": f"Route to workers (researcher, coder, reviewer). Return JSON: {{\"tasks\": [{{\"worker\": str, \"task\": str}}]}}\n\nRequest: {request}"}],
    )
    tasks = json.loads(routing.choices[0].message.content)["tasks"]

    results = {}
    for t in tasks:
        response = client.chat.completions.create(
            model="gpt-4o",
            messages=[
                {"role": "system", "content": WORKERS[t["worker"]]},
                {"role": "user", "content": t["task"]},
            ],
        )
        results[t["worker"]] = response.choices[0].message.content

    return results

References