Sequential three-agent chain demonstrating structured outputs flowing between agents. Research Agent 1 gathers research, Expand Agent 2 expands research, Synthesis Agent 3 synthesizes final answer. Uses Exa tools and AI SDK 6's stabilized structured output support.
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, EXA_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.
AI SDK APIs
ToolLoopAgentcreateAgentUIStreamResponsetoolOutput.objectstepCountIsprepareStepgatewayInferAgentUIMessageProviders
External services
app/agent-agent-workflow/page.tsxapp/agent-agent-workflow/layout.tsxapp/api/agents-workflow/route.tscomponents/orchestrator-demo.tsxai/types.tsai/sub-agents.tsai/agents/researchAgent1.tsai/agents/expandAgent2.tsai/agents/synthesisAgent3.tsai/tools/exa/exa-tool.tsai/tools/exa/exa-tool-ui.tsxai/tools/cheerio/cheerio-tool.tsai/tools/cheerio/cheerio-tool-ui.tsxREADME.mdnpm packages
8
Registry components
agents-workflow/route.tsOrchestrator API route that routes to 3 sequential agents (research, expand, synthesis). Validates agent field, passes previousOutput between stages. Core orchestration pattern.
ai/sub-agents.tsDefines all 3 ToolLoopAgent instances with Output.object() schemas, configurable tool filtering via activeTools, stepCountIs limits, and prepareStep for message trimming.
ai/types.tsZod output schemas for all 3 agents defining the structured contract between sequential agents in the workflow.
agents/researchAgent1.tsExecution logic for Agent 1. Shows how to consume a ToolLoopAgent stream, extract tool calls from onFinish callback, and await structured output.
agents/expandAgent2.tsExecution logic for Agent 2. Demonstrates prompt chaining: formats Agent 1's structured output into a prompt for Agent 2.
agents/synthesisAgent3.tsExecution logic for Agent 3. Synthesizes outputs from both Agent 1 and Agent 2 into a final answer.
cheerio/cheerio-tool.tsCheerio-based web scraping tools (scrapeUrl, crawlWebsite) with retry logic, content extraction, and BFS crawling.
exa/exa-tool.tsExa search API tools (searchUrls, searchForUrlsContent, searchWikipedia, searchReddit, searchNews). Tool factory pattern with configurable options.
Sequential three-agent chain demonstrating structured outputs flowing between agents. Research Agent 1 gathers research, Expand Agent 2 expands research, Synthesis Agent 3 synthesizes final answer. Uses Exa tools and AI SDK 6's stabilized structured output support.
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, EXA_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.
AI SDK APIs
ToolLoopAgentcreateAgentUIStreamResponsetoolOutput.objectstepCountIsprepareStepgatewayInferAgentUIMessageProviders
External services
app/agent-agent-workflow/page.tsxapp/agent-agent-workflow/layout.tsxapp/api/agents-workflow/route.tscomponents/orchestrator-demo.tsxai/types.tsai/sub-agents.tsai/agents/researchAgent1.tsai/agents/expandAgent2.tsai/agents/synthesisAgent3.tsai/tools/exa/exa-tool.tsai/tools/exa/exa-tool-ui.tsxai/tools/cheerio/cheerio-tool.tsai/tools/cheerio/cheerio-tool-ui.tsxREADME.mdnpm packages
8
Registry components
agents-workflow/route.tsOrchestrator API route that routes to 3 sequential agents (research, expand, synthesis). Validates agent field, passes previousOutput between stages. Core orchestration pattern.
ai/sub-agents.tsDefines all 3 ToolLoopAgent instances with Output.object() schemas, configurable tool filtering via activeTools, stepCountIs limits, and prepareStep for message trimming.
ai/types.tsZod output schemas for all 3 agents defining the structured contract between sequential agents in the workflow.
agents/researchAgent1.tsExecution logic for Agent 1. Shows how to consume a ToolLoopAgent stream, extract tool calls from onFinish callback, and await structured output.
agents/expandAgent2.tsExecution logic for Agent 2. Demonstrates prompt chaining: formats Agent 1's structured output into a prompt for Agent 2.
agents/synthesisAgent3.tsExecution logic for Agent 3. Synthesizes outputs from both Agent 1 and Agent 2 into a final answer.
cheerio/cheerio-tool.tsCheerio-based web scraping tools (scrapeUrl, crawlWebsite) with retry logic, content extraction, and BFS crawling.
exa/exa-tool.tsExa search API tools (searchUrls, searchForUrlsContent, searchWikipedia, searchReddit, searchNews). Tool factory pattern with configurable options.

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.
Sequential three-agent chain demonstrating structured outputs flowing between agents. Research Agent 1 gathers research, Expand Agent 2 expands research, Synthesis Agent 3 synthesizes final answer. Uses Exa tools and AI SDK 6's stabilized structured output support.
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.
Sequential three-agent chain demonstrating structured outputs flowing between agents. Research Agent 1 gathers research, Expand Agent 2 expands research, Synthesis Agent 3 synthesizes final answer. Uses Exa tools and AI SDK 6's stabilized structured output support.
Unlock the live preview and source
Locked on free (high token spend). Pro runs the live demo and includes the source.