Evaluator-optimizer pattern

Also known as: generator-critic loop

On this page 7

The evaluator-optimizer pattern is an agentic workflow in which one language model call generates a candidate output and a second call evaluates it against explicit criteria, returning feedback that the generator uses to revise the output in a loop until it passes or a stop condition is reached. Among AI agents design patterns, it is also known as the generator-critic loop, and it suits tasks where quality can be judged more reliably than it can be produced in a single attempt.

The pattern mirrors how a writer works with an editor. Its value depends on two conditions: the evaluation criteria must be clear, and feedback must measurably improve the next draft. When either condition fails, the loop adds cost without adding quality.

How the evaluator-optimizer loop works

The evaluator-optimizer loop works by alternating generation and critique within a bounded number of iterations. The optimizer, sometimes called the generator, receives the task and any prior feedback. The evaluator receives the task, the candidate and a rubric, and returns a verdict with reasons.

  1. The optimizer produces an initial candidate from the task description.
  2. The evaluator scores the candidate against the rubric and returns a pass or fail decision with specific comments.
  3. If the candidate fails, the optimizer revises it using the comments and its previous attempt.
  4. The loop ends when the evaluator passes the candidate, when the iteration limit is reached, or when scores stop improving.

The evaluator can be the same model with a different prompt, a different model, or a deterministic checker such as a test suite, a schema validator or a compiler. Deterministic evaluators are the most reliable, because they do not share the generator’s blind spots. Many production systems combine both: code-based checks run first, and a model-based judge assesses what code cannot measure, such as tone or completeness.

Components and design parameters

The behavior of the pattern is determined by a small set of design parameters that control cost, latency and the risk of endless revision. Choosing them deliberately matters more than the choice of model.

ParameterTypical settingWhat it controls
Maximum iterations2 to 5Upper bound on cost and latency
Evaluation rubric3 to 8 explicit criteriaWhat counts as acceptable
Pass thresholdAll criteria met or score above cutoffWhen the loop stops
Feedback formatStructured list of issuesHow usable the critique is
Evaluator typeCode check, model judge or bothReliability of the verdict
Memory of attemptsLast draft or full historyWhether errors repeat
Main design parameters of the loop

Structured feedback is the most important detail. An evaluator that says only “not good enough” gives the optimizer nothing to act on, while an evaluator that lists specific failures with locations and expected fixes usually produces convergence within two or three rounds.

How it compares with other agentic workflow patterns

The evaluator-optimizer pattern differs from other agentic workflow patterns in that its control flow is driven by quality judgments, not by task structure. Other patterns split, route or delegate work; this one repeats work until it is good enough.

PatternCore mechanismTypical use
Evaluator-optimizerGenerate, critique, reviseTranslation, code, structured writing
Prompt chainingFixed sequence of stepsPredictable multi-stage tasks
RoutingClassifier selects a pathMixed request types
Orchestrator-workerPlanner delegates subtasksTasks of unknown shape
ReflexionSelf-reflection stored in memoryLearning across episodes
Multi-agent debateSeveral agents argue positionsContested reasoning questions
Evaluator-optimizer pattern and neighboring patterns

The closest relative is Reflexion, which also uses critique. The difference is scope: Reflexion keeps verbal lessons across attempts and episodes, while a basic evaluator-optimizer loop focuses on improving one output within a single task. The pattern can also run inside an orchestrator-worker system, where each worker output passes through its own evaluator before the orchestrator accepts it.

When to use the pattern

The pattern is worth its cost when evaluation is easier and more reliable than generation, and when a human reviewer would typically request revisions. It is a poor fit when the first attempt is already good enough or when no clear criteria exist.

TaskFitReason
Code that must pass unit testsStrong fitTests give an objective verdict
Literary translationGood fitCritic catches nuance and omissions
Answers with strict JSON schemaGood fitValidator gives exact errors
Simple factual lookupPoor fitOne call is usually sufficient
Open-ended creative brainstormingPoor fitNo stable quality criteria
Decision guide for applying the pattern

A practical test is to ask whether a domain expert could write down what a failed output looks like. If such a rubric can be written, an evaluator can apply it. If the expert can only say that they will know a good result when they see it, human-in-the-loop review is usually a better design.

Risks and common mistakes

The main risks of the pattern are runaway cost, false convergence and evaluator bias. Each iteration adds at least two model calls, so a loop without a hard cap can multiply the price of a request several times.

  • Self-preference bias: a model judging its own output tends to rate it too favorably.
  • Oscillation: the optimizer fixes one issue and reintroduces another, cycling without progress.
  • Vague rubrics: criteria such as “high quality” produce inconsistent verdicts.
  • Reward hacking: the optimizer learns to satisfy the evaluator wording rather than the real goal.
  • No final fallback: when the limit is reached, the system needs a defined action, such as returning the best-scoring draft or escalating to a person.

Teams reduce these risks by using a different model or a deterministic check as evaluator, logging every iteration for agent observability, and tracking the score of each draft so the best version is kept even if later revisions regress.

In plain words

Think of a student and a teacher. The student writes an essay. The teacher marks the mistakes and explains them. The student fixes them and hands it in again. This repeats until the essay is good enough.

The evaluator-optimizer pattern does this with two AI roles. One writes. The other checks against a clear list of rules. The key point is that checking is often easier than writing well the first time. A limit on rounds keeps the process from running forever.

A real-world example

A software team uses a coding agent to write data conversion functions. The optimizer model writes a function from a short specification. The evaluator is a test runner with 40 unit tests, followed by a model-based reviewer that checks naming and error handling against a five-point rubric.

The loop allows at most four iterations. On the first attempt, the function fails six tests involving empty inputs and time zones. The test output is passed back as feedback, and the second draft fails one test. The third draft passes all tests and the review. Across 200 such tasks, the share of functions accepted without human edits rises from about 55 to 85 percent, while the average cost per task roughly doubles, which the team considers acceptable.