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.
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, EXA_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.
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.
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, EXA_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.
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.