Evaluator-Optimizer Pattern
Evaluator-Optimizer Pattern
Improve output quality with dual agents. Evaluator analyzes quality while optimizer refines results through iterative feedback.
Loading preview…
Problems solved
- Evaluate draft quality with a dedicated evaluator tool
- Optimize content iteratively from evaluation feedback
- Loop evaluator and optimizer tools under one orchestrator agent
- Stop once quality thresholds or step limits are reached
Use cases
- Marketing copy optimization loops
- Technical documentation review agents
- Translation quality control workflows
- Creative writing refinement assistants
Setup
Requirements, wiring steps, and what this pattern adds to your project.
Getting started
Pick how you want to pull this pattern in — then wire env vars and routes the same way.
- 1
Install from the preview toolbar

Copy the install command above and run it in your project — Pro patterns include a short-lived token.
- 2
Add environment variables to .env.local
OPENAI_API_KEY
- 3
Point client fetches at your API routes
Replace preview `/view/.../api/...` paths with `/api/...` in the installed files.
- 4
Customize the agent and tool files
Adapt prompts, tools, and stop conditions for your product — Copy for AI in the toolbar helps seed that work.
- 5
Run your dev server and open the pattern route
Install dependencies if needed, then start the app and verify responses.
Environment variables
OPENAI_API_KEYGet key
Capabilities
AI SDK APIs
AgenttoolstepCountIsExperimental_AgentgatewayProviders
Files added
14 filesapp/page.tsxapp/layout.tsxapp/api/evaluator-optimizer/route.tslib/multi-agent-orchestrator.tslib/multi-agent-tool-types.tslib/ai-agent-evaluator-optimizer-tools/evaluator.tslib/ai-agent-evaluator-optimizer-tools/optimizer.tslib/ai-agent-evaluator-optimizer-tools/schema.tslib/ai-agent-evaluator-optimizer-tools/communication.tscomponents/evaluator-optimizer-chat.tsxcomponents/tool-views/evaluator-view.tsxcomponents/tool-views/optimizer-view.tsxREADME.mdAGENT_FLOW.md
Dependencies
9 totalnpm packages
6
Registry components
Critical files
lib/multi-agent-orchestrator.tsCore orchestrator agent definition using Experimental_Agent. Configures the evaluator-optimizer coordination loop with model, instructions, tools, and stepCountIs(15) stop condition.
ai-agent-evaluator-optimizer-tools/evaluator.tsEvaluator tool that assesses content quality against criteria. Uses generator pattern to yield loading/ready states. Returns quality scores, issues, suggestions, and threshold checks.
ai-agent-evaluator-optimizer-tools/optimizer.tsOptimizer tool that takes evaluation feedback and iteratively improves content. Uses generator pattern for streaming state transitions.
ai-agent-evaluator-optimizer-tools/communication.tsInter-agent communication tools (sendEvaluation, requestEvaluation, sendOptimization) that enable the evaluator-optimizer message passing loop.
ai-agent-evaluator-optimizer-tools/schema.tsShared Zod schemas (EvaluationResult, OptimizationParams, OptimizationResult, EvaluationCriteria) defining data contracts between evaluator and optimizer agents.
Requirements
- Complexity
- Advanced
- Setup time
- ~15 minutes
- Node
- 24+
- Memory
- 1GB










