Back to Patterns

Orchestrator-Workers

Agent Patterns

Summary

The Orchestrator-workers pattern implements a hierarchical workflow where a central orchestrator LLM breaks down complex tasks into subtasks, delegates them to specialized worker LLMs, and then synthesizes their outputs into a coherent final result. This pattern is particularly effective for handling complex, multi-step tasks that require different types of expertise or processing.

How it works

  1. Task Analysis: Orchestrator analyzes the complex request
  2. Subtask Planning: Decomposes into specialized subtasks with dependencies
  3. Worker Dispatch: Each worker receives its assigned subtask
  4. Result Collection: Workers return specialized outputs
  5. Synthesis: Orchestrator combines all results into final response

Coordination patterns

  • Linear: Workers execute sequentially, passing results
  • Hierarchical: Workers report to orchestrator between stages
  • Fan-out/fan-in: Parallel workers then orchestrated merge
  • Dynamic: Orchestrator adapts plan based on worker results

Use cases

  • Complex content generation requiring multiple specialized perspectives
  • Research and analysis tasks that need to be broken down into manageable subtasks
  • Multi-step problem solving where each step requires different expertise
  • Coordinated content creation and refinement workflows

Build This Pattern

Copy this prompt and paste it into Claude Code, OpenCode, Codex, or Cursor to implement this pattern.

Build me an orchestrator-workers agent system. Architecture: the orchestrator module receives a complex task and breaks it down into subtasks using an LLM call guided by a decomposition strategy (top-down or dependency-based). Each subtask is delegated to a worker module via a task queue. Workers execute their subtasks and return results to an aggregator. The orchestrator synthesizes all worker results into the final output. Support dynamic subtask creation based on task complexity and worker result validation against expected schemas before synthesis. Error handling: retry failed subtasks up to 2 times with different parameters (temperature, model). Implement a dead letter queue for subtasks that fail after all retries. Handle orchestrator decomposition failure by falling back to a manual breakdown mode. Edge cases: detect circular dependencies between subtasks by analyzing dependency graphs and break loops. Support subtask prioritization so critical paths execute first. Handle workers that return empty results by requesting clarification or regenerating. Best practices: set worker-level timeouts (30s default, configurable). Include a progress and callback system so the UI can show real-time status per subtask. Log subtask timing and results. Testing: test decomposition with various task complexities. Test retry and dead letter queue behavior. Integration test full orchestration cycle with mock workers. TypeScript.