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.
Download → Next.js app
Use Download → Next.js app in the preview toolbar. You get a zip scaffold (Pro downloads rewrite preview `/view/.../api/*` paths to `/api/*` automatically).
Extract the zip and install dependencies
Unzip the archive, then run `pnpm install` (or npm / yarn) in the project folder.
Fill .env.local
The download includes .env.local placeholders when needed. Add real values for: OPENAI_API_KEY.
Customize the agent and tool files
Adapt prompts, tools, and stop conditions in the generated project for your product.
Run the app and open the pattern route
Run `pnpm dev`, open the setup/checklist page if present, then navigate to the generated pattern route 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.
Download → Next.js app
Use Download → Next.js app in the preview toolbar. You get a zip scaffold (Pro downloads rewrite preview `/view/.../api/*` paths to `/api/*` automatically).
Extract the zip and install dependencies
Unzip the archive, then run `pnpm install` (or npm / yarn) in the project folder.
Fill .env.local
The download includes .env.local placeholders when needed. Add real values for: OPENAI_API_KEY.
Customize the agent and tool files
Adapt prompts, tools, and stop conditions in the generated project for your product.
Run the app and open the pattern route
Run `pnpm dev`, open the setup/checklist page if present, then navigate to the generated pattern route 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.