ai 7.0.172 → 7.0.173

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -321,7 +321,7 @@ import { google } from '@ai-sdk/google';
321
321
  import { generateText } from 'ai';
322
322
 
323
323
  const result = await generateText({
324
- model: google('gemini-3.8-flash'),
324
+ model: google('gemini-4-hydrogen'),
325
325
  messages: [
326
326
  {
327
327
  role: 'user',
@@ -22,7 +22,7 @@ The `stopWhen` parameter controls when to stop execution when there are tool res
22
22
 
23
23
  If this default limit stops a tool loop that could otherwise continue, the SDK logs a warning with guidance on configuring `stopWhen`. Set `stopWhen` explicitly to choose a limit, even if you want to keep `isStepCount(20)`. Explicit stop conditions do not produce this warning.
24
24
 
25
- `WorkflowAgent.stream()` does not apply a default step limit. It continues until the model stops calling tools or another natural termination condition is met. Configure an explicit condition such as `isStepCount(20)` when you need to bound its model calls. `WorkflowAgent.generate()` stops after 20 steps by default and does not log the warning. See [WorkflowAgent Loop Control](/docs/agents/workflow-agent#loop-control) for details.
25
+ `WorkflowAgent.stream()` does not apply a default step limit. It continues until the model stops calling tools or another natural termination condition is met. Configure an explicit condition such as `isStepCount(20)` when you need to bound its model calls. `WorkflowAgent.generate()` stops after 20 steps by default and logs the same warning. See [WorkflowAgent Loop Control](/docs/agents/workflow-agent#loop-control) for details.
26
26
 
27
27
  When you provide `stopWhen`, the agent continues executing after tool calls until a stopping condition is met. When the condition is an array, execution stops when any of the conditions are met.
28
28
 
@@ -352,6 +352,6 @@ Every serverless instance that might handle a request needs the same secret, sin
352
352
 
353
353
  - Use `toolApproval` with `ToolLoopAgent`, `generateText`, and `streamText`.
354
354
  - Author approval rules as code with [Policy-Based Tool Approvals](/docs/agents/policy-tool-approvals) (`@ai-sdk/policy-opa`).
355
- - Use `needsApproval` only with [`WorkflowAgent`](/docs/agents/workflow-agent), where approvals suspend and resume durable workflow execution.
355
+ - [`WorkflowAgent`](/docs/agents/workflow-agent) supports `toolApproval` and `needsApproval`. Approvals suspend and resume durable workflow execution.
356
356
  - Subagent tools cannot use `toolApproval`; see [Subagents](/docs/agents/subagents#no-tool-approvals-in-subagents).
357
357
  - Chat SDK's `createChatTools` marks its write tools and `getUser` as needing approval. A `toolApproval` rule overrides those defaults; see [Chat Platforms](/docs/agents/chat-platforms#give-the-agent-chat-tools).
@@ -322,11 +322,11 @@ Tools without `'use step'` still work but run as regular in-memory functions wit
322
322
 
323
323
  ## Tool Approval
324
324
 
325
- For `WorkflowAgent`, human approval is configured on the tool definition with
326
- `needsApproval`. This is specific to `WorkflowAgent`; for `generateText`,
327
- `streamText`, and `ToolLoopAgent`, use `toolApproval` instead. When a workflow
328
- tool has `needsApproval` set, the agent pauses and emits an approval request to
329
- the writable stream. The workflow suspends until the user approves or denies:
325
+ Human approval is configured on the tool definition with `needsApproval` or on
326
+ the agent with `toolApproval`. The `toolApproval` configuration takes precedence
327
+ over `needsApproval`. When a tool call needs user approval, the agent pauses and
328
+ emits an approval request to the writable stream. The workflow suspends until
329
+ the user approves or denies:
330
330
 
331
331
  ```ts
332
332
  const agent = new WorkflowAgent({
@@ -356,6 +356,36 @@ const agent = new WorkflowAgent({
356
356
 
357
357
  Because the workflow is durable, the approval request survives process restarts — the user can approve hours later and the agent will resume.
358
358
 
359
+ Use `toolApproval` when approval depends on the tool set, the call, or the
360
+ runtime context, or when a tool does not set `needsApproval`. The functions in
361
+ the configuration run in workflow context, outside of the durable model steps:
362
+
363
+ ```ts
364
+ const agent = new WorkflowAgent({
365
+ model: 'anthropic/claude-sonnet-5.5',
366
+ tools: {
367
+ bookFlight: tool({
368
+ description: 'Book a flight',
369
+ inputSchema: z.object({ flightId: z.string() }),
370
+ execute: bookFlightStep,
371
+ }),
372
+ },
373
+ toolApproval: {
374
+ bookFlight: 'user-approval',
375
+ },
376
+ });
377
+ ```
378
+
379
+ A call that the configuration marks as `'approved'` runs in the same step. A
380
+ call that it marks as `'denied'` does not run: the model receives an
381
+ `execution-denied` tool result and the loop continues. Neither decision pauses
382
+ the workflow. `step.content` records both decisions with an automatic approval
383
+ request and an approval response. Two details differ from `ToolLoopAgent`. The
384
+ tool message in `step.response.messages` holds only the tool result, while
385
+ `ToolLoopAgent` also adds the approval response part there. In `stream()`, the
386
+ approval parts follow the tool results in `step.content`, while `ToolLoopAgent`
387
+ places them next to the tool calls.
388
+
359
389
  ### Signed Tool Approvals
360
390
 
361
391
  Client-supplied message history can be modified before it is replayed to the
@@ -404,7 +434,7 @@ The stream-level value overrides the constructor default.
404
434
  `stream()` does not apply a default step limit. When `stopWhen` is omitted, it
405
435
  continues until the model stops calling tools or another natural termination
406
436
  condition is met. `generate()` stops after 20 steps by default, like
407
- `ToolLoopAgent`, but does not log a warning when it reaches that limit.
437
+ `ToolLoopAgent`, and logs the same warning when it reaches that limit.
408
438
 
409
439
  <Note>
410
440
  A model that repeatedly calls tools can make an unlimited number of model
@@ -596,8 +626,8 @@ const agent = new WorkflowAgent({
596
626
  A `model`, `toolChoice`, `activeTools`, or generation setting returned from
597
627
  `prepareStep` applies to the current step only, as in `ToolLoopAgent`. Later
598
628
  steps use the agent or call values again unless `prepareStep` returns an
599
- override for them too. Returned `messages`, `system`, `runtimeContext`, and
600
- `toolsContext` values stay in effect for later steps.
629
+ override for them too. Returned `messages`, `instructions`, `runtimeContext`,
630
+ and `toolsContext` values stay in effect for later steps.
601
631
 
602
632
  `prepareStep` can also be passed per call in `generate()` and `stream()`.
603
633
  `prepareCall` is a constructor option only.
@@ -689,37 +719,35 @@ TypeScript rejects these options on `WorkflowAgent`. If you pass them anyway, fo
689
719
 
690
720
  | ToolLoopAgent option | With WorkflowAgent |
691
721
  | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
692
- | `toolApproval` | Set `needsApproval` on each tool. See [Tool Approval](#tool-approval). |
693
722
  | `toolOrder` | Not supported. Tools are sent in the order of the `tools` object. |
694
723
  | `callOptionsSchema` and the `options` call parameter | Not supported. Pass settings to `generate()` or `stream()` directly. |
695
- | `experimental_refineToolInput` | Not supported. |
696
724
  | `experimental_toolCallers` | Not supported. |
697
725
  | `experimental_steering` | Not supported. To add messages between steps, return `messages` from `prepareStep`. |
698
726
  | `experimental_transform` | Not supported. Transform `run.readable` with `pipeThrough()` where you create the response. |
699
727
  | `onStepError` | Not supported. Use `onError`. |
700
728
  | `onLanguageModelCallStart`, `onLanguageModelCallEnd` | Not supported. |
701
729
  | `include` in the constructor | Pass `include` to `generate()`. `stream()` has no `include` option and does not record request data in its steps. Use `includeRawChunks` to receive raw provider chunks. |
702
- | `timeout` in the constructor, and `timeout` as an object | Pass `timeout` as a number of milliseconds to `generate()` or `stream()`. An object value fails with a `TypeError`. |
730
+ | `timeout` in the constructor | Pass `timeout` to `generate()` or `stream()`. |
703
731
  | `experimental_telemetry` | Use `telemetry`. |
704
732
  | `experimental_onToolCallStart`, `experimental_onToolCallFinish` | Use `onToolExecutionStart` and `onToolExecutionEnd`. |
705
733
 
706
734
  ### Options with a different shape
707
735
 
708
- | Option | ToolLoopAgent | WorkflowAgent |
709
- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
710
- | Generation settings, `instructions`, `toolChoice`, `activeTools`, `stopWhen`, `output`, `telemetry`, `prepareStep`, `repairToolCall` | Constructor only. Use `prepareCall` to change them per call. | Constructor, or per call in `generate()` and `stream()`. The per-call value overrides the constructor value. |
711
- | `abortSignal` | Per call. | Constructor or per call. |
712
- | `experimental_sandbox` | Per call. | Constructor or per call. |
713
- | `timeout` | A number or an object, in the constructor or per call. | A number, per call. It sets a deadline for model calls and does not cancel a tool that waits on a hook. See [Deadlines, cancellation, and replay](#deadlines-cancellation-and-replay). |
714
- | `experimental_toolApprovalSecret` | The secret, as a `string` or `Uint8Array`. | `{ environmentVariable: string }`, the name of an environment variable that holds the secret. See [Signed Tool Approvals](#signed-tool-approvals). |
715
- | `runtimeContext`, `toolsContext` | Any JavaScript value. | Serializable values. See [runtimeContext and toolsContext](#runtimecontext-and-toolscontext). |
736
+ | Option | ToolLoopAgent | WorkflowAgent |
737
+ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
738
+ | Generation settings, `instructions`, `toolChoice`, `activeTools`, `stopWhen`, `output`, `telemetry`, `prepareStep`, `repairToolCall` | Constructor only. Use `prepareCall` to change them per call. | Constructor, or per call in `generate()` and `stream()`. The per-call value overrides the constructor value. |
739
+ | `abortSignal` | Per call. | Constructor or per call. |
740
+ | `experimental_sandbox` | Per call. | Constructor or per call. |
741
+ | `timeout` | A number or an object, in the constructor or per call. | A number or an object, per call. The object has no tool timeouts, and `stepMs` covers the model call without tool execution. See [Deadlines, cancellation, and replay](#deadlines-cancellation-and-replay). |
742
+ | `experimental_toolApprovalSecret` | The secret, as a `string` or `Uint8Array`. | `{ environmentVariable: string }`, the name of an environment variable that holds the secret. See [Signed Tool Approvals](#signed-tool-approvals). |
743
+ | `runtimeContext`, `toolsContext` | Any JavaScript value. | Serializable values. See [runtimeContext and toolsContext](#runtimecontext-and-toolscontext). |
716
744
 
717
745
  ### Default step limit
718
746
 
719
747
  | | `generate()` | `stream()` |
720
748
  | --------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
721
749
  | `ToolLoopAgent` | 20 steps. A warning is logged when the limit stops the loop. | 20 steps. A warning is logged when the limit stops the loop. |
722
- | `WorkflowAgent` | 20 steps. No warning is logged. | No limit. |
750
+ | `WorkflowAgent` | 20 steps. A warning is logged when the limit stops the loop. | No limit. |
723
751
 
724
752
  ### prepareCall
725
753
 
@@ -732,11 +760,8 @@ In `ToolLoopAgent`, `prepareCall` receives the settings together with the `promp
732
760
  ### prepareStep
733
761
 
734
762
  - `messages` uses the provider prompt format (`LanguageModelV4Prompt`) in the argument and in the return value, and it includes the system message. `ToolLoopAgent` uses `ModelMessage[]` without the system message.
735
- - The argument has no `instructions` and no `responseMessages`. `initialInstructions` and `initialMessages` are available.
736
- - To change the system prompt, return `system` as a string. A returned `instructions` value is ignored.
737
- - A returned `providerOptions` object replaces the `providerOptions` of the agent. `ToolLoopAgent` merges the two objects.
738
- - You can return `headers`. They replace all headers of the call, including the `user-agent` value that identifies the agent. `ToolLoopAgent` does not accept `headers` from `prepareStep`.
739
- - You cannot return `toolOrder`.
763
+ - The argument has no `responseMessages`. `initialInstructions`, `instructions`, and `initialMessages` are available.
764
+ - You can return `headers`. They are merged over the headers of the call, and the request keeps the `user-agent` value that identifies the agent. `ToolLoopAgent` does not accept `headers` from `prepareStep`.
740
765
 
741
766
  ### Callbacks
742
767
 
@@ -758,7 +783,6 @@ The callbacks also run at different times:
758
783
  - After a failed run, `stream()` calls `onEnd` before it rejects. `generate()` and `ToolLoopAgent` do not call `onEnd` for a failed run.
759
784
  - `onAbort` is called by `generate()` and by `stream()`, and its event has only `steps`. `ToolLoopAgent` calls `onAbort` only for `stream()`, with `callId`, `reason`, and `steps`.
760
785
  - An aborted `stream()` call resolves with the steps that finished. An aborted `generate()` call rejects.
761
- - If `generate()` is aborted during a step with a custom abort reason, it calls `onError` with that reason. `ToolLoopAgent` does not report aborts to `onError`.
762
786
 
763
787
  ### Results
764
788
 
@@ -772,22 +796,25 @@ The callbacks also run at different times:
772
796
  - `output` is `undefined` unless you set an `output` specification. `ToolLoopAgent` defaults to the generated text.
773
797
  - If the structured output cannot be parsed, the `stream()` call rejects. In `ToolLoopAgent`, the call resolves and only `result.output` rejects.
774
798
  - If the model call throws, the `stream()` call rejects with that error. In `ToolLoopAgent`, the call resolves and the error is reported through the stream and `onError`.
775
- - Each step is a plain object. Its `request` is empty, its `model.provider` is derived from the model ID of the response and can differ from the provider name, and its `providerMetadata` is `{}` when the provider sends none. Steps from `generate()` match `ToolLoopAgent`.
776
- - A tool call for an unknown tool, or with input that does not match the schema, is missing from `content` and `toolCalls` of the step. The model still receives the error as a tool result and the loop continues. `generate()` and `ToolLoopAgent` keep the call in the step, marked `invalid`, with a `tool-error` part.
777
-
778
- `WorkflowAgent` does not log provider warnings. Read them from `warnings` on each step.
799
+ - Each step is a plain object. Its `request` is empty, and its `providerMetadata` is `{}` when the provider sends none. Steps from `generate()` match `ToolLoopAgent`.
779
800
 
780
801
  ### Tools
781
802
 
782
- - Approval is configured with `needsApproval` on the tool. Approval request IDs have the form `approval-<toolCallId>`. `ToolLoopAgent` generates random IDs.
783
- - A tool whose `execute` function is an async generator is not supported. `ToolLoopAgent` treats every yielded value except the last one as a preliminary result. `WorkflowAgent` does not iterate the generator, and the tool result is an empty object.
784
- - In `stream()`, the `onInputStart` and `onInputAvailable` hooks of a tool are not called when the provider sends the tool call without streaming its input first. They are called in `generate()`.
803
+ - Approval is configured with `needsApproval` on the tool or `toolApproval` on the agent. Approval request IDs have the form `approval-<toolCallId>`. `ToolLoopAgent` generates random IDs.
804
+ - For a tool whose `execute` function is an async generator, the last yielded value is the tool result, as in `ToolLoopAgent`. `ToolLoopAgent` also reports the earlier values as preliminary results. `WorkflowAgent` does not send them to the `writable`.
785
805
  - Tool timeouts (`toolMs` and `tools` in the `timeout` object) are not supported.
806
+ - `experimental_refineToolInput` functions run in the workflow context after the model step returns. The `tool-call` chunk that `stream()` writes to `writable` for a tool without its own runtime validator, and the input of provider-executed tool calls, keep the unrefined value.
786
807
 
787
808
  ### Requests
788
809
 
789
810
  Requests carry `ai-sdk-agent/workflow` in the `user-agent` header. `ToolLoopAgent` sends `ai-sdk-agent/tool-loop`.
790
811
 
812
+ ### Timeouts
813
+
814
+ - `stepMs` limits one model call. In `ToolLoopAgent` it also covers the tool calls of the step.
815
+ - `generate()` ignores `firstChunkMs` and `chunkMs`. `ToolLoopAgent` also logs a warning for them.
816
+ - A timeout value that is not a finite number, or that is larger than 2147483647, is rejected with an `InvalidArgumentError`. So is a negative `stepMs`, `firstChunkMs`, or `chunkMs`. `ToolLoopAgent` does not validate the values.
817
+
791
818
  ## Migrating from `DurableAgent`
792
819
 
793
820
  `WorkflowAgent` replaces the Workflow DevKit's [`DurableAgent`](https://workflow-sdk.dev/docs/api-reference/workflow-ai/durable-agent). The two share the same core idea — a durable agent loop that runs inside a workflow — but `WorkflowAgent` moves the class into the AI SDK, tightens typing, and introduces first-class tool approval. If you are using `DurableAgent` today, follow the steps below to switch.
@@ -955,7 +982,33 @@ Local tools execute only after approval validation; denied tools produce an exec
955
982
 
956
983
  #### Deadlines, cancellation, and replay
957
984
 
958
- Inside a workflow, `timeout` sets an absolute deadline for model calls. Each model step checks it before dispatch, before SDK retry attempts, and after the provider returns. The same deadline remains in effect after a tool suspends and resumes. SDK `maxRetries` governs model retries; the durable model step does not add another retry layer. Expiration before dispatch rejects with `TimeoutError`; expiration during SDK retry backoff rejects with `AbortError`. Neither starts a new retry.
985
+ `timeout` accepts a number of milliseconds or an object:
986
+
987
+ ```ts
988
+ const result = await agent.stream({
989
+ messages,
990
+ timeout: {
991
+ totalMs: 5 * 60_000,
992
+ stepMs: 60_000,
993
+ firstChunkMs: 15_000,
994
+ chunkMs: 10_000,
995
+ },
996
+ });
997
+ ```
998
+
999
+ A number has the same meaning as `totalMs`. Inside a workflow, it sets an absolute deadline for model calls. Each model step checks it before dispatch, before SDK retry attempts, and after the provider returns. The same deadline remains in effect after a tool suspends and resumes. SDK `maxRetries` governs model retries; the durable model step does not add another retry layer. Expiration before dispatch rejects with `TimeoutError`; expiration during SDK retry backoff rejects with `AbortError`. Neither starts a new retry.
1000
+
1001
+ The other values apply to one model call and start again for the next one:
1002
+
1003
+ - `stepMs` limits the whole model call: dispatch, SDK retries, and reading the response. Tool execution is not part of it.
1004
+ - `firstChunkMs` limits the wait for the first output of the model call, counted from the start of the response stream.
1005
+ - `chunkMs` limits the wait between two outputs.
1006
+
1007
+ `firstChunkMs` and `chunkMs` are used by `stream()` only. Only generated output counts for them: files, tool calls, and text, reasoning, or tool-input deltas that are not empty. Response metadata, start and end markers, and empty deltas do not start or reset these timers.
1008
+
1009
+ When one of these limits is reached, the model call is aborted with a `TimeoutError` and the run ends like an aborted run: `stream()` resolves with the steps that finished, `generate()` rejects with the error, and both call `onAbort`. The timers run inside the durable model step. A model step that has completed is not timed again on replay.
1010
+
1011
+ Each value must be a finite number of at most 2147483647, which is about 24.8 days. A negative `timeout` or `totalMs` is a deadline that has already passed. Any other invalid value is rejected with an `InvalidArgumentError` before the first model call.
959
1012
 
960
1013
  A model deadline does not cancel a tool waiting on a Workflow hook. The run can remain suspended after that deadline. Once the hook resumes, any subsequent model call fails before dispatch if the deadline has expired. To stop the suspended run, use the Workflow runtime's `run.cancel()` API. Cancellation does not undo external side effects that already happened.
961
1014
 
@@ -1,6 +1,11 @@
1
1
  ---
2
2
  title: Generating Text
3
3
  description: Learn how to generate text with the AI SDK.
4
+ keywords:
5
+ - text generation
6
+ - generate text
7
+ - stream text
8
+ - streaming text
4
9
  ---
5
10
 
6
11
  # Generating and Streaming Text
@@ -722,7 +727,7 @@ When you use `generateText`, you can access the sources using the `sources` prop
722
727
 
723
728
  ```ts
724
729
  const result = await generateText({
725
- model: 'google/gemini-3.8-flash',
730
+ model: 'google/gemini-4-hydrogen',
726
731
  tools: {
727
732
  google_search: google.tools.googleSearch({}),
728
733
  },
@@ -744,7 +749,7 @@ When you use `streamText`, you can access the sources using the `stream` propert
744
749
 
745
750
  ```tsx
746
751
  const result = streamText({
747
- model: 'google/gemini-3.8-flash',
752
+ model: 'google/gemini-4-hydrogen',
748
753
  tools: {
749
754
  google_search: google.tools.googleSearch({}),
750
755
  },
@@ -1,6 +1,10 @@
1
1
  ---
2
2
  title: Generating Structured Data
3
3
  description: Learn how to generate structured data with the AI SDK.
4
+ keywords:
5
+ - structured output
6
+ - structured outputs
7
+ - structured data
4
8
  ---
5
9
 
6
10
  # Generating Structured Data
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  title: Model Context Protocol (MCP)
3
3
  description: Learn how to connect to Model Context Protocol (MCP) servers and use their tools with AI SDK Core.
4
+ keywords:
5
+ - mcp
6
+ - model context protocol
4
7
  ---
5
8
 
6
9
  # Model Context Protocol (MCP)
@@ -40,7 +40,7 @@ The `reasoning` parameter works the same way with `streamText`:
40
40
  import { streamText } from 'ai';
41
41
 
42
42
  const result = streamText({
43
- model: 'google/gemini-3.8-flash',
43
+ model: 'google/gemini-4-hydrogen',
44
44
  reasoning: 'high',
45
45
  prompt: 'Explain the Riemann hypothesis in simple terms.',
46
46
  });
@@ -153,7 +153,7 @@ If you need to enforce an exact token budget (e.g. exactly 12000 tokens), keep u
153
153
 
154
154
  ```ts
155
155
  const { text } = await generateText({
156
- model: google('gemini-3.8-flash'),
156
+ model: google('gemini-4-hydrogen'),
157
157
  providerOptions: {
158
158
  google: {
159
159
  thinkingConfig: { thinkingLevel: 'high', includeThoughts: true },
@@ -167,7 +167,7 @@ const { text } = await generateText({
167
167
 
168
168
  ```ts
169
169
  const { text } = await generateText({
170
- model: google('gemini-3.8-flash'),
170
+ model: google('gemini-4-hydrogen'),
171
171
  reasoning: 'high',
172
172
  providerOptions: {
173
173
  google: { thinkingConfig: { includeThoughts: true } },
@@ -109,6 +109,7 @@ Use a provider's `decisionModel` factory:
109
109
  | OpenAI | `openai.decisionModel('gpt-6-luna')` |
110
110
  | Anthropic | `anthropic.decisionModel('claude-haiku-4-5-20251001')` |
111
111
  | Google | `google.decisionModel('gemini-decision-1')` |
112
+ | HeyGen | `heygen.decisionModel('heygen-decision-1')` |
112
113
 
113
114
  TypeSafe AI's [Jev](https://vercel.com/i/what-is-jev), OpenAI's
114
115
  [Decisions API](https://developers.openai.com/api/docs/guides/decisions),
@@ -296,6 +297,9 @@ Perplexity exposes Choice/Score confidence at
296
297
  Google exposes confidence for all three question types at
297
298
  `result.providerMetadata?.google?.confidence` and Score legends at
298
299
  `result.providerMetadata?.google?.legend`, also keyed by question ID.
300
+ HeyGen exposes Choice/Score confidence at
301
+ `result.providerMetadata?.heygen?.confidence` and Score legends at
302
+ `result.providerMetadata?.heygen?.legend`, also keyed by question ID.
299
303
 
300
304
  Check for optional distributions before using them. For example, an application
301
305
  can route only when a provider supplies a sufficiently high selected-option
@@ -109,7 +109,7 @@ Use a provider's `extractionModel` factory:
109
109
  | --------- | ------------------------------------------------ |
110
110
  | OpenAI | `openai.extractionModel('gpt-6.1-sol')` |
111
111
  | Anthropic | `anthropic.extractionModel('claude-sonnet-5-5')` |
112
- | Google | `google.extractionModel('gemini-3.8-flash')` |
112
+ | Google | `google.extractionModel('gemini-4-hydrogen')` |
113
113
 
114
114
  These adapt structured language-model output and extract every field in one
115
115
  prompt. Anthropic sends more than 16 fields as parallel calls, see
@@ -1,6 +1,8 @@
1
1
  ---
2
2
  title: Image Generation
3
3
  description: Learn how to generate images with the AI SDK.
4
+ keywords:
5
+ - generate images
4
6
  ---
5
7
 
6
8
  # Image Generation
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  title: Transcription
3
3
  description: Learn how to transcribe audio with the AI SDK.
4
+ keywords:
5
+ - speech to text
6
+ - audio transcription
4
7
  ---
5
8
 
6
9
  # Transcription
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  title: Speech
3
3
  description: Learn how to generate speech from text with the AI SDK.
4
+ keywords:
5
+ - text to speech
6
+ - speech generation
4
7
  ---
5
8
 
6
9
  # Speech
@@ -7,6 +7,12 @@ description: API Reference for validateUIMessages
7
7
 
8
8
  `validateUIMessages` is an async function that validates UI messages against schemas for metadata, data parts, and tools. It ensures type safety and data integrity for your message arrays before processing or rendering.
9
9
 
10
+ Structural validation stops at the first invalid element in message and part arrays.
11
+ Part types and tool states select the applicable schema before its fields are validated.
12
+ The error retains the failing element's path without accumulating errors for every
13
+ malformed element. Valid message and part arrays have no SDK-imposed count limit;
14
+ apply request size and message history limits appropriate for your application.
15
+
10
16
  ## Basic Usage
11
17
 
12
18
  Simple validation without custom schemas:
@@ -7,6 +7,9 @@ description: API Reference for safeValidateUIMessages
7
7
 
8
8
  `safeValidateUIMessages` is an async function that validates UI messages like [`validateUIMessages`](/docs/reference/ai-sdk-core/validate-ui-messages), but instead of throwing it returns an object with a `success` key and either `data` or `error`.
9
9
 
10
+ Structural validation stops at the first invalid element in message and part
11
+ arrays, retaining its path in the returned error.
12
+
10
13
  ## Basic Usage
11
14
 
12
15
  Simple validation without custom schemas:
@@ -117,6 +117,13 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
117
117
  description:
118
118
  'Default set of active tools. Limits which tools the model can call without changing tool call and result types. Per-stream values override this default.',
119
119
  },
120
+ {
121
+ name: 'toolOrder',
122
+ type: 'ToolOrder<TTools>',
123
+ isOptional: true,
124
+ description:
125
+ 'Controls the order in which tools are sent to the provider. The list can be partial. Tools not listed in `toolOrder` are sent after the listed tools, sorted alphabetically. Tool names are restricted to the string keys of the tool set.',
126
+ },
120
127
  {
121
128
  name: 'output',
122
129
  type: 'OutputSpecification',
@@ -131,6 +138,13 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
131
138
  description:
132
139
  "Default function to repair tool calls that fail to parse. Mark the function with 'use step' when used in a workflow. Per-stream values override this default.",
133
140
  },
141
+ {
142
+ name: 'experimental_refineToolInput',
143
+ type: 'ToolInputRefinement<TTools>',
144
+ isOptional: true,
145
+ description:
146
+ 'Optional mapping of tool names to functions that refine parsed tool inputs. Each function receives the typed input for its tool and must return the same input type shape. The refined input is used for tool execution, output parts, lifecycle callbacks, and telemetry in both `generate()` and `stream()`. Per-stream values override this default.',
147
+ },
134
148
  {
135
149
  name: 'experimental_download',
136
150
  type: 'DownloadFunction',
@@ -145,6 +159,13 @@ To see `WorkflowAgent` in action, check out [these examples](#examples).
145
159
  description:
146
160
  'Default sandbox session passed to tool descriptions and execution as `experimental_sandbox`, and exposed to `prepareStep`. Per-stream values override this default.',
147
161
  },
162
+ {
163
+ name: 'toolApproval',
164
+ type: 'ToolApprovalConfiguration<TTools, TRuntimeContext>',
165
+ isOptional: true,
166
+ description:
167
+ "Default approval configuration for tool calls. Pass a `GenericToolApprovalFunction` to handle all tool calls in one callback with `toolCall`, `tools`, `toolsContext`, `messages`, and `runtimeContext`, or pass a per-tool object where each key can be a status (`'not-applicable'`, `'approved'`, `'denied'`, or `'user-approval'`), an object form such as `{ type: 'denied', reason: 'blocked by policy' }`, or a `SingleToolApprovalFunction` that receives the tool input and options `toolCallId`, `messages`, `toolContext`, and `runtimeContext`. This setting takes precedence over a tool's `needsApproval` default. The functions in the configuration run in workflow context, outside of the durable model steps, and are never passed across a step boundary. Per-stream values override this default.",
168
+ },
148
169
  {
149
170
  name: 'experimental_toolApprovalSecret',
150
171
  type: 'WorkflowToolApprovalSecret',
@@ -628,6 +649,13 @@ In addition to the options in the table, `stream()` accepts the generation setti
628
649
  isOptional: true,
629
650
  description: 'Limits the subset of tools available for this call without changing tool call and result types.',
630
651
  },
652
+ {
653
+ name: 'toolOrder',
654
+ type: 'ToolOrder<TTools>',
655
+ isOptional: true,
656
+ description:
657
+ 'Controls the order in which tools are sent to the provider. The list can be partial. Tools not listed in `toolOrder` are sent after the listed tools, sorted alphabetically. Tool names are restricted to the string keys of the tool set.',
658
+ },
631
659
  {
632
660
  name: 'output',
633
661
  type: 'OutputSpecification',
@@ -637,9 +665,9 @@ In addition to the options in the table, `stream()` accepts the generation setti
637
665
  },
638
666
  {
639
667
  name: 'timeout',
640
- type: 'number',
668
+ type: 'WorkflowAgentTimeoutConfiguration',
641
669
  isOptional: true,
642
- description: 'Model-call deadline in milliseconds. Inside a workflow, the absolute deadline is checked at dispatch and retry and remains in effect across suspension. It does not cancel a tool waiting on a Workflow hook; use run.cancel() to stop the suspended run.',
670
+ description: 'Timeout for model calls. A number, or `totalMs` in the object form, is one deadline in milliseconds for the whole run. Inside a workflow, the absolute deadline is checked at dispatch and retry and remains in effect across suspension. `stepMs` limits each model call. `firstChunkMs` limits the wait for the first output of each model call, and `chunkMs` limits the wait between two outputs. A timeout does not cancel a tool waiting on a Workflow hook; use run.cancel() to stop the suspended run.',
643
671
  },
644
672
  {
645
673
  name: 'sendFinish',
@@ -665,6 +693,13 @@ In addition to the options in the table, `stream()` accepts the generation setti
665
693
  isOptional: true,
666
694
  description: "Callback to attempt automatic recovery when a tool call cannot be parsed. Mark the function with 'use step' when used in a workflow.",
667
695
  },
696
+ {
697
+ name: 'experimental_refineToolInput',
698
+ type: 'ToolInputRefinement<TTools>',
699
+ isOptional: true,
700
+ description:
701
+ 'Optional mapping of tool names to functions that refine parsed tool inputs. Each function receives the typed input for its tool and must return the same input type shape. The refined input is used for tool execution, output parts, lifecycle callbacks, and telemetry in both `generate()` and `stream()`. Overrides the constructor default.',
702
+ },
668
703
  {
669
704
  name: 'experimental_download',
670
705
  type: 'DownloadFunction',
@@ -679,6 +714,13 @@ In addition to the options in the table, `stream()` accepts the generation setti
679
714
  description:
680
715
  'Sandbox session passed to tool descriptions and execution as `experimental_sandbox`, and exposed to `prepareStep`. Overrides the constructor default.',
681
716
  },
717
+ {
718
+ name: 'toolApproval',
719
+ type: 'ToolApprovalConfiguration<TTools, TRuntimeContext>',
720
+ isOptional: true,
721
+ description:
722
+ "Approval configuration for tool calls. Pass a `GenericToolApprovalFunction` to handle all tool calls in one callback with `toolCall`, `tools`, `toolsContext`, `messages`, and `runtimeContext`, or pass a per-tool object where each key can be a status (`'not-applicable'`, `'approved'`, `'denied'`, or `'user-approval'`), an object form such as `{ type: 'denied', reason: 'blocked by policy' }`, or a `SingleToolApprovalFunction` that receives the tool input and options `toolCallId`, `messages`, `toolContext`, and `runtimeContext`. This setting takes precedence over a tool's `needsApproval` default. The functions in the configuration run in workflow context, outside of the durable model steps, and are never passed across a step boundary. Overrides the constructor default.",
723
+ },
682
724
  {
683
725
  name: 'experimental_toolApprovalSecret',
684
726
  type: 'WorkflowToolApprovalSecret',
@@ -912,6 +954,21 @@ type ActiveTools<TTools extends ToolSet> =
912
954
 
913
955
  Limits a workflow agent call to the listed tool names. `undefined` means no tool restriction is applied.
914
956
 
957
+ ### `WorkflowAgentTimeoutConfiguration`
958
+
959
+ ```ts
960
+ type WorkflowAgentTimeoutConfiguration =
961
+ | number
962
+ | {
963
+ totalMs?: number;
964
+ stepMs?: number;
965
+ firstChunkMs?: number;
966
+ chunkMs?: number;
967
+ };
968
+ ```
969
+
970
+ The `timeout` option of `generate()` and `stream()`. A number is the total deadline in milliseconds. `generate()` uses `totalMs` and `stepMs`. `stream()` uses all four values. See [Deadlines, cancellation, and replay](/docs/agents/workflow-agent#deadlines-cancellation-and-replay).
971
+
915
972
  ### `InferWorkflowAgentUIMessage`
916
973
 
917
974
  Infers the UI message type for a `WorkflowAgent` instance. Optionally accepts a second type argument for custom message metadata.
@@ -1079,9 +1136,9 @@ console.log(result.output);
1079
1136
 
1080
1137
  ### Agent with Tool Approval
1081
1138
 
1082
- For `WorkflowAgent`, tool approval is configured on the tool definition with
1083
- `needsApproval`. For `generateText`, `streamText`, and `ToolLoopAgent`, use
1084
- `toolApproval` instead.
1139
+ Tool approval is configured on the tool definition with `needsApproval` or on
1140
+ the agent with `toolApproval`. The `toolApproval` configuration takes precedence
1141
+ over `needsApproval`.
1085
1142
 
1086
1143
  ```ts
1087
1144
  import { WorkflowAgent } from '@ai-sdk/workflow';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "7.0.172",
3
+ "version": "7.0.173",
4
4
  "type": "module",
5
5
  "description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
6
6
  "license": "Apache-2.0",
@@ -42,20 +42,20 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@ai-sdk/gateway": "4.0.145",
45
+ "@ai-sdk/gateway": "4.0.146",
46
46
  "@ai-sdk/provider": "4.0.38",
47
47
  "@ai-sdk/provider-utils": "5.0.81"
48
48
  },
49
49
  "devDependencies": {
50
- "@ai-sdk/amazon-bedrock": "5.0.141",
51
- "@ai-sdk/deepseek": "3.0.86",
52
- "@ai-sdk/google": "4.0.120",
53
- "@ai-sdk/groq": "4.0.83",
54
- "@ai-sdk/huggingface": "2.0.92",
55
- "@ai-sdk/moonshotai": "3.0.92",
56
- "@ai-sdk/openai": "4.0.117",
50
+ "@ai-sdk/amazon-bedrock": "5.0.142",
51
+ "@ai-sdk/deepseek": "3.0.87",
52
+ "@ai-sdk/google": "4.0.121",
53
+ "@ai-sdk/groq": "4.0.84",
54
+ "@ai-sdk/huggingface": "2.0.93",
55
+ "@ai-sdk/moonshotai": "3.0.93",
56
+ "@ai-sdk/openai": "4.0.118",
57
57
  "@ai-sdk/test-server": "2.0.4",
58
- "@ai-sdk/xai": "5.0.45",
58
+ "@ai-sdk/xai": "5.0.46",
59
59
  "@edge-runtime/vm": "^5.0.0",
60
60
  "@smithy/eventstream-codec": "^4.3.3",
61
61
  "@smithy/util-utf8": "^4.3.3",