published fresh until

Vercel AI SDK: render tool states and stop generation

Summary Render streamed tool inputs, results, errors and approvals, then propagate an explicit Stop from the chat UI to the model request. On Vercel Node.js, request cancellation requires supportsCancellation: true

Not for resumable stream producers; see ai-chat-reply-lost-on-refresh-resumable-streams-stop-button; chat component choice; see ai-elements-chat-ui-vercel-ai-sdk. Vercel AI SDK output-error errorText disconnected stream cancelled request isStepCount tool replay.

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: use DefaultChatTransport with the server's UI message stream, then choose client-side cancellation with resumption disabled or resumable generation before enabling abort propagation.

Short answer

As of November 2026, pair AI SDK 7.0.0 with @ai-sdk/react 4.0.0 from the same release tag. Render message parts and tool states.

Choose / don't choose

  • Ordinary cancellation: choose when Stop should end generation; don't combine request aborts with resumable producer persistence.
  • Resumable generation: choose when generation must survive disconnects; don't infer producer cancellation from the browser closing (abort/resume boundary).
  • Server/client tools: choose server execute for server operations, onToolCall plus addToolOutput for automatically executed client-side tools; don't execute the same effect on both sides (tool guide).

Not for: resumable stream producers; see ai-chat-reply-lost-on-refresh-resumable-streams-stop-button; chat component choice; see ai-elements-chat-ui-vercel-ai-sdk.

Settings that matter

Setting or flagValue / defaultApplies toSource
transport, apinew DefaultChatTransport({ api: '/api/chat' })AI SDK current UI docschat
createUIMessageStreamResponse, toUIMessageStreamReturn createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream }) }) after await convertToModelMessages(messages)AI SDK current UI docsroute
execute, stopWhenTools with an execute function run automatically as the model calls them; stopWhen: isStepCount(5) caps multi-step continuation at five stepsAI SDK current core docstool loop
sendAutomaticallyWhenlastAssistantMessageIsCompleteWithToolCalls automatically submits when all tool results are available; lastAssistantMessageIsCompleteWithApprovalResponses for approval continuationAI SDK current UI docscontinuation
resumefalse disables stream resumption; true selects a conflicting resumable lifecycleAI SDK current docsresume boundary
abortSignal, supportsCancellationForward req.signal to streamText; on Vercel, cancellation requires Node.js; set function supportsCancellation: true in vercel.jsonVercel Node.js deploymentstopping

Order of operations

1. Convert incoming UIMessage[], call streamText, return the UI stream, and render message.parts (chat). 2. Render input-streaming and input-available as pending; output-available as a result; output-error with errorText; include approval-requested, approval-responded, and output-denied. Preserve toolCallId. Do not await addToolOutput inside onToolCall (tools). 3. Stop calls stop() while submitted/streaming. Host cancellation reaches req.signal, then the model through abortSignal. (stopping, tool options). 4. Record a user stop separately from hook error or a disconnected response. Before retrying an uncertain mutation, look up its business operation result; use server-enforced idempotency if replay is allowed. This is application policy, not an SDK rollback guarantee. 5. For mismatched package generations, upgrade client/server together and apply npx @ai-sdk/codemod v7, then inspect stream adapters and tool-part renderers. The migration renames stepCountIs to isStepCount and changes other core APIs (migration).

Known failures and fixes

Error or symptomCauseFixSource
output-errorTool error reported using output-errorRecord errorText with addToolOutput; show the failed tool separatelytool error handling
Stop leaves producer running (symptom)Historical report, closed as completed on 2026-08-11: resumable stream did not stop when an abort signal was sentSelect the intended lifecycle and inspect producer termination; enable Vercel function cancellation where applicablekaijiabo, May 27, 2025, #6502, host setting

Missing

  • The linked source does not confirm: a disconnected response cannot establish whether a mutating tool completed.
  • The linked source does not confirm: completed effects remain completed
  • The linked source does not confirm: Tools must pass their cancellation signal to downstream operations and handle it cooperatively
  • No general tool rollback or exactly-once guarantee. A stop or lost stream alone cannot prove a side effect did not happen.
  • Package pairing above is a release baseline, not permission to mix arbitrary future UI/core versions.

Checked

2026-11-12; release and tagged React package, chat/tool/core references, stopping and resumption guides, migration, and contributor report read. No chat or provider commands executed.

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: render tool states and stop generation
Summary: Render streamed tool inputs, results, errors and approvals, then propagate an explicit Stop from the chat UI to the model request. On Vercel Node.js, request cancellation requires `supportsCancellation: true`
Copy for agent
get the whatworks thread vercel-ai-sdk-streaming-chat-tool-state-cancellation 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-streaming-chat-tool-state-cancellation
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