05. Design Patterns
Orchestrator-Worker and Evaluator-Optimizer Patterns
Orchestrator-Worker decomposes a job and assigns specialist workers, then integrates their outputs. Evaluator-Optimizer generates a candidate, scores it against a rubric, and revises until it passes or the budget ends.
What you will learn
- Define both patterns in one clear sentence each
- Design orchestrator contracts for workers
- Build an evaluate-revise loop with stop rules
- Choose which pattern fits a product task
- Answer interview questions with short, solid answers
Definition
Orchestrator-Worker is a control pattern where a central planner (orchestrator / supervisor) breaks a goal into subtasks, assigns them to workers with scoped tools and prompts, then integrates results into a final artifact.
Evaluator-Optimizer is an iterative quality pattern: a generator produces a draft; an evaluator scores or critiques it; feedback drives revision until a pass threshold or max iterations / cost budget is hit.
Introduction
This lesson (#3 in Design Patterns) follows Routing and Parallelization. Orchestrators often route and parallelize workers; evaluator loops often sit after a chain or worker produces a draft.
Next: Reflection and Planning Patterns β related self-critique and plan-then-act shapes.
Why these patterns matter
- Isolate permissions and prompts per worker role
- Scale complex jobs without one mega-agent
- Raise output quality with explicit rubrics
- Make stop conditions and budgets enforceable in code
Orchestrator-Worker pattern
Keep the orchestrator thin on tools: plan, assign, wait, integrate. Put privileged or domain tools on workers.
- Plan - decompose goal into typed subtasks
- Assign - map each subtask to a worker + tool allowlist
- Execute - sequential or parallel workers (join policy matters)
- Integrate - schema merge or synthesizer hop
- Escalate - unknown / failed subtasks to human or safe path
Evaluator-Optimizer pattern
Separate generator and evaluator roles (different prompts or models). Shared prompts encourage rubber-stamping.
- Generate - draft candidate under constraints
- Evaluate - rubric scores, checklist, or tests
- Decide - pass, revise with critique, or abort
- Optimize - rewrite / patch using evaluator feedback
- Stop - max N loops, token budget, or diminishing returns
When to use which
- Orchestrator-Worker - multi-skill jobs needing isolation (research + code + review)
- Evaluator-Optimizer - single artifact quality (emails, code patches, summaries)
- Compose - workers produce drafts; an evaluator loop polishes the final merge
- Avoid - orchestrating tiny tasks that a chain handles cheaper
Stop conditions and contracts
- Worker output schemas the orchestrator can validate
- Evaluator returns structured scores + actionable critique
- Hard caps: max workers, max parallel, max critique rounds
- On fail-at-budget: escalate, ship with warning, or safe fallback
Failure modes
- God orchestrator - still calls every tool; defeat the pattern
- Worker contention - overlapping writes; serialize or lock
- Eval rubber-stamp - same model praises itself; diversify or use tests
- Infinite revise - no max iterations / no diminishing-return check
- Vague rubrics - scores that cannot guide a rewrite
Program / implementation notes
Implement orchestrators as state machines: pending assignments, join waits, integrate. Implement evaluator loops as for-loops with break on pass or budget.
- Log assignment_id, worker_id, and critique_round for traces
- Prefer unit tests or linters as evaluators when the domain allows
- Next: Reflection and Planning Patterns
Advantages and limitations
- Advantage: clearer roles and safer tool scopes (orchestrator)
- Advantage: measurable quality lifts via critique loops
- Advantage: easy to swap workers or evaluators independently
- Limitation: more latency and tokens than a single shot
- Limitation: bad decomposition wastes whole worker fleets
- Limitation: weak evaluators create expensive thrash
Key points
- Orchestrator-Worker: plan, assign specialists, integrate results.
- Evaluator-Optimizer: generate, score/critique, revise until pass or budget.
- Keep orchestrators thin on tools; put privileges on workers.
- Separate generator and evaluator prompts or models.
- Hard-cap iterations, concurrency, and spend.
- Compose: orchestrate work, then evaluate-optimize the merge.
FAQs
Is Orchestrator-Worker the same as multi-agent?
It is a common multi-agent topology (supervisor + workers). You can also implement workers as functions/tools under one process β the pattern is about roles, not process count.
How is Evaluator-Optimizer different from reflection?
Same family. Evaluator-Optimizer names the generate/score/revise loop with an explicit evaluator role; reflection often means the same agent critiques itself.
Can the evaluator be code instead of an LLM?
Yes β and often better. Tests, schemas, linters, and policy checkers make strong evaluators; use LLMs for subjective rubrics.
When should I stop revising?
On pass threshold, max iterations, token/cost budget, or when score gains flatten β never leave the loop open-ended.
Interview questions
- What is the Orchestrator-Worker pattern?
Answer A planner decomposes a goal, assigns subtasks to specialist workers, then integrates their structured results.
- What is the Evaluator-Optimizer pattern?
Answer A generator produces a candidate; an evaluator scores or critiques it; the system revises until pass or a hard budget stop.
- Why separate orchestrator and workers?
Answer To isolate tools/permissions, specialize prompts, and keep planning separate from heavy execution.
- How do you prevent infinite critique loops?
Answer Set max iterations, cost caps, and clear pass criteria; on exhaustion escalate or ship with a warning.
- Give a combined example.
Answer Orchestrator assigns research and draft workers; an evaluator loop grades the draft against a rubric before release.
- When is a simple chain better than these patterns?
Answer When the path is short, fixed, and does not need role isolation or iterative quality gates.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- Sketch an orchestrator with 3 workers for a βweekly research briefβ product; list each workerβs tools.
- Write a 5-item evaluator rubric for that brief (pass = all 5 true).
- Define stop rules: max 3 revise rounds and what happens if still failing.
- Mark one step that should stay a plain chain instead of orchestrated workers.
- Answer interview questions 1, 2, and 4 in two sentences each.