ai 7.0.180 → 7.0.181
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.
- package/CHANGELOG.md +11 -0
- package/dist/{default-stop-condition-vtYEJcnz.js → default-stop-condition-D8PwkeWe.js} +52 -27
- package/dist/default-stop-condition-D8PwkeWe.js.map +1 -0
- package/dist/{index-CM_8u8gB.d.ts → index-CKEJqCzY.d.ts} +69 -4
- package/dist/index-CKEJqCzY.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +192 -119
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +8 -4
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-agents/04-loop-control.mdx +35 -1
- package/docs/03-agents/08-terminal-ui.mdx +10 -0
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +6 -0
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +21 -0
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +19 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +25 -0
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +7 -0
- package/docs/07-reference/06-ai-sdk-tui/01-run-agent-tui.mdx +3 -0
- package/package.json +4 -4
- package/src/agent/default-stop-condition.ts +12 -3
- package/src/agent/tool-loop-agent-settings.ts +11 -0
- package/src/agent/tool-loop-agent.ts +3 -1
- package/src/extract/restricted-telemetry-dispatcher.ts +9 -5
- package/src/generate-text/default-generate-text-result.ts +4 -0
- package/src/generate-text/generate-text-events.ts +7 -0
- package/src/generate-text/generate-text-result.ts +9 -0
- package/src/generate-text/generate-text.ts +37 -5
- package/src/generate-text/index.ts +1 -0
- package/src/generate-text/steering.ts +19 -5
- package/src/generate-text/stopped-by.ts +43 -0
- package/src/generate-text/stream-language-model-call.ts +21 -2
- package/src/generate-text/stream-text-result.ts +18 -0
- package/src/generate-text/stream-text.ts +59 -6
- package/src/logger/create-log-warnings.ts +17 -0
- package/src/model/as-language-model-v3.ts +3 -0
- package/src/model/as-language-model-v4.ts +5 -1
- package/src/model/resolve-model.ts +8 -3
- package/src/prompt/convert-to-language-model-prompt.ts +15 -6
- package/src/util/log-v2-compatibility-warning.ts +5 -2
- package/dist/default-stop-condition-vtYEJcnz.js.map +0 -1
- package/dist/index-CM_8u8gB.d.ts.map +0 -1
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Al as LanguageModelUsage, Ao as ToolApprovalStatus, Ba as GenerateTextOnEndCallback, Bc as Instructions, Ca as TelemetryDispatcher, Dl as Warning, Eo as ResolvedToolCallers, Fc as ToolModelMessage$1, Ga as GenerateTextOnStepFinishCallback, Go as StoppedBy, Gs as DefaultStepResult, Ha as GenerateTextOnStartCallback, Hl as ResponseMessage, Jl as LanguageModel, Jo as InferCompleteOutput, Ka as GenerateTextOnStepStartCallback, Ko as StaticToolOutputDenied, Ml as asLanguageModelUsage, Nl as createNullLanguageModelUsage, Qo as createAsyncIterableStream, Qs as TypedToolResult, So as ToolCallRepairFunction, Tc as AssistantModelMessage$1, Tl as logWarnings, Ua as GenerateTextOnStepEndCallback, Ul as LanguageModelRequestMetadata, Vl as LanguageModelResponseMetadata, Vo as ToolOrder, Wa as GenerateTextOnStepErrorCallback, Xs as DynamicToolResult, Yl as ToolChoice, Ys as ContentPart, Zs as StaticToolResult, _a as LanguageModelStreamPart, _c as Callback, _o as OnToolExecutionEndCallback, ac as StaticToolCall, cc as ReasoningOutput, dc as GeneratedFile, el as LanguageModelCallOptions, fc as IncludedContext, ga as GenerateTextResult, ic as DynamicToolCall, jl as addLanguageModelUsage, ko as ToolApprovalConfiguration, mc as TelemetryOptions, mo as ToolInputRefinement, nc as ToolApprovalResponseOutput, oc as TypedToolCall, pc as IncludedToolsContext, po as ToolsContextSettings, ql as FinishReason, qs as StepResult, rc as ToolApprovalRequestOutput, sc as ReasoningFileOutput, to as Output, vc as StandardizedPrompt, vl as DownloadFunction, vo as OnToolExecutionStartCallback, wl as LogWarningsFunction, wo as InvalidToolInputError, xo as ToolOutput, yc as standardizePrompt, yl as createDefaultDownloadFunction, za as GenerateTextOnAbortCallback } from "../index-CKEJqCzY.js";
|
|
2
2
|
import { Arrayable, Context, Experimental_SandboxSession, FlexibleSchema, IdGenerator, InferToolSetContext, ModelMessage, RetryFunction, ShouldRetryFunction, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolResultOutput, ToolResultPart, ToolSet, convertAsyncIteratorToReadableStream } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { EmbeddingModelV4, Experimental_DecisionModelV4, Experimental_ExtractionModelV4, Experimental_SpeechTranslationModelV4, Experimental_VideoModelV4, ImageModelV4, LanguageModelV4, LanguageModelV4Content, LanguageModelV4FunctionTool, LanguageModelV4Prompt, LanguageModelV4ProviderTool, LanguageModelV4ToolCall, LanguageModelV4ToolChoice, LanguageModelV4ToolResultOutput, RerankingModelV4, SharedV4Warning, SpeechModelV4, TranscriptionModelV4 } from "@ai-sdk/provider";
|
|
4
4
|
//#region src/prompt/convert-to-language-model-prompt.d.ts
|
|
5
|
-
export declare function convertToLanguageModelPrompt({ prompt, supportedUrls, download, abortSignal, provider }: {
|
|
5
|
+
export declare function convertToLanguageModelPrompt({ prompt, supportedUrls, download, abortSignal, provider, warnings }: {
|
|
6
6
|
prompt: StandardizedPrompt;
|
|
7
7
|
supportedUrls: Record<string, RegExp[]>;
|
|
8
8
|
download: DownloadFunction | undefined;
|
|
9
9
|
abortSignal?: AbortSignal;
|
|
10
10
|
provider?: string;
|
|
11
|
+
warnings?: Warning[];
|
|
11
12
|
}): Promise<LanguageModelV4Prompt>;
|
|
12
13
|
/**
|
|
13
14
|
* Downloads files from URLs in the user messages.
|
|
@@ -70,7 +71,7 @@ export declare function prepareRetries({ maxRetries, abortSignal, additionalRetr
|
|
|
70
71
|
};
|
|
71
72
|
//#endregion
|
|
72
73
|
//#region src/model/resolve-model.d.ts
|
|
73
|
-
export declare function resolveLanguageModel(model: LanguageModel): LanguageModelV4;
|
|
74
|
+
export declare function resolveLanguageModel(model: LanguageModel, onWarning?: LogWarningsFunction): LanguageModelV4;
|
|
74
75
|
//#endregion
|
|
75
76
|
//#region src/util/merge-abort-signals.d.ts
|
|
76
77
|
/**
|
|
@@ -248,10 +249,11 @@ export declare function createToolSearchState({ tools, toolCallers }: {
|
|
|
248
249
|
/**
|
|
249
250
|
* Logs the warning for the default stopWhen condition.
|
|
250
251
|
*/
|
|
251
|
-
export declare function logDefaultStopConditionWarning({ stepCount, provider, modelId }: {
|
|
252
|
+
export declare function logDefaultStopConditionWarning({ stepCount, provider, modelId, onWarning }: {
|
|
252
253
|
stepCount: number;
|
|
253
254
|
provider: string;
|
|
254
255
|
modelId: string;
|
|
256
|
+
onWarning?: LogWarningsFunction;
|
|
255
257
|
}): void;
|
|
256
258
|
//#endregion
|
|
257
259
|
//#region src/generate-text/collect-tool-approvals.d.ts
|
|
@@ -361,12 +363,14 @@ export declare function toResponseMessages<TOOLS extends ToolSet>({ content: inp
|
|
|
361
363
|
export declare class DefaultGenerateTextResult<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context, OUTPUT extends Output> implements GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT> {
|
|
362
364
|
readonly steps: GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>['steps'];
|
|
363
365
|
readonly totalUsage: LanguageModelUsage;
|
|
366
|
+
readonly stoppedBy: StoppedBy | undefined;
|
|
364
367
|
private readonly _output;
|
|
365
368
|
constructor(options: {
|
|
366
369
|
initialResponseMessages: Array<ResponseMessage>;
|
|
367
370
|
steps: GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>['steps'];
|
|
368
371
|
output: InferCompleteOutput<OUTPUT> | undefined;
|
|
369
372
|
totalUsage: LanguageModelUsage;
|
|
373
|
+
stoppedBy?: StoppedBy;
|
|
370
374
|
});
|
|
371
375
|
private readonly initialResponseMessages;
|
|
372
376
|
get finalStep(): StepResult<TOOLS, RUNTIME_CONTEXT>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["SandboxSession","SandboxSession","AssistantModelMessage","ToolModelMessage","_$__step_result0.StepResult","_$__content_part0.ContentPart","_$__generated_file0.GeneratedFile","_$__reasoning_output0.ReasoningOutput","_$__reasoning_output0.ReasoningFileOutput","_$__tool_call0.TypedToolCall","_$__tool_call0.StaticToolCall","_$__tool_call0.DynamicToolCall","_$__tool_result0.TypedToolResult","_$__tool_result0.StaticToolResult","_$__tool_result0.DynamicToolResult","_$__0.FinishReason","_$__0.LanguageModelResponseMetadata","_$__0.LanguageModelRequestMetadata"],"sources":["../../src/prompt/convert-to-language-model-prompt.ts","../../src/prompt/create-tool-model-output.ts","../../src/prompt/prepare-tool-choice.ts","../../src/prompt/prepare-tools.ts","../../src/prompt/prepare-language-model-call-options.ts","../../src/util/prepare-retries.ts","../../src/model/resolve-model.ts","../../src/util/merge-abort-signals.ts","../../src/util/set-abort-timeout.ts","../../src/util/merge-callbacks.ts","../../src/util/merge-objects.ts","../../src/telemetry/create-telemetry-dispatcher.ts","../../src/telemetry/filter-included-context.ts","../../src/generate-text/restricted-telemetry-dispatcher.ts","../../src/generate-text/parse-tool-call.ts","../../src/generate-text/stream-retry-attempt-boundary.ts","../../src/generate-text/execute-tools-from-stream.ts","../../src/generate-text/is-output-chunk.ts","../../src/generate-text/validate-tool-context.ts","../../src/tool-search/prepare-tool-search.ts","../../src/agent/default-stop-condition.ts","../../src/generate-text/collect-tool-approvals.ts","../../src/generate-text/tool-approval-signature.ts","../../src/generate-text/validate-tool-approvals.ts","../../src/generate-text/resolve-tool-approval.ts","../../src/generate-text/to-response-messages.ts","../../src/generate-text/default-generate-text-result.ts","../../src/generate-text/resolve-generated-file-data.ts","../../src/generate-text/convert-language-model-content.ts","../../src/generate-text/calculate-tokens-per-second.ts","../../src/generate-text/tool-call-concurrency.ts"],"mappings":";;;;wBAmCsB,+BACpB,QACA,eACA,UACA,aAGA;EAEA,QAAQ;EACR,eAAe,eAAe;EAC9B,UAAU;EACV,cAAc;EACd;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["SandboxSession","SandboxSession","AssistantModelMessage","ToolModelMessage","_$__step_result0.StepResult","_$__content_part0.ContentPart","_$__generated_file0.GeneratedFile","_$__reasoning_output0.ReasoningOutput","_$__reasoning_output0.ReasoningFileOutput","_$__tool_call0.TypedToolCall","_$__tool_call0.StaticToolCall","_$__tool_call0.DynamicToolCall","_$__tool_result0.TypedToolResult","_$__tool_result0.StaticToolResult","_$__tool_result0.DynamicToolResult","_$__0.FinishReason","_$__0.LanguageModelResponseMetadata","_$__0.LanguageModelRequestMetadata"],"sources":["../../src/prompt/convert-to-language-model-prompt.ts","../../src/prompt/create-tool-model-output.ts","../../src/prompt/prepare-tool-choice.ts","../../src/prompt/prepare-tools.ts","../../src/prompt/prepare-language-model-call-options.ts","../../src/util/prepare-retries.ts","../../src/model/resolve-model.ts","../../src/util/merge-abort-signals.ts","../../src/util/set-abort-timeout.ts","../../src/util/merge-callbacks.ts","../../src/util/merge-objects.ts","../../src/telemetry/create-telemetry-dispatcher.ts","../../src/telemetry/filter-included-context.ts","../../src/generate-text/restricted-telemetry-dispatcher.ts","../../src/generate-text/parse-tool-call.ts","../../src/generate-text/stream-retry-attempt-boundary.ts","../../src/generate-text/execute-tools-from-stream.ts","../../src/generate-text/is-output-chunk.ts","../../src/generate-text/validate-tool-context.ts","../../src/tool-search/prepare-tool-search.ts","../../src/agent/default-stop-condition.ts","../../src/generate-text/collect-tool-approvals.ts","../../src/generate-text/tool-approval-signature.ts","../../src/generate-text/validate-tool-approvals.ts","../../src/generate-text/resolve-tool-approval.ts","../../src/generate-text/to-response-messages.ts","../../src/generate-text/default-generate-text-result.ts","../../src/generate-text/resolve-generated-file-data.ts","../../src/generate-text/convert-language-model-content.ts","../../src/generate-text/calculate-tokens-per-second.ts","../../src/generate-text/tool-call-concurrency.ts"],"mappings":"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"}
|
package/dist/internal/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as convertToLanguageModelPrompt, B as setAbortTimeout, C as resolveToolApproval,
|
|
1
|
+
import { $ as convertToLanguageModelPrompt, B as setAbortTimeout, C as resolveToolApproval, Dt as logWarnings, E as DefaultGenerateTextResult, G as addLanguageModelUsage, H as mergeAbortSignals, J as standardizePrompt, K as asLanguageModelUsage, O as validateToolContext, P as convertLanguageModelContent, Q as createToolModelOutput, R as collectToolApprovals, S as filterIncludedContext, V as prepareRetries, X as prepareToolChoice, Y as prepareTools, Z as prepareLanguageModelCallOptions, _ as createTelemetryDispatcher, a as createAsyncIterableStream, c as validateApprovedToolApprovals, d as verifyToolApprovalSignature, et as downloadAssets, g as DefaultStepResult, h as createRestrictedTelemetryDispatcher, ht as resolveLanguageModel, k as createToolSearchState, n as logDefaultStopConditionWarning, o as mapWithConcurrency, ot as mergeObjects, p as toResponseMessages, q as createNullLanguageModelUsage, r as isOutputChunk, s as prepareToolCallConcurrency, st as createDefaultDownloadFunction, tt as mapToolResultOutput, u as signToolApproval, w as parseToolCall, x as mergeCallbacks, z as calculateTokensPerSecond } from "../default-stop-condition-D8PwkeWe.js";
|
|
2
2
|
import { convertAsyncIteratorToReadableStream } from "@ai-sdk/provider-utils";
|
|
3
3
|
export { DefaultGenerateTextResult, DefaultStepResult, addLanguageModelUsage, asLanguageModelUsage, calculateTokensPerSecond, collectToolApprovals, convertAsyncIteratorToReadableStream, convertLanguageModelContent, convertToLanguageModelPrompt, createAsyncIterableStream, createDefaultDownloadFunction, createNullLanguageModelUsage, createRestrictedTelemetryDispatcher, createTelemetryDispatcher, createToolModelOutput, createToolSearchState, downloadAssets, filterIncludedContext, isOutputChunk, logDefaultStopConditionWarning, logWarnings, mapToolResultOutput, mapWithConcurrency, mergeAbortSignals, mergeCallbacks, mergeObjects, parseToolCall, prepareLanguageModelCallOptions as prepareCallSettings, prepareLanguageModelCallOptions, prepareRetries, prepareToolCallConcurrency, prepareToolChoice, prepareTools, resolveLanguageModel, resolveToolApproval, setAbortTimeout, signToolApproval, standardizePrompt, toResponseMessages, validateApprovedToolApprovals, validateToolContext, verifyToolApprovalSignature };
|
|
@@ -16,6 +16,38 @@ A [steering message](#steering) that is waiting when the model finishes its answ
|
|
|
16
16
|
|
|
17
17
|
The AI SDK provides built-in loop control through two parameters: `stopWhen` for defining stopping conditions and `prepareStep` for modifying settings (model, tools, messages, and more) between steps.
|
|
18
18
|
|
|
19
|
+
## Why the Loop Stopped
|
|
20
|
+
|
|
21
|
+
`stoppedBy` tells you which of these ended the loop. It is on the `generateText` and `streamText` results, the `onEnd` callback, and the final `finish` stream part:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { ToolLoopAgent, isStepCount } from 'ai';
|
|
25
|
+
__PROVIDER_IMPORT__;
|
|
26
|
+
|
|
27
|
+
const agent = new ToolLoopAgent({
|
|
28
|
+
model: __MODEL__,
|
|
29
|
+
tools: {
|
|
30
|
+
// your tools here
|
|
31
|
+
},
|
|
32
|
+
stopWhen: isStepCount(5),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const result = await agent.generate({
|
|
36
|
+
prompt: 'Analyze this dataset and create a summary report',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (result.stoppedBy === 'stop-condition') {
|
|
40
|
+
// the step limit ended the loop before the model finished
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- `model`: the model finished without tool calls that continue the loop. `finishReason` tells how its last call finished, e.g. `stop` or `length`.
|
|
45
|
+
- `stop-condition`: a stop condition was met, e.g. `isStepCount(5)`.
|
|
46
|
+
- `tool-without-execute`: a tool call needs a result from a tool without an `execute` function.
|
|
47
|
+
- `approval`: a tool call needs an [approval](/docs/agents/tool-approvals).
|
|
48
|
+
|
|
49
|
+
`finishReason` only describes the last model call, so a loop that hits `isStepCount(5)` still reports `tool-calls`. `stoppedBy` tells these cases apart. `WorkflowAgent` and `HarnessAgent` do not report it yet.
|
|
50
|
+
|
|
19
51
|
## Stop Conditions
|
|
20
52
|
|
|
21
53
|
The `stopWhen` parameter controls when to stop execution when there are tool results in the last step. By default, `ToolLoopAgent` stops after 20 steps using `isStepCount(20)`. This default is a safety measure to prevent runaway loops that could result in excessive API calls and costs.
|
|
@@ -547,7 +579,7 @@ if (outcome.type === 'delivered') {
|
|
|
547
579
|
}
|
|
548
580
|
```
|
|
549
581
|
|
|
550
|
-
A message is delivered when it is part of the messages that are sent to the model, after `prepareStep`. It is not delivered when the loop ends before the next step boundary, or when `prepareStep` removes it. The `reason` is one of:
|
|
582
|
+
A message is delivered when it is part of the messages that are sent to the model, after `prepareStep`. It is not delivered when the loop ends before the next step boundary, or when `prepareStep` removes it. `prepareStep` can copy the message, turn its text into a text part, or add provider options to its parts and it still counts as delivered. A message whose text `prepareStep` changes counts as removed, so add details like timestamps before you send the message. The `reason` is one of:
|
|
551
583
|
|
|
552
584
|
- `finished`: the loop ended before the message could be added.
|
|
553
585
|
- `removed-by-prepare-step`: `prepareStep` returned messages without it.
|
|
@@ -556,6 +588,8 @@ A message is delivered when it is part of the messages that are sent to the mode
|
|
|
556
588
|
- `aborted`: the loop was aborted.
|
|
557
589
|
- `error`: the loop failed.
|
|
558
590
|
|
|
591
|
+
A message sent after the loop ended is not delivered and has the reason the loop ended with, e.g. `aborted` after an abort.
|
|
592
|
+
|
|
559
593
|
Pass an `id` to make retries safe. Sending a message again with the same `id` returns the outcome of the first message.
|
|
560
594
|
|
|
561
595
|
### Saving Steering Messages
|
|
@@ -157,6 +157,16 @@ const agent = new ToolLoopAgent({
|
|
|
157
157
|
await runAgentTUI({ title: 'Weather Agent', agent });
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
+
Tool calls are decided one at a time, in the order the agent requested them.
|
|
161
|
+
While the terminal UI waits for a decision, the tool call that the decision
|
|
162
|
+
applies to is marked with `approve? y/n` and shown with its input, regardless of
|
|
163
|
+
the `tools` display mode. When the input does not fit on the screen, you can
|
|
164
|
+
only approve after you have scrolled to the end of the input.
|
|
165
|
+
|
|
166
|
+
Tool sections show tool input and output as they are, without markdown
|
|
167
|
+
formatting. Invisible Unicode format characters, such as bidirectional controls
|
|
168
|
+
and zero-width characters, are shown as escapes like `\u{202e}`.
|
|
169
|
+
|
|
160
170
|
## Compatibility
|
|
161
171
|
|
|
162
172
|
When using the `agent` option, the agent must be runnable directly from terminal
|
|
@@ -961,6 +961,12 @@ Called once when the full generation completes.
|
|
|
961
961
|
type: 'FinishReason',
|
|
962
962
|
description: 'Unified reason why the final step finished.',
|
|
963
963
|
},
|
|
964
|
+
{
|
|
965
|
+
name: 'stoppedBy',
|
|
966
|
+
type: "'model' | 'stop-condition' | 'tool-without-execute' | 'approval' | undefined",
|
|
967
|
+
description:
|
|
968
|
+
'Why the loop stopped. Unlike `finishReason`, it describes the whole loop, not the last model call. See [Loop Control](/docs/agents/loop-control#why-the-loop-stopped).',
|
|
969
|
+
},
|
|
964
970
|
{
|
|
965
971
|
name: 'usage',
|
|
966
972
|
type: 'LanguageModelUsage',
|
|
@@ -86,6 +86,27 @@ fields. If AI SDK 5 is also installed, include its
|
|
|
86
86
|
handle its warning array before accessing the options object used by AI SDK 6
|
|
87
87
|
and 7.
|
|
88
88
|
|
|
89
|
+
#### Per-Call Warning Handler
|
|
90
|
+
|
|
91
|
+
You can pass `onWarning` to `generateText`, `streamText`, or `ToolLoopAgent` to
|
|
92
|
+
handle the warnings of a single call, e.g. to show them in a terminal UI instead
|
|
93
|
+
of writing them to stderr. When `onWarning` is set, the warnings of that call are
|
|
94
|
+
not sent to the global warning logger.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const result = streamText({
|
|
98
|
+
model: __MODEL__,
|
|
99
|
+
prompt: 'Hello, world!',
|
|
100
|
+
onWarning: ({ warnings, provider, model }) => {
|
|
101
|
+
// Show the warnings in your UI
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`onWarning` receives the warnings of each step, including prompt deprecations
|
|
107
|
+
such as the legacy `image` content part. These are the same warnings as in
|
|
108
|
+
`step.warnings`, `result.warnings`, and the `start-step` stream part.
|
|
109
|
+
|
|
89
110
|
### Deprecation Warnings
|
|
90
111
|
|
|
91
112
|
The default logger emits each deprecation code once per loaded SDK instance.
|
|
@@ -2022,6 +2022,13 @@ To see `generateText` in action, check out [these examples](#examples).
|
|
|
2022
2022
|
},
|
|
2023
2023
|
],
|
|
2024
2024
|
},
|
|
2025
|
+
{
|
|
2026
|
+
name: 'onWarning',
|
|
2027
|
+
type: '(options: { warnings: Warning[]; provider?: string; model?: string }) => void',
|
|
2028
|
+
isOptional: true,
|
|
2029
|
+
description:
|
|
2030
|
+
'Callback that receives the warnings of the call, e.g. unsupported settings or deprecated prompt parts. When it is set, the warnings are not sent to the global warning logger (`AI_SDK_LOG_WARNINGS`).',
|
|
2031
|
+
},
|
|
2025
2032
|
{
|
|
2026
2033
|
name: 'onStepFinish',
|
|
2027
2034
|
type: 'GenerateTextOnStepFinishCallback<TOOLS>',
|
|
@@ -2061,6 +2068,12 @@ To see `generateText` in action, check out [these examples](#examples).
|
|
|
2061
2068
|
description:
|
|
2062
2069
|
'The raw reason why the generation finished (from the provider).',
|
|
2063
2070
|
},
|
|
2071
|
+
{
|
|
2072
|
+
name: 'stoppedBy',
|
|
2073
|
+
type: "'model' | 'stop-condition' | 'tool-without-execute' | 'approval' | undefined",
|
|
2074
|
+
description:
|
|
2075
|
+
'Why the generation stopped its tool loop. Unlike `finishReason`, which describes the last model call, it tells whether the model, a stop condition, a tool without an `execute` function, or a tool approval ended the loop. See [Loop Control](/docs/agents/loop-control#why-the-loop-stopped).',
|
|
2076
|
+
},
|
|
2064
2077
|
{
|
|
2065
2078
|
name: 'usage',
|
|
2066
2079
|
type: 'LanguageModelUsage',
|
|
@@ -2673,6 +2686,12 @@ To see `generateText` in action, check out [these examples](#examples).
|
|
|
2673
2686
|
description:
|
|
2674
2687
|
'The raw reason why the generation finished (from the provider).',
|
|
2675
2688
|
},
|
|
2689
|
+
{
|
|
2690
|
+
name: 'stoppedBy',
|
|
2691
|
+
type: "'model' | 'stop-condition' | 'tool-without-execute' | 'approval' | undefined",
|
|
2692
|
+
description:
|
|
2693
|
+
'Why the generation stopped its tool loop. Unlike `finishReason`, which describes the last model call, it tells whether the model, a stop condition, a tool without an `execute` function, or a tool approval ended the loop. See [Loop Control](/docs/agents/loop-control#why-the-loop-stopped). Always set by `generateText` and `ToolLoopAgent`.',
|
|
2694
|
+
},
|
|
2676
2695
|
{
|
|
2677
2696
|
name: 'usage',
|
|
2678
2697
|
type: 'LanguageModelUsage',
|
|
@@ -1766,6 +1766,13 @@ retain the content their contracts require.
|
|
|
1766
1766
|
},
|
|
1767
1767
|
],
|
|
1768
1768
|
},
|
|
1769
|
+
{
|
|
1770
|
+
name: 'onWarning',
|
|
1771
|
+
type: '(options: { warnings: Warning[]; provider?: string; model?: string }) => void',
|
|
1772
|
+
isOptional: true,
|
|
1773
|
+
description:
|
|
1774
|
+
'Callback that receives the warnings of the call, e.g. unsupported settings or deprecated prompt parts. When it is set, the warnings are not sent to the global warning logger (`AI_SDK_LOG_WARNINGS`).',
|
|
1775
|
+
},
|
|
1769
1776
|
{
|
|
1770
1777
|
name: 'onStepFinish',
|
|
1771
1778
|
type: 'GenerateTextOnStepFinishCallback<TOOLS>',
|
|
@@ -1795,6 +1802,12 @@ retain the content their contracts require.
|
|
|
1795
1802
|
description:
|
|
1796
1803
|
'The raw reason why the generation finished (from the provider).',
|
|
1797
1804
|
},
|
|
1805
|
+
{
|
|
1806
|
+
name: 'stoppedBy',
|
|
1807
|
+
type: "'model' | 'stop-condition' | 'tool-without-execute' | 'approval' | undefined",
|
|
1808
|
+
description:
|
|
1809
|
+
'Why the generation stopped its tool loop. Unlike `finishReason`, which describes the last model call, it tells whether the model, a stop condition, a tool without an `execute` function, or a tool approval ended the loop. See [Loop Control](/docs/agents/loop-control#why-the-loop-stopped).',
|
|
1810
|
+
},
|
|
1798
1811
|
{
|
|
1799
1812
|
name: 'output',
|
|
1800
1813
|
type: 'COMPLETE_OUTPUT | undefined',
|
|
@@ -2723,6 +2736,12 @@ retain the content their contracts require.
|
|
|
2723
2736
|
description:
|
|
2724
2737
|
'The raw reason why the generation finished (from the provider).',
|
|
2725
2738
|
},
|
|
2739
|
+
{
|
|
2740
|
+
name: 'stoppedBy',
|
|
2741
|
+
type: "PromiseLike<'model' | 'stop-condition' | 'tool-without-execute' | 'approval' | undefined>",
|
|
2742
|
+
description:
|
|
2743
|
+
'Why the generation stopped its tool loop. Unlike `finishReason`, which describes the last model call, it tells whether the model, a stop condition, a tool without an `execute` function, or a tool approval ended the loop. See [Loop Control](/docs/agents/loop-control#why-the-loop-stopped). Like `finishReason`, it rejects when the stream is aborted. Automatically consumes the stream.',
|
|
2744
|
+
},
|
|
2726
2745
|
{
|
|
2727
2746
|
name: 'usage',
|
|
2728
2747
|
type: 'Promise<LanguageModelUsage>',
|
|
@@ -4023,6 +4042,12 @@ retain the content their contracts require.
|
|
|
4023
4042
|
description:
|
|
4024
4043
|
'The raw reason why the generation finished (from the provider).',
|
|
4025
4044
|
},
|
|
4045
|
+
{
|
|
4046
|
+
name: 'stoppedBy',
|
|
4047
|
+
type: "'model' | 'stop-condition' | 'tool-without-execute' | 'approval' | undefined",
|
|
4048
|
+
description:
|
|
4049
|
+
'Why the generation stopped its tool loop. See [Loop Control](/docs/agents/loop-control#why-the-loop-stopped).',
|
|
4050
|
+
},
|
|
4026
4051
|
{
|
|
4027
4052
|
name: 'totalUsage',
|
|
4028
4053
|
type: 'LanguageModelUsage',
|
|
@@ -526,6 +526,13 @@ To see `ToolLoopAgent` in action, check out [these examples](#examples).
|
|
|
526
526
|
description:
|
|
527
527
|
"Callback invoked when an agent step that started fails before it produces a step result, i.e. when the provider call throws or rejects, or when the model stream ends without output. `onStepEnd` is not called for such a step. A provider `error` chunk does not fail the step: it still ends with `onStepEnd` and `finishReason: 'error'`. The event contains all properties of the `onStepStart` event of the step that failed, plus `error`. In `generate()`, aborts and timeouts also end the step here. In `stream()`, they end the step with `onAbort` instead. Only available in the constructor.",
|
|
528
528
|
},
|
|
529
|
+
{
|
|
530
|
+
name: 'onWarning',
|
|
531
|
+
type: '(options: { warnings: Warning[]; provider?: string; model?: string }) => void',
|
|
532
|
+
isOptional: true,
|
|
533
|
+
description:
|
|
534
|
+
'Callback that receives the warnings of the agent calls, e.g. unsupported settings, deprecated prompt parts, or reaching the default step limit. When it is set, the warnings are not sent to the global warning logger (`AI_SDK_LOG_WARNINGS`). Only available in the constructor.',
|
|
535
|
+
},
|
|
529
536
|
{
|
|
530
537
|
name: 'onError',
|
|
531
538
|
type: '(event: { error: unknown }) => Promise<void> | void',
|
|
@@ -151,6 +151,9 @@ type TerminalPartDisplayMode =
|
|
|
151
151
|
section appears, then collapse it.
|
|
152
152
|
- `"hidden"`: Omit the section entirely.
|
|
153
153
|
|
|
154
|
+
A tool call that is waiting for an approval decision is always shown with its
|
|
155
|
+
input until the decision is made, regardless of the display mode.
|
|
156
|
+
|
|
154
157
|
### `ResponseStatisticsMode`
|
|
155
158
|
|
|
156
159
|
Controls which response statistic is shown:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.181",
|
|
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",
|
|
@@ -43,20 +43,20 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@ai-sdk/gateway": "4.0.
|
|
46
|
+
"@ai-sdk/gateway": "4.0.154",
|
|
47
47
|
"@ai-sdk/provider": "4.0.39",
|
|
48
48
|
"@ai-sdk/provider-utils": "5.0.83"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@ai-sdk/amazon-bedrock": "5.0.146",
|
|
52
52
|
"@ai-sdk/deepseek": "3.0.89",
|
|
53
|
-
"@ai-sdk/google": "4.0.
|
|
53
|
+
"@ai-sdk/google": "4.0.125",
|
|
54
54
|
"@ai-sdk/groq": "4.0.86",
|
|
55
55
|
"@ai-sdk/huggingface": "2.0.95",
|
|
56
56
|
"@ai-sdk/moonshotai": "3.0.95",
|
|
57
57
|
"@ai-sdk/openai": "4.0.122",
|
|
58
58
|
"@ai-sdk/test-server": "2.0.4",
|
|
59
|
-
"@ai-sdk/xai": "5.0.
|
|
59
|
+
"@ai-sdk/xai": "5.0.49",
|
|
60
60
|
"@edge-runtime/vm": "^5.0.0",
|
|
61
61
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
62
62
|
"@smithy/util-utf8": "^4.3.3",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createLogWarnings } from '../logger/create-log-warnings';
|
|
2
|
+
import type { LogWarningsFunction } from '../logger/log-warnings';
|
|
2
3
|
import type { StopCondition } from '../generate-text/stop-condition';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -8,12 +9,14 @@ export function logDefaultStopConditionWarning({
|
|
|
8
9
|
stepCount,
|
|
9
10
|
provider,
|
|
10
11
|
modelId,
|
|
12
|
+
onWarning,
|
|
11
13
|
}: {
|
|
12
14
|
stepCount: number;
|
|
13
15
|
provider: string;
|
|
14
16
|
modelId: string;
|
|
17
|
+
onWarning?: LogWarningsFunction;
|
|
15
18
|
}): void {
|
|
16
|
-
|
|
19
|
+
createLogWarnings(onWarning)({
|
|
17
20
|
provider,
|
|
18
21
|
model: modelId,
|
|
19
22
|
warnings: [
|
|
@@ -34,6 +37,7 @@ export function logDefaultStopConditionWarning({
|
|
|
34
37
|
*/
|
|
35
38
|
export function createDefaultStopCondition(
|
|
36
39
|
stepCount: number,
|
|
40
|
+
onWarning?: LogWarningsFunction,
|
|
37
41
|
): StopCondition<any, any> {
|
|
38
42
|
return ({ steps }) => {
|
|
39
43
|
if (steps.length !== stepCount) {
|
|
@@ -41,7 +45,12 @@ export function createDefaultStopCondition(
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
const { provider, modelId } = steps[steps.length - 1].model;
|
|
44
|
-
logDefaultStopConditionWarning({
|
|
48
|
+
logDefaultStopConditionWarning({
|
|
49
|
+
stepCount,
|
|
50
|
+
provider,
|
|
51
|
+
modelId,
|
|
52
|
+
onWarning,
|
|
53
|
+
});
|
|
45
54
|
|
|
46
55
|
return true;
|
|
47
56
|
};
|
|
@@ -40,6 +40,7 @@ import type {
|
|
|
40
40
|
import type { ToolInputRefinement } from '../generate-text/tool-input-refinement';
|
|
41
41
|
import type { ToolOrder } from '../generate-text/tool-order';
|
|
42
42
|
import type { ToolsContextParameter } from '../generate-text/tools-context-parameter';
|
|
43
|
+
import type { LogWarningsFunction } from '../logger/log-warnings';
|
|
43
44
|
import type { LanguageModelCallOptions } from '../prompt/language-model-call-options';
|
|
44
45
|
import type { Instructions, Prompt } from '../prompt/prompt';
|
|
45
46
|
import type { RequestOptions } from '../prompt/request-options';
|
|
@@ -273,6 +274,16 @@ export type ToolLoopAgentSettings<
|
|
|
273
274
|
NoInfer<OUTPUT>
|
|
274
275
|
>;
|
|
275
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Callback that receives the warnings of the agent calls, e.g. unsupported
|
|
279
|
+
* settings, deprecated prompt parts, or reaching the default step limit.
|
|
280
|
+
* When it is set, the warnings are not sent to the global warning logger
|
|
281
|
+
* (`AI_SDK_LOG_WARNINGS`).
|
|
282
|
+
*
|
|
283
|
+
* Like `onStepError`, it can only be set here and not per call.
|
|
284
|
+
*/
|
|
285
|
+
onWarning?: LogWarningsFunction;
|
|
286
|
+
|
|
276
287
|
/**
|
|
277
288
|
* Callback that is called when an error occurs. For `stream()` it receives
|
|
278
289
|
* the errors of the stream, for `generate()` it receives the error before
|
|
@@ -147,7 +147,9 @@ export class ToolLoopAgent<
|
|
|
147
147
|
|
|
148
148
|
const baseCallArgs = {
|
|
149
149
|
...settingsWithoutCallbacks,
|
|
150
|
-
stopWhen:
|
|
150
|
+
stopWhen:
|
|
151
|
+
this.settings.stopWhen ??
|
|
152
|
+
createDefaultStopCondition(20, this.settings.onWarning),
|
|
151
153
|
...options,
|
|
152
154
|
};
|
|
153
155
|
|
|
@@ -22,11 +22,15 @@ export function toTelemetryEvent<
|
|
|
22
22
|
|
|
23
23
|
function redactFileLocations<STATE>(state: STATE): STATE {
|
|
24
24
|
if (!Array.isArray(state)) return state;
|
|
25
|
-
return state.map(part =>
|
|
26
|
-
part?.type
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
return state.map(part => {
|
|
26
|
+
if (part?.type !== 'text' && part?.type !== 'file') return part;
|
|
27
|
+
const copy = { ...part };
|
|
28
|
+
delete copy.providerOptions;
|
|
29
|
+
if (copy.type === 'file' && isFileLocation(copy.data)) {
|
|
30
|
+
copy.data = '[redacted]';
|
|
31
|
+
}
|
|
32
|
+
return copy;
|
|
33
|
+
}) as STATE;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
function isFileLocation(data: unknown): boolean {
|
|
@@ -6,6 +6,7 @@ import type { Output } from './output';
|
|
|
6
6
|
import type { InferCompleteOutput } from './output-utils';
|
|
7
7
|
import { convertToReasoningOutputs } from './reasoning-output';
|
|
8
8
|
import type { ResponseMessage } from './response-message';
|
|
9
|
+
import type { StoppedBy } from './stopped-by';
|
|
9
10
|
|
|
10
11
|
export class DefaultGenerateTextResult<
|
|
11
12
|
TOOLS extends ToolSet,
|
|
@@ -14,6 +15,7 @@ export class DefaultGenerateTextResult<
|
|
|
14
15
|
> implements GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT> {
|
|
15
16
|
readonly steps: GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>['steps'];
|
|
16
17
|
readonly totalUsage: LanguageModelUsage;
|
|
18
|
+
readonly stoppedBy: StoppedBy | undefined;
|
|
17
19
|
private readonly _output: InferCompleteOutput<OUTPUT> | undefined;
|
|
18
20
|
|
|
19
21
|
constructor(options: {
|
|
@@ -21,11 +23,13 @@ export class DefaultGenerateTextResult<
|
|
|
21
23
|
steps: GenerateTextResult<TOOLS, RUNTIME_CONTEXT, OUTPUT>['steps'];
|
|
22
24
|
output: InferCompleteOutput<OUTPUT> | undefined;
|
|
23
25
|
totalUsage: LanguageModelUsage;
|
|
26
|
+
stoppedBy?: StoppedBy;
|
|
24
27
|
}) {
|
|
25
28
|
this.initialResponseMessages = options.initialResponseMessages;
|
|
26
29
|
this.steps = options.steps;
|
|
27
30
|
this._output = options.output;
|
|
28
31
|
this.totalUsage = options.totalUsage;
|
|
32
|
+
this.stoppedBy = options.stoppedBy;
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
private readonly initialResponseMessages: Array<ResponseMessage>;
|
|
@@ -15,6 +15,7 @@ import type { Output } from './output';
|
|
|
15
15
|
import type { ResponseMessage } from './response-message';
|
|
16
16
|
import type { StepResult } from './step-result';
|
|
17
17
|
import type { ToolOrder } from './tool-order';
|
|
18
|
+
import type { StoppedBy } from './stopped-by';
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Event passed to the `onStart` callback.
|
|
@@ -246,6 +247,12 @@ export type GenerateTextEndEvent<
|
|
|
246
247
|
RUNTIME_CONTEXT
|
|
247
248
|
>['rawFinishReason'];
|
|
248
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Why the generation stopped its tool loop, e.g. because of a stop
|
|
252
|
+
* condition. `generateText`, `streamText`, and `ToolLoopAgent` always set it.
|
|
253
|
+
*/
|
|
254
|
+
readonly stoppedBy?: StoppedBy;
|
|
255
|
+
|
|
249
256
|
/** Aggregated token usage across all steps. */
|
|
250
257
|
readonly usage: LanguageModelUsage;
|
|
251
258
|
|
|
@@ -24,6 +24,7 @@ import type {
|
|
|
24
24
|
StaticToolResult,
|
|
25
25
|
TypedToolResult,
|
|
26
26
|
} from './tool-result';
|
|
27
|
+
import type { StoppedBy } from './stopped-by';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* The result of a `generateText` call.
|
|
@@ -112,6 +113,14 @@ export interface GenerateTextResult<
|
|
|
112
113
|
*/
|
|
113
114
|
readonly rawFinishReason: string | undefined;
|
|
114
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Why the generation stopped its tool loop. Unlike `finishReason`, which
|
|
118
|
+
* describes the last model call, it tells whether the model, a stop
|
|
119
|
+
* condition, a tool without an `execute` function, or a tool approval ended
|
|
120
|
+
* the loop. `generateText` and `ToolLoopAgent` always set it.
|
|
121
|
+
*/
|
|
122
|
+
readonly stoppedBy?: StoppedBy;
|
|
123
|
+
|
|
115
124
|
/**
|
|
116
125
|
* The total token usage of all steps.
|
|
117
126
|
* When there are multiple steps, the usage is the sum of all step usages.
|