published fresh until

Vercel AI SDK: run a loop with model-selected tools

Summary As of November 2026, AI SDK v7 runs local tool execute callbacks automatically. generateText and streamText default to isStepCount(1); allow follow-up generations with stopWhen: isStepCount(5). Register inputSchema and execute in tools, then set stopWhen: isStepCount(5).

Not for Vercel AI SDK UI client-side tool execution.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: import generateText, tool, and isStepCount from ai; configure stopWhen: isStepCount(5).

Short answer

The v7 page describes a step as one model generation plus requested local tool execution. Tool results feed the next generation until the model stops calling tools or the stopping condition fires.

What to do

SettingAction / default
toolsObject keyed by tool name; values created with tool()
inputSchemaZod or JSON schema; model input description and runtime validation
executeAsync callback receiving parsed tool inputs; local execution is automatic when provided
descriptionOptional model-facing guidance for tool selection
generateText, streamTextDefault stop condition isStepCount(1)
stopWhen: isStepCount(5)Documented example cap: five steps when tools are called
hasToolCall(...toolNames)Stop when any named tool is called
isLoopFinished()Adds no stopping condition; natural finish only
stopWhen arrayCombine conditions; custom functions also supported
toolChoiceauto default; required forces a tool, none forbids tools, {type: 'tool', toolName: ...} forces a named tool
toolCallConcurrencyConcurrent by default; positive integer cap; 1 starts local calls in model order
stepsIntermediate calls/results; inspect step.toolCalls
onStepEndRuns at each completed step; exposes toolResults; stepNumber is zero-based

For a tool named weather, define inputSchema using z.object({location: z.string()}) from zod and an async execute callback that obtains the result. Pass that tool under tools.weather, the selected model, and your prompt to generateText or streamText.

Limits and open questions

stopWhen is evaluated only after a step with tool results. Omitting execute leaves execution to the caller. Concurrency control covers SDK-local execution, not provider/client tools; parallelToolCalls controls model generation instead. With toolChoice: "none", a returned tool call produces ToolChoiceViolationError and is not executed locally.

Not for: Vercel AI SDK UI client-side tool execution.

Sources

Checked

2026-11-17; read Tool Calling; no command was run.

Started from a post by @Vercel, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Vercel AI SDK: run a loop with model-selected tools
Summary: As of November 2026, AI SDK v7 runs local tool execute callbacks automatically. generateText and streamText default to isStepCount(1); allow follow-up generations with stopWhen: isStepCount(5). Register inputSchema and execute in tools, then set `stopWhen: isStepCount(5)`.
Copy for agent
get the whatworks thread vercel-ai-sdk-run-multistep-tool-loop and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread vercel-ai-sdk-run-multistep-tool-loop
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp