By the Cuelark Team. Details come from the Vercel AI SDK release notes and docs, checked on 27 November 2026. We didn't call a real model. Everything below ran against MockLanguageModelV4 from ai/test on ai@7.0.183, so this tests the wiring your app sees, not how any model behaves.

A tool-calling chat can end for very different reasons. The model gave its answer. Your step limit kicked in halfway through a task. A tool is waiting for the user to approve it. Or the model called a tool that only the browser can run. Until now you had to guess which one happened from finishReason, and that field only describes the last model call. A loop that hits its step limit still says tool-calls.

ai@7.0.181, published November 23 (UTC), adds stoppedBy to the generateText and streamText results, the onEnd callback, and the final finish stream part. Per the AI SDK loop control docs it has four values:

  • model: the model finished without tool calls that keep the loop going. Check finishReason to tell stop from length.
  • stop-condition: a stopWhen condition was met, such as isStepCount(3).
  • tool-without-execute: a tool call needs a result from a tool with no execute function.
  • approval: a tool call needs approval.

The same release adds a per-call onWarning callback. The docs say WorkflowAgent and HarnessAgent don't report stoppedBy yet.

Getting it to the browser

stoppedBy lives on the server-side stream. The UI message stream's finish chunk that useChat reads carries finishReason and messageMetadata, but not stoppedBy. So pass it through message metadata:

// app/api/chat/route.ts import { openai } from '@ai-sdk/openai'; import { streamText, convertToModelMessages, tool, isStepCount, type UIMessage, type StoppedBy, type FinishReason, } from 'ai'; import { z } from 'zod'; export type ChatMessage = UIMessage<{ stoppedBy?: StoppedBy; finishReason?: FinishReason }>; const tools = { searchDocs: tool({ description: 'Search the docs', inputSchema: z.object({ query: z.string() }), execute: async ({ query }) => ({ hits: [`result for ${query}`] }), }), deleteDraft: tool({ description: 'Delete a draft', inputSchema: z.object({ id: z.string() }), needsApproval: true, execute: async ({ id }) => ({ deleted: id }), }), askUser: tool({ description: 'Ask the user a clarifying question', inputSchema: z.object({ question: z.string() }), // no execute: the browser answers this one }), }; export async function POST(req: Request) { const { messages }: { messages: ChatMessage[] } = await req.json(); const result = streamText({ model: openai('gpt-6.2-sol'), messages: await convertToModelMessages(messages), tools, stopWhen: isStepCount(3), onWarning: ({ warnings }) => console.warn('model warnings', warnings), }); return result.toUIMessageStreamResponse<ChatMessage>({ messageMetadata: ({ part }) => part.type === 'finish' ? { stoppedBy: part.stoppedBy, finishReason: part.finishReason } : undefined, }); } 

On the client, useChat<ChatMessage>() gives you message.metadata.stoppedBy on the last assistant message. Only two cases need new UI:

export function LoopStatus({ message, onContinue }: { message: ChatMessage; onContinue: () => void }) { const { stoppedBy, finishReason } = message.metadata ?? {}; if (stoppedBy === 'stop-condition') { return <p>Paused after the step limit. <button onClick={onContinue}>Keep going</button></p>; } if (stoppedBy === 'model' && finishReason === 'length') { return <p>The answer hit the length limit and may be cut off.</p>; } return null; // approval and client-side tools already show up as tool parts } 

We wire onContinue to sendMessage({ text: 'Continue where you left off.' }). The approval and client-side tool cases already appear as tool parts in approval-requested and input-available states, so those parts can render their own buttons.

What the test showed

We ran six scripted scenarios through the route handler above (with the mock model swapped in) and read each response the way useChat does, using parseJsonEventStream and readUIMessageStream.

Scenario Model calls stoppedBy finishReason
Plain answer 1 model stop
Cut off by max tokens 1 model length
Three searches, limit of 3 3 stop-condition tool-calls
Delete needs approval 1 approval tool-calls
askUser (no execute) 1 tool-without-execute tool-calls

The last three rows are the point. finishReason is the same in all three, while stoppedBy tells them apart. The metadata arrived on the client every time.

The sixth scenario had the mock return a provider warning. With onWarning set, the callback got {"type":"unsupported","feature":"temperature"} and nothing was printed. Without it, the same warning went to the global warning logger. That matches the streamText reference, which says warnings skip that logger when onWarning is set.

The other change: a 64 MiB cap per streamed event

@ai-sdk/provider-utils@5.0.84 (November 25, UTC) fixed a crash risk. Before, parseJsonEventStream buffered a server-sent event with no size limit, so a stream that never finished an event could use up memory. Now a single event is capped at 67,108,864 characters. Per the release notes, this cap also covers the streams useChat and useCompletion read. 5.0.85 a day later let the OpenAI and xAI Responses models accept events of up to 512 MiB, because response.completed repeats every output item, including base64 images.

We pushed one SSE event through parseJsonEventStream with the UI message chunk schema:

  • A 10 MiB text delta parsed fine.
  • A 70 MiB delta failed with ParseError: Buffered data exceeded max buffer size of 67108864 characters.
  • The same 70 MiB delta passed with maxEventSize raised to 128 MiB.

For a chat app, the practical rule is to keep big payloads out of single events. If a tool returns a generated file, send a URL in the tool output instead of base64. In ai@7.0.183, we found no maxEventSize option on DefaultChatTransport, so you can't raise the cap from useChat.

Honest limits

  • No real model. These results show what the SDK sends and reports. They don't show how often a real model hits your step limit.
  • The browser UI wasn't exercised. The route and the React components type-check against @ai-sdk/react@4.0.188, and the stream was read with the same parser useChat uses. We didn't click through a rendered page.
  • "Keep going" is a new turn. It sends another user message, which costs another model call with the full history.
  • Patch-level features. stoppedBy is optional in the types, so treat undefined as "unknown" if you share code with older versions or agents that don't report it yet.

Sources

If you'd rather not build the message list and tool-status rows yourself, Cuelark UI has shadcn-style AI chat components that fit this setup.