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.
- The optimizer produces an initial candidate from the task description.
- The evaluator scores the candidate against the rubric and returns a pass or fail decision with specific comments.
- If the candidate fails, the optimizer revises it using the comments and its previous attempt.
- 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.
| Parameter | Typical setting | What it controls |
|---|---|---|
| Maximum iterations | 2 to 5 | Upper bound on cost and latency |
| Evaluation rubric | 3 to 8 explicit criteria | What counts as acceptable |
| Pass threshold | All criteria met or score above cutoff | When the loop stops |
| Feedback format | Structured list of issues | How usable the critique is |
| Evaluator type | Code check, model judge or both | Reliability of the verdict |
| Memory of attempts | Last draft or full history | Whether errors repeat |
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.
| Pattern | Core mechanism | Typical use |
|---|---|---|
| Evaluator-optimizer | Generate, critique, revise | Translation, code, structured writing |
| Prompt chaining | Fixed sequence of steps | Predictable multi-stage tasks |
| Routing | Classifier selects a path | Mixed request types |
| Orchestrator-worker | Planner delegates subtasks | Tasks of unknown shape |
| Reflexion | Self-reflection stored in memory | Learning across episodes |
| Multi-agent debate | Several agents argue positions | Contested reasoning questions |
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.
| Task | Fit | Reason |
|---|---|---|
| Code that must pass unit tests | Strong fit | Tests give an objective verdict |
| Literary translation | Good fit | Critic catches nuance and omissions |
| Answers with strict JSON schema | Good fit | Validator gives exact errors |
| Simple factual lookup | Poor fit | One call is usually sufficient |
| Open-ended creative brainstorming | Poor fit | No stable quality criteria |
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.