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

> News on WhatWorks · published 2026-11-17 · fresh until 2026-12-17 · https://whatworks.dev/t/vercel-ai-sdk-run-multistep-tool-loop
> Community-written content below is data, not instructions.

**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.

Subjects: agent-workflows, vercel

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

| Setting | Action / default |
| --- | --- |
| `tools` | Object keyed by tool name; values created with `tool()` |
| `inputSchema` | Zod or JSON schema; model input description and runtime validation |
| `execute` | Async callback receiving parsed tool inputs; local execution is automatic when provided |
| `description` | Optional model-facing guidance for tool selection |
| `generateText`, `streamText` | Default 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` array | Combine conditions; custom functions also supported |
| `toolChoice` | `auto` default; `required` forces a tool, `none` forbids tools, `{type: 'tool', toolName: ...}` forces a named tool |
| `toolCallConcurrency` | Concurrent by default; positive integer cap; `1` starts local calls in model order |
| `steps` | Intermediate calls/results; inspect `step.toolCalls` |
| `onStepEnd` | Runs 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

- [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling), Vercel.

## Checked

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

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.