Execute multi-step workflows with typed tools. Includes streaming, tool chaining, and decision-making for automated tasks.
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, PERPLEXITY_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
AgenttoolstepCountIsgenerateObjectExperimental_AgentgatewayhasToolCallProviders
External services
app/page.tsxapp/layout.tsxapp/api/multi-step-tool-agent/route.tslib/multi-step-agent.tslib/multi-step-tool-types.tslib/ai-agent-multi-step-tools/web-search.tslib/ai-agent-multi-step-tools/news-search.tslib/ai-agent-multi-step-tools/analyze.tslib/ai-agent-multi-step-tools/decide.tslib/ai-agent-multi-step-tools/provide-answer.tslib/ai-agent-multi-step-tools/schema.tscomponents/multi-step-tool-chat-demo.tsxcomponents/tool-views/web-search-view.tsxcomponents/tool-views/news-search-view.tsxcomponents/tool-views/analyze-view.tsxcomponents/tool-views/decide-view.tsxcomponents/tool-views/provide-answer-view.tsxREADME.mdnpm packages
6
Registry components
multi-step-tool-agent/route.tsAPI route wiring the agent to HTTP: uses createAgentUIStreamResponse and validateUIMessages to connect the multi-step agent to a streaming endpoint.
lib/multi-step-agent.tsCore agent definition: creates an Experimental_Agent with comprehensive system instructions, 5 registered tools, and stop conditions (hasToolCall or stepCountIs(8)).
ai-agent-multi-step-tools/web-search.tsWeb search tool using Perplexity Sonar: uses generateObject with perplexity/sonar model. Implements generator-based execute with loading/ready states.
ai-agent-multi-step-tools/news-search.tsNews search tool using HN Algolia API. Generator-based tool with loading/ready states and graceful error fallback.
ai-agent-multi-step-tools/analyze.tsAnalysis tool: breaks down complex problems into components using systematic/creative/technical approaches. Generator-based with Zod schema validation.
ai-agent-multi-step-tools/decide.tsDecision tool with scoring logic: evaluates options against criteria using keyword matching and heuristic scoring. Shows a tool with non-trivial local computation.
ai-agent-multi-step-tools/provide-answer.tsTerminal answer tool that synthesizes all previous tool results into a final structured answer with inline citations and confidence score. Triggers agent termination via stopWhen condition.
ai-agent-multi-step-tools/schema.tsShared Zod schemas for web search tools: WebSearchItemSchema and WebSearchSchema for Perplexity Sonar responses.
Execute multi-step workflows with typed tools. Includes streaming, tool chaining, and decision-making for automated tasks.
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, PERPLEXITY_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
AgenttoolstepCountIsgenerateObjectExperimental_AgentgatewayhasToolCallProviders
External services
app/page.tsxapp/layout.tsxapp/api/multi-step-tool-agent/route.tslib/multi-step-agent.tslib/multi-step-tool-types.tslib/ai-agent-multi-step-tools/web-search.tslib/ai-agent-multi-step-tools/news-search.tslib/ai-agent-multi-step-tools/analyze.tslib/ai-agent-multi-step-tools/decide.tslib/ai-agent-multi-step-tools/provide-answer.tslib/ai-agent-multi-step-tools/schema.tscomponents/multi-step-tool-chat-demo.tsxcomponents/tool-views/web-search-view.tsxcomponents/tool-views/news-search-view.tsxcomponents/tool-views/analyze-view.tsxcomponents/tool-views/decide-view.tsxcomponents/tool-views/provide-answer-view.tsxREADME.mdnpm packages
6
Registry components
multi-step-tool-agent/route.tsAPI route wiring the agent to HTTP: uses createAgentUIStreamResponse and validateUIMessages to connect the multi-step agent to a streaming endpoint.
lib/multi-step-agent.tsCore agent definition: creates an Experimental_Agent with comprehensive system instructions, 5 registered tools, and stop conditions (hasToolCall or stepCountIs(8)).
ai-agent-multi-step-tools/web-search.tsWeb search tool using Perplexity Sonar: uses generateObject with perplexity/sonar model. Implements generator-based execute with loading/ready states.
ai-agent-multi-step-tools/news-search.tsNews search tool using HN Algolia API. Generator-based tool with loading/ready states and graceful error fallback.
ai-agent-multi-step-tools/analyze.tsAnalysis tool: breaks down complex problems into components using systematic/creative/technical approaches. Generator-based with Zod schema validation.
ai-agent-multi-step-tools/decide.tsDecision tool with scoring logic: evaluates options against criteria using keyword matching and heuristic scoring. Shows a tool with non-trivial local computation.
ai-agent-multi-step-tools/provide-answer.tsTerminal answer tool that synthesizes all previous tool results into a final structured answer with inline citations and confidence score. Triggers agent termination via stopWhen condition.
ai-agent-multi-step-tools/schema.tsShared Zod schemas for web search tools: WebSearchItemSchema and WebSearchSchema for Perplexity Sonar responses.

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.
Execute multi-step workflows with typed tools. Includes streaming, tool chaining, and decision-making for automated tasks.
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.
Execute multi-step workflows with typed tools. Includes streaming, tool chaining, and decision-making for automated tasks.
Unlock the live preview and source
Locked on free (high token spend). Pro runs the live demo and includes the source.