Multi-Agent Wiki
Decision

Refinement Loop / Evaluator-Optimizer

Generate → evaluate → revise, until an exit condition or budget is reached.

Live visualizationAnimated topology — press Space to play / pause
·Diagram
Live
1 / 6

Definition

Iterate generation → evaluation → revision until an exit condition is met or the budget is exhausted.

Category: Decision

When to use

Test-driven code repair, document polishing, prompt optimization, plan iteration, quality gates.

When not to use

When there's no clear evaluation criterion, no defined exit condition, or budget is tight.

How to implement

  1. Define exit conditions up front: tests passing, score above threshold, human approval, no new issues.
  2. Each round only modifies explicit failure points — avoid oscillation.
  3. Log per-round diff, score, feedback, and cost.
  4. On max-rounds, return current state and unresolved issues.

Minimal pseudocode

TypeScript
for (let round = 1; round <= maxRounds; round++) {
  const output = await worker.run(state);
  const evalResult = await evaluator.run(output);
  logRound(round, output, evalResult);
  if (evalResult.pass) return output;
  state = applyFeedback(state, evalResult.feedback);
}
return { status: "incomplete", state };
  • loop.round.started
  • loop.evaluation.completed
  • loop.exit.pass
  • loop.exit.budget_exceeded

Common failure modes

  • Vague exit conditions create infinite loops.
  • Each round introduces new bugs.
  • The system optimizes the evaluator's score, not the real goal.

Implementation checklist

  • Input/output schemas defined.
  • Each agent's permission boundary defined.
  • Every agent call carries a run id / trace id.
  • Failure, timeout, cancel, and retry strategies defined.
  • Context passed is the minimum required, not the full history.
  • High-risk actions are gated by approval or a verifier.

References