๐ฉป Evaluator-Optimizer
July 10, 2026 ยท View on GitHub
๐ Home โบ Workflows โบ ๐ฉป Evaluator-Optimizer
โ 04 Orchestrator-Workers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Agents โ
๐ฉป Evaluator-Optimizer
TL;DR: One LLM generates, another evaluates. Loop until quality threshold is met. Self-improvement through feedback.
Diagram
%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
flowchart TB
classDef user fill:#6366f1,stroke:#4f46e5,stroke-width:2px,color:#ffffff
classDef data fill:#06b6d4,stroke:#0891b2,stroke-width:2px,color:#ffffff
classDef main fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#ffffff
classDef wizard fill:#14b8a6,stroke:#0d9488,stroke-width:2px,color:#ffffff
classDef success fill:#10b981,stroke:#059669,stroke-width:2px,color:#ffffff
classDef error fill:#ef4444,stroke:#dc2626,stroke-width:2px,color:#ffffff
INPUT["๐โโ๏ธ๐ฅ Task"]:::user --> GEN["๐๐ญ Generate"]:::main
GEN --> CAND["๐๐ค Candidate"]:::data
CAND --> EVAL{"๐๐ฉป Evaluate"}:::wizard
EVAL -->|"๐โ
Pass"| OUTPUT["๐โโ๏ธ๐ค Output"]:::success
EVAL -->|"๐โ Fail"| FEEDBACK["๐๐ Feedback"]:::error
FEEDBACK --> GEN
Detailed Flow
%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
sequenceDiagram
participant U as ๐โโ๏ธ User
participant G as ๐๐ญ Generator
participant E as ๐๐ฉป Evaluator
U->>G: ๐โโ๏ธ๐ฅ Request
loop ๐ Until quality threshold
G->>G: ๐๐ญ Generate candidate
G->>E: ๐๐ค Submit for evaluation
E->>E: ๐๐ Score candidate
alt โ
Score >= threshold
E->>U: ๐โโ๏ธ๐ค Accept
else โ Score < threshold
E->>G: ๐๐ Feedback for improvement
end
end
Characteristics
| Property | Value |
|---|---|
| Complexity | Medium |
| Parallelism | Optional |
| Human-Loop | Optional |
| Iteration | Loop |
When to Use
Effective when we have clear evaluation criteria, and when iterative refinement provides measurable value. Two signs of good fit:
- LLM responses can be demonstrably improved when feedback is articulated
- The LLM can provide such feedback
| Domain | Criteria | Use Case |
|---|---|---|
| Code | Tests pass, lint clean, no security issues | Code generation |
| Text | Clarity score, factual accuracy, tone match | Literary translation |
| Search | Comprehensiveness, relevance | Complex research tasks |
Example: Code Generation
Generator: Write function to parse CSV
Attempt 1: Basic implementation
Evaluator: "Missing error handling for malformed input"
Attempt 2: Added try/catch
Evaluator: "Not handling empty files"
Attempt 3: Complete implementation
Evaluator: "Pass - all criteria met"
Advanced: Self-Correction Chains
You can chain prompts to have Claude review its own work. This catches errors and refines outputs, especially for high-stakes tasks.
%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
sequenceDiagram
participant U as ๐โโ๏ธ User
participant G as ๐๐ญ Generator
participant R as ๐๐ Reviewer
U->>G: ๐โโ๏ธ๐ฅ "Summarize this research paper"
G->>G: ๐๐ญ Generate summary
G->>R: ๐๐ค Submit for self-review
R->>R: ๐๐ Check accuracy, clarity, completeness
alt โ
Quality OK
R->>U: ๐โโ๏ธ๐ค Final summary
else โ Issues found
R->>G: ๐๐ "Missing methodology details"
G->>G: ๐๐ญ Regenerate with feedback
G->>R: ๐๐ค Submit improved version
end
Use Self-Correction for:
- Research summaries requiring accuracy
- Code that must meet strict criteria
- Content requiring specific style/tone
When NOT to Use
- First attempt is usually good enough
- No clear quality metrics
- Time constraints prevent iteration
๐ This pattern, as a file
Runnable version (offline mock, no API key ยท nika check proves the DAG before any token is spent): patterns-as-code/05-evaluator-optimizer.nika.yaml โ see Patterns as Code.
โ 04 Orchestrator-Workers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Agents โ