Improve output quality with dual agents. Evaluator analyzes quality while optimizer refines results through iterative feedback.
Requirements, wiring steps, and what this pattern adds to your project.
Pick how you want to pull this pattern in. Then wire env vars and routes the same way.
Install from the preview toolbar
Copy the install command above and run it in your project — Pro patterns include a short-lived token.
Add environment variables to .env.local
OPENAI_API_KEY
Point client fetches at your API routes
Replace preview `/view/.../api/...` paths with `/api/...` in the installed files.
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.
Run your dev server and open the pattern route
Install dependencies if needed, then start the app and verify responses.
OPENAI_API_KEYGet keyAI SDK APIs
AgenttoolstepCountIsExperimental_AgentgatewayProviders
app/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.mdnpm packages
6
Registry components
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.
Improve output quality with dual agents. Evaluator analyzes quality while optimizer refines results through iterative feedback.
Requirements, wiring steps, and what this pattern adds to your project.
Pick how you want to pull this pattern in. Then wire env vars and routes the same way.
Install from the preview toolbar
Copy the install command above and run it in your project — Pro patterns include a short-lived token.
Add environment variables to .env.local
OPENAI_API_KEY
Point client fetches at your API routes
Replace preview `/view/.../api/...` paths with `/api/...` in the installed files.
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.
Run your dev server and open the pattern route
Install dependencies if needed, then start the app and verify responses.
OPENAI_API_KEYGet keyAI SDK APIs
AgenttoolstepCountIsExperimental_AgentgatewayProviders
app/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.mdnpm packages
6
Registry components
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.

Unlock the live preview and source
Locked on free (high token spend). Pro runs the live demo and includes the source.
Early-bird pricing — limited time

Open on desktop for the interactive preview.
Improve output quality with dual agents. Evaluator analyzes quality while optimizer refines results through iterative feedback.
Unlock the live preview and source
Locked on free (high token spend). Pro runs the live demo and includes the source.

Unlock the live preview and source
Locked on free (high token spend). Pro runs the live demo and includes the source.
Early-bird pricing — limited time

Open on desktop for the interactive preview.
Improve output quality with dual agents. Evaluator analyzes quality while optimizer refines results through iterative feedback.
Unlock the live preview and source
Locked on free (high token spend). Pro runs the live demo and includes the source.