Evaluator-Optimizer

Generate. Judge. Improve. Repeat.

A generator produces a result, an evaluator scores it against specific criteria, and the generator optimizes it based on the feedback.

Level
02 · Workflow
Also known as
Generator-Critic, Critique and Revise, Evaluate-Improve
Trade-off
Better output quality is gained against additional evaluation complexity and latency.
Native in
Google ADK, LangGraph, AutoGen / AG2, Microsoft Agent Framework
The mental model

A shape you can draw on a napkin.

An optimizer generates drafts; an external evaluator scores and feeds back until the threshold is met.

OptimizerEvaluator
Walk it through

A real run, step by step.

TaskA product text for a hiking backpack. The evaluator checks three criteria: at most 80 words, the three key specifications are named, no superlatives.
Illustrative run.
RoundGeneratorEvaluatorVerdict
1112 words, opens with “the best backpack ever made”Too long. Superlative in the first sentence. The weight is missingRevise
278 words, weight added, still says “unbeatable”Length and specifications are met. One superlative remainsRevise
376 words, volume, weight and frame named, neutral wordingAll three criteria are metAccept
What this shows: the evaluator is a second call with its own prompt and a fixed list of criteria, and it answers per criterion. That is why the loop converges in three rounds. An evaluator that can only say “make it better” gives the generator nothing to act on. In Iterative Refinement the signal comes from tests, rules or a person instead of a second model.
In code

The pattern in code.

Plain Pythonpython
def write_until_accepted(brief, criteria, max_rounds=3):
    draft, feedback = None, None
    for _ in range(max_rounds):
        draft = generator(brief, previous=draft, feedback=feedback)
        # a separate call with its own prompt
        verdict = evaluator(draft, criteria)
        if verdict.accepted:
            return draft
        # concrete, one entry per failed criterion
        feedback = verdict.reasons
    return draft  # budget used up: hand over for review
Fit

Use it, or not.

When to reach for it

  • Quality criteria can be explicitly formulated.
  • Iterative improvement is measurable.
  • Creative outputs need rigorous checking.

When it backfires

  • The evaluator cannot provide reliable signals.
  • Schema validation suffices.
  • The budget does not allow for multiple runs.
Pitfalls

Two ways this pattern will hurt you.

Evaluator and optimizer share the same blind spot

Both models miss the same factual error. The loop converges to a polished but wrong answer.

Countermeasure

Use a different model family for evaluator, or ground scoring in external checks (tests, regex, database queries).

Optimization metric drifts from user intent

The evaluator optimizes for BLEU score or length, not the user's actual quality criteria. The output looks good but misses the point.

Countermeasure

Align the evaluator's rubric with user requirements. Calibrate with human ratings before deploying.

Framework support

Where Evaluator-Optimizer is native.

LangGraphNative
Claude CookbooksRecipesdocumented as a recipeAdaptable
Pydantic AIvalidation plus retryAdaptable
Sources

Where this pattern comes from.

  1. Building Effective AgentsIn the source list

Search

Search patterns, frameworks, and pages.