Skip to content
mentoor

Topic 4 of 5 · 5 min read

Orchestrator-workers and evaluator-optimizer loops

Goal: Pick orchestrator-workers or evaluator-optimizer for a described task and write the stop criteria for the evaluator loop.

Orchestrator-workers lets a lead model decide at run time how to split a task and hand pieces to worker calls; evaluator-optimizer pairs a generator with a critic that scores the output and sends it back for revision until it passes. Pick the first when you cannot know the subtasks in advance. Pick the second when you can state what good looks like but the first draft rarely reaches it.

Check yourself · 1 of 3

When is orchestrator-workers a better fit than a fixed chain?

Choose one answer

Orchestrator-workers

In sectioning, you decide the parts in code. Here the orchestrator decides. A request such as "update the logging in this codebase" touches an unknown number of files, so the orchestrator reads the request, writes a list of subtasks, sends each to a worker with only the context it needs, and then merges the results. Use it for coding changes across files and for research questions with open-ended search. Costs rise quickly because each worker is a separate model run, and the orchestrator must give each worker a clear objective, an output format and a boundary. Vague briefs lead workers to repeat each other's work.

Evaluator-optimizer

One call generates. A second call, with its own prompt and a written rubric, scores the output and lists what to fix. The generator revises. It works when a person could give useful feedback on a draft and a model can do the same, such as translation nuance or code that must meet a style guide. It does not work when the evaluator cannot tell good from bad, because the loop then polishes nothing.

Stop criteria are the design

An unbounded loop is a bill. Write all of these before you run it:

  1. A pass condition in measurable terms: "all rubric items score 4 or more", "all tests pass".
  2. A maximum number of rounds, often two or three.
  3. A no-progress rule: stop if the score did not improve over the last round.
  4. A budget cap on tokens or time.
  5. What happens on exit without a pass: return the best draft with its failures flagged, or escalate.

Prefer an evaluator that runs code, such as tests or a linter, to one that only gives an opinion.

Before and after

# Before: loop until the critic says "good"
while "good" not in critic(draft):
    draft = revise(draft)
# After: bounded, scored, with a way out
last = None
for attempt in range(3):
    score, issues = evaluate(draft, RUBRIC)
    if score >= 4 or (last is not None and score <= last):
        break  # passed, or no progress
    last = score
    if attempt < 2:
        draft = revise(draft, issues)
return Result(draft, passed=score >= 4, issues=issues)

What goes wrong

  • No stop rule. The loop runs until the budget is gone.
  • Vague rubric. "Make it better" gives the critic nothing to check and the generator nothing to fix.
  • Using an orchestrator for a fixed task. If the steps are known, a chain is cheaper and easier to debug.

Examples

Orchestrator for a multi-file change

Task: "Replace the deprecated request library with fetch across the repo." The orchestrator searches for usages, finds 23 files, groups them into five subtasks and sends each to a worker with the file list and the migration rule. After the workers return, code runs the test suite. The orchestrator is needed because the file list was unknown when the task started.

Evaluator loop with an exit

A generator writes release notes. The evaluator scores accuracy against the commit list, tone and length, each from 1 to 5. Pass: every item 4 or higher. Maximum three rounds. If the score does not improve between rounds, stop. On exit without a pass, the notes go to an editor with the failing items listed.

Key points

  • Orchestrator-workers lets a lead model decide the subtasks at run time, which suits tasks whose parts are unknown in advance.
  • Give each worker a clear objective, an output format and a boundary, or workers duplicate each other's effort.
  • Evaluator-optimizer needs a written rubric the critic can apply, and a task where a model can tell good from bad.
  • Write stop criteria first: a pass condition, a maximum round count, a no-progress rule and a budget cap.
  • Prefer an evaluator that runs tests or checks over one that only gives an opinion.

Common mistakes

  • Running an evaluator loop with no maximum rounds, no-progress rule or budget.
  • Giving the critic a vague rubric such as "make it better".
  • Handing workers vague briefs so they overlap or leave gaps.
  • Using an orchestrator when the subtasks are known and a fixed chain would do.

Check yourself · 2 of 3

An evaluator-optimizer loop keeps revising a draft until the critic says it is good. What is missing?

Choose one answer

Check yourself · 3 of 3

Which evaluator is more reliable for a generated code change?

Choose one answer

Practice items, not counted towards your mastery.

Start here