ai 6.0.96 → 6.0.98
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 +13 -0
- package/dist/index.d.mts +137 -126
- package/dist/index.d.ts +137 -126
- package/dist/index.js +69 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -12
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/02-foundations/05-streaming.mdx +1 -1
- package/docs/03-agents/02-building-agents.mdx +47 -5
- package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +25 -0
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +478 -3
- package/package.json +2 -2
- package/src/agent/agent.ts +33 -1
- package/src/agent/create-agent-ui-stream-response.ts +1 -1
- package/src/agent/create-agent-ui-stream.ts +1 -1
- package/src/agent/index.ts +6 -2
- package/src/agent/pipe-agent-ui-stream-to-response.ts +1 -1
- package/src/agent/tool-loop-agent-settings.ts +61 -2
- package/src/agent/tool-loop-agent.ts +80 -20
- package/src/agent/tool-loop-agent-on-finish-callback.ts +0 -31
- package/src/agent/tool-loop-agent-on-step-finish-callback.ts +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.98
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [0c9395b]
|
|
8
|
+
- @ai-sdk/gateway@3.0.54
|
|
9
|
+
|
|
10
|
+
## 6.0.97
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- ebfdad1: feat(ai): experimental callbacks in ToolLoopAgent
|
|
15
|
+
|
|
3
16
|
## 6.0.96
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -3205,128 +3205,12 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
3205
3205
|
readonly output: InferCompleteOutput<OUTPUT>;
|
|
3206
3206
|
}
|
|
3207
3207
|
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
type
|
|
3214
|
-
|
|
3215
|
-
/**
|
|
3216
|
-
* Parameters for calling an agent.
|
|
3217
|
-
*/
|
|
3218
|
-
type AgentCallParameters<CALL_OPTIONS, TOOLS extends ToolSet = {}> = ([
|
|
3219
|
-
CALL_OPTIONS
|
|
3220
|
-
] extends [never] ? {
|
|
3221
|
-
options?: never;
|
|
3222
|
-
} : {
|
|
3223
|
-
options: CALL_OPTIONS;
|
|
3224
|
-
}) & ({
|
|
3225
|
-
/**
|
|
3226
|
-
* A prompt. It can be either a text prompt or a list of messages.
|
|
3227
|
-
*
|
|
3228
|
-
* You can either use `prompt` or `messages` but not both.
|
|
3229
|
-
*/
|
|
3230
|
-
prompt: string | Array<ModelMessage>;
|
|
3231
|
-
/**
|
|
3232
|
-
* A list of messages.
|
|
3233
|
-
*
|
|
3234
|
-
* You can either use `prompt` or `messages` but not both.
|
|
3235
|
-
*/
|
|
3236
|
-
messages?: never;
|
|
3237
|
-
} | {
|
|
3238
|
-
/**
|
|
3239
|
-
* A list of messages.
|
|
3240
|
-
*
|
|
3241
|
-
* You can either use `prompt` or `messages` but not both.
|
|
3242
|
-
*/
|
|
3243
|
-
messages: Array<ModelMessage>;
|
|
3244
|
-
/**
|
|
3245
|
-
* A prompt. It can be either a text prompt or a list of messages.
|
|
3246
|
-
*
|
|
3247
|
-
* You can either use `prompt` or `messages` but not both.
|
|
3248
|
-
*/
|
|
3249
|
-
prompt?: never;
|
|
3250
|
-
}) & {
|
|
3251
|
-
/**
|
|
3252
|
-
* Abort signal.
|
|
3253
|
-
*/
|
|
3254
|
-
abortSignal?: AbortSignal;
|
|
3255
|
-
/**
|
|
3256
|
-
* Timeout in milliseconds. Can be specified as a number or as an object with `totalMs`.
|
|
3257
|
-
*/
|
|
3258
|
-
timeout?: TimeoutConfiguration;
|
|
3259
|
-
/**
|
|
3260
|
-
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
3261
|
-
*/
|
|
3262
|
-
onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
|
|
3263
|
-
};
|
|
3264
|
-
/**
|
|
3265
|
-
* Parameters for streaming an output from an agent.
|
|
3266
|
-
*/
|
|
3267
|
-
type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS, TOOLS> & {
|
|
3268
|
-
/**
|
|
3269
|
-
* Optional stream transformations.
|
|
3270
|
-
* They are applied in the order they are provided.
|
|
3271
|
-
* The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
3272
|
-
*/
|
|
3273
|
-
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3274
|
-
};
|
|
3275
|
-
/**
|
|
3276
|
-
* An Agent receives a prompt (text or messages) and generates or streams an output
|
|
3277
|
-
* that consists of steps, tool calls, data parts, etc.
|
|
3278
|
-
*
|
|
3279
|
-
* You can implement your own Agent by implementing the `Agent` interface,
|
|
3280
|
-
* or use the `ToolLoopAgent` class.
|
|
3281
|
-
*/
|
|
3282
|
-
interface Agent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never> {
|
|
3283
|
-
/**
|
|
3284
|
-
* The specification version of the agent interface. This will enable
|
|
3285
|
-
* us to evolve the agent interface and retain backwards compatibility.
|
|
3286
|
-
*/
|
|
3287
|
-
readonly version: 'agent-v1';
|
|
3288
|
-
/**
|
|
3289
|
-
* The id of the agent.
|
|
3290
|
-
*/
|
|
3291
|
-
readonly id: string | undefined;
|
|
3292
|
-
/**
|
|
3293
|
-
* The tools that the agent can use.
|
|
3294
|
-
*/
|
|
3295
|
-
readonly tools: TOOLS;
|
|
3296
|
-
/**
|
|
3297
|
-
* Generates an output from the agent (non-streaming).
|
|
3298
|
-
*/
|
|
3299
|
-
generate(options: AgentCallParameters<CALL_OPTIONS, TOOLS>): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
3300
|
-
/**
|
|
3301
|
-
* Streams an output from the agent (streaming).
|
|
3302
|
-
*/
|
|
3303
|
-
stream(options: AgentStreamParameters<CALL_OPTIONS, TOOLS>): PromiseLike<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3304
|
-
}
|
|
3305
|
-
|
|
3306
|
-
/**
|
|
3307
|
-
* Callback that is set using the `onFinish` option.
|
|
3308
|
-
*
|
|
3309
|
-
* @param event - The event that is passed to the callback.
|
|
3310
|
-
*/
|
|
3311
|
-
type ToolLoopAgentOnFinishCallback<TOOLS extends ToolSet = {}> = (event: StepResult<TOOLS> & {
|
|
3312
|
-
/**
|
|
3313
|
-
* Details for all steps.
|
|
3314
|
-
*/
|
|
3315
|
-
readonly steps: StepResult<TOOLS>[];
|
|
3316
|
-
/**
|
|
3317
|
-
* Total usage for all steps. This is the sum of the usage of all steps.
|
|
3318
|
-
*/
|
|
3319
|
-
readonly totalUsage: LanguageModelUsage;
|
|
3320
|
-
/**
|
|
3321
|
-
* Context that is passed into tool execution.
|
|
3322
|
-
*
|
|
3323
|
-
* Experimental (can break in patch releases).
|
|
3324
|
-
*
|
|
3325
|
-
* @default undefined
|
|
3326
|
-
*/
|
|
3327
|
-
experimental_context: unknown;
|
|
3328
|
-
}) => PromiseLike<void> | void;
|
|
3329
|
-
|
|
3208
|
+
type ToolLoopAgentOnStartCallback<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output> = (event: OnStartEvent<TOOLS, OUTPUT>) => PromiseLike<void> | void;
|
|
3209
|
+
type ToolLoopAgentOnStepStartCallback<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output> = (event: OnStepStartEvent<TOOLS, OUTPUT>) => PromiseLike<void> | void;
|
|
3210
|
+
type ToolLoopAgentOnToolCallStartCallback<TOOLS extends ToolSet = ToolSet> = (event: OnToolCallStartEvent<TOOLS>) => PromiseLike<void> | void;
|
|
3211
|
+
type ToolLoopAgentOnToolCallFinishCallback<TOOLS extends ToolSet = ToolSet> = (event: OnToolCallFinishEvent<TOOLS>) => PromiseLike<void> | void;
|
|
3212
|
+
type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: OnStepFinishEvent<TOOLS>) => Promise<void> | void;
|
|
3213
|
+
type ToolLoopAgentOnFinishCallback<TOOLS extends ToolSet = {}> = (event: OnFinishEvent<TOOLS>) => PromiseLike<void> | void;
|
|
3330
3214
|
/**
|
|
3331
3215
|
* Configuration options for an agent.
|
|
3332
3216
|
*/
|
|
@@ -3381,6 +3265,22 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
|
|
|
3381
3265
|
* A function that attempts to repair a tool call that failed to parse.
|
|
3382
3266
|
*/
|
|
3383
3267
|
experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
|
|
3268
|
+
/**
|
|
3269
|
+
* Callback that is called when the agent operation begins, before any LLM calls.
|
|
3270
|
+
*/
|
|
3271
|
+
experimental_onStart?: ToolLoopAgentOnStartCallback<NoInfer<TOOLS>, OUTPUT>;
|
|
3272
|
+
/**
|
|
3273
|
+
* Callback that is called when a step (LLM call) begins, before the provider is called.
|
|
3274
|
+
*/
|
|
3275
|
+
experimental_onStepStart?: ToolLoopAgentOnStepStartCallback<NoInfer<TOOLS>, OUTPUT>;
|
|
3276
|
+
/**
|
|
3277
|
+
* Callback that is called before each tool execution begins.
|
|
3278
|
+
*/
|
|
3279
|
+
experimental_onToolCallStart?: ToolLoopAgentOnToolCallStartCallback<NoInfer<TOOLS>>;
|
|
3280
|
+
/**
|
|
3281
|
+
* Callback that is called after each tool execution completes.
|
|
3282
|
+
*/
|
|
3283
|
+
experimental_onToolCallFinish?: ToolLoopAgentOnToolCallFinishCallback<NoInfer<TOOLS>>;
|
|
3384
3284
|
/**
|
|
3385
3285
|
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
3386
3286
|
*/
|
|
@@ -3421,6 +3321,117 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
|
|
|
3421
3321
|
prepareCall?: (options: Omit<AgentCallParameters<CALL_OPTIONS, NoInfer<TOOLS>>, 'onStepFinish'> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'> & Omit<Prompt, 'system'>>;
|
|
3422
3322
|
};
|
|
3423
3323
|
|
|
3324
|
+
/**
|
|
3325
|
+
* Parameters for calling an agent.
|
|
3326
|
+
*/
|
|
3327
|
+
type AgentCallParameters<CALL_OPTIONS, TOOLS extends ToolSet = {}> = ([
|
|
3328
|
+
CALL_OPTIONS
|
|
3329
|
+
] extends [never] ? {
|
|
3330
|
+
options?: never;
|
|
3331
|
+
} : {
|
|
3332
|
+
options: CALL_OPTIONS;
|
|
3333
|
+
}) & ({
|
|
3334
|
+
/**
|
|
3335
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
3336
|
+
*
|
|
3337
|
+
* You can either use `prompt` or `messages` but not both.
|
|
3338
|
+
*/
|
|
3339
|
+
prompt: string | Array<ModelMessage>;
|
|
3340
|
+
/**
|
|
3341
|
+
* A list of messages.
|
|
3342
|
+
*
|
|
3343
|
+
* You can either use `prompt` or `messages` but not both.
|
|
3344
|
+
*/
|
|
3345
|
+
messages?: never;
|
|
3346
|
+
} | {
|
|
3347
|
+
/**
|
|
3348
|
+
* A list of messages.
|
|
3349
|
+
*
|
|
3350
|
+
* You can either use `prompt` or `messages` but not both.
|
|
3351
|
+
*/
|
|
3352
|
+
messages: Array<ModelMessage>;
|
|
3353
|
+
/**
|
|
3354
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
3355
|
+
*
|
|
3356
|
+
* You can either use `prompt` or `messages` but not both.
|
|
3357
|
+
*/
|
|
3358
|
+
prompt?: never;
|
|
3359
|
+
}) & {
|
|
3360
|
+
/**
|
|
3361
|
+
* Abort signal.
|
|
3362
|
+
*/
|
|
3363
|
+
abortSignal?: AbortSignal;
|
|
3364
|
+
/**
|
|
3365
|
+
* Timeout in milliseconds. Can be specified as a number or as an object with `totalMs`.
|
|
3366
|
+
*/
|
|
3367
|
+
timeout?: TimeoutConfiguration;
|
|
3368
|
+
/**
|
|
3369
|
+
* Callback that is called when the agent operation begins, before any LLM calls.
|
|
3370
|
+
*/
|
|
3371
|
+
experimental_onStart?: ToolLoopAgentOnStartCallback<TOOLS>;
|
|
3372
|
+
/**
|
|
3373
|
+
* Callback that is called when a step (LLM call) begins, before the provider is called.
|
|
3374
|
+
*/
|
|
3375
|
+
experimental_onStepStart?: ToolLoopAgentOnStepStartCallback<TOOLS>;
|
|
3376
|
+
/**
|
|
3377
|
+
* Callback that is called before each tool execution begins.
|
|
3378
|
+
*/
|
|
3379
|
+
experimental_onToolCallStart?: ToolLoopAgentOnToolCallStartCallback<TOOLS>;
|
|
3380
|
+
/**
|
|
3381
|
+
* Callback that is called after each tool execution completes.
|
|
3382
|
+
*/
|
|
3383
|
+
experimental_onToolCallFinish?: ToolLoopAgentOnToolCallFinishCallback<TOOLS>;
|
|
3384
|
+
/**
|
|
3385
|
+
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
3386
|
+
*/
|
|
3387
|
+
onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
|
|
3388
|
+
/**
|
|
3389
|
+
* Callback that is called when all steps are finished and the response is complete.
|
|
3390
|
+
*/
|
|
3391
|
+
onFinish?: ToolLoopAgentOnFinishCallback<TOOLS>;
|
|
3392
|
+
};
|
|
3393
|
+
/**
|
|
3394
|
+
* Parameters for streaming an output from an agent.
|
|
3395
|
+
*/
|
|
3396
|
+
type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS, TOOLS> & {
|
|
3397
|
+
/**
|
|
3398
|
+
* Optional stream transformations.
|
|
3399
|
+
* They are applied in the order they are provided.
|
|
3400
|
+
* The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
3401
|
+
*/
|
|
3402
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3403
|
+
};
|
|
3404
|
+
/**
|
|
3405
|
+
* An Agent receives a prompt (text or messages) and generates or streams an output
|
|
3406
|
+
* that consists of steps, tool calls, data parts, etc.
|
|
3407
|
+
*
|
|
3408
|
+
* You can implement your own Agent by implementing the `Agent` interface,
|
|
3409
|
+
* or use the `ToolLoopAgent` class.
|
|
3410
|
+
*/
|
|
3411
|
+
interface Agent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never> {
|
|
3412
|
+
/**
|
|
3413
|
+
* The specification version of the agent interface. This will enable
|
|
3414
|
+
* us to evolve the agent interface and retain backwards compatibility.
|
|
3415
|
+
*/
|
|
3416
|
+
readonly version: 'agent-v1';
|
|
3417
|
+
/**
|
|
3418
|
+
* The id of the agent.
|
|
3419
|
+
*/
|
|
3420
|
+
readonly id: string | undefined;
|
|
3421
|
+
/**
|
|
3422
|
+
* The tools that the agent can use.
|
|
3423
|
+
*/
|
|
3424
|
+
readonly tools: TOOLS;
|
|
3425
|
+
/**
|
|
3426
|
+
* Generates an output from the agent (non-streaming).
|
|
3427
|
+
*/
|
|
3428
|
+
generate(options: AgentCallParameters<CALL_OPTIONS, TOOLS>): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
3429
|
+
/**
|
|
3430
|
+
* Streams an output from the agent (streaming).
|
|
3431
|
+
*/
|
|
3432
|
+
stream(options: AgentStreamParameters<CALL_OPTIONS, TOOLS>): PromiseLike<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3424
3435
|
/**
|
|
3425
3436
|
* A tool loop agent is an agent that runs tools in a loop. In each step,
|
|
3426
3437
|
* it calls the LLM, and if there are tool calls, it executes the tools
|
|
@@ -3445,15 +3456,15 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OU
|
|
|
3445
3456
|
*/
|
|
3446
3457
|
get tools(): TOOLS;
|
|
3447
3458
|
private prepareCall;
|
|
3448
|
-
private
|
|
3459
|
+
private mergeCallbacks;
|
|
3449
3460
|
/**
|
|
3450
3461
|
* Generates an output from the agent (non-streaming).
|
|
3451
3462
|
*/
|
|
3452
|
-
generate({ abortSignal, timeout, onStepFinish, ...options }: AgentCallParameters<CALL_OPTIONS, TOOLS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
3463
|
+
generate({ abortSignal, timeout, experimental_onStart, experimental_onStepStart, experimental_onToolCallStart, experimental_onToolCallFinish, onStepFinish, onFinish, ...options }: AgentCallParameters<CALL_OPTIONS, TOOLS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
3453
3464
|
/**
|
|
3454
3465
|
* Streams an output from the agent (streaming).
|
|
3455
3466
|
*/
|
|
3456
|
-
stream({ abortSignal, timeout, experimental_transform, onStepFinish, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3467
|
+
stream({ abortSignal, timeout, experimental_transform, experimental_onStart, experimental_onStepStart, experimental_onToolCallStart, experimental_onToolCallFinish, onStepFinish, onFinish, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3457
3468
|
}
|
|
3458
3469
|
|
|
3459
3470
|
/**
|
|
@@ -6369,4 +6380,4 @@ declare global {
|
|
|
6369
6380
|
var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
|
|
6370
6381
|
}
|
|
6371
6382
|
|
|
6372
|
-
export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
|
|
6383
|
+
export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStartCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentOnStepStartCallback, ToolLoopAgentOnToolCallFinishCallback, ToolLoopAgentOnToolCallStartCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -3205,128 +3205,12 @@ interface GenerateTextResult<TOOLS extends ToolSet, OUTPUT extends Output> {
|
|
|
3205
3205
|
readonly output: InferCompleteOutput<OUTPUT>;
|
|
3206
3206
|
}
|
|
3207
3207
|
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
type
|
|
3214
|
-
|
|
3215
|
-
/**
|
|
3216
|
-
* Parameters for calling an agent.
|
|
3217
|
-
*/
|
|
3218
|
-
type AgentCallParameters<CALL_OPTIONS, TOOLS extends ToolSet = {}> = ([
|
|
3219
|
-
CALL_OPTIONS
|
|
3220
|
-
] extends [never] ? {
|
|
3221
|
-
options?: never;
|
|
3222
|
-
} : {
|
|
3223
|
-
options: CALL_OPTIONS;
|
|
3224
|
-
}) & ({
|
|
3225
|
-
/**
|
|
3226
|
-
* A prompt. It can be either a text prompt or a list of messages.
|
|
3227
|
-
*
|
|
3228
|
-
* You can either use `prompt` or `messages` but not both.
|
|
3229
|
-
*/
|
|
3230
|
-
prompt: string | Array<ModelMessage>;
|
|
3231
|
-
/**
|
|
3232
|
-
* A list of messages.
|
|
3233
|
-
*
|
|
3234
|
-
* You can either use `prompt` or `messages` but not both.
|
|
3235
|
-
*/
|
|
3236
|
-
messages?: never;
|
|
3237
|
-
} | {
|
|
3238
|
-
/**
|
|
3239
|
-
* A list of messages.
|
|
3240
|
-
*
|
|
3241
|
-
* You can either use `prompt` or `messages` but not both.
|
|
3242
|
-
*/
|
|
3243
|
-
messages: Array<ModelMessage>;
|
|
3244
|
-
/**
|
|
3245
|
-
* A prompt. It can be either a text prompt or a list of messages.
|
|
3246
|
-
*
|
|
3247
|
-
* You can either use `prompt` or `messages` but not both.
|
|
3248
|
-
*/
|
|
3249
|
-
prompt?: never;
|
|
3250
|
-
}) & {
|
|
3251
|
-
/**
|
|
3252
|
-
* Abort signal.
|
|
3253
|
-
*/
|
|
3254
|
-
abortSignal?: AbortSignal;
|
|
3255
|
-
/**
|
|
3256
|
-
* Timeout in milliseconds. Can be specified as a number or as an object with `totalMs`.
|
|
3257
|
-
*/
|
|
3258
|
-
timeout?: TimeoutConfiguration;
|
|
3259
|
-
/**
|
|
3260
|
-
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
3261
|
-
*/
|
|
3262
|
-
onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
|
|
3263
|
-
};
|
|
3264
|
-
/**
|
|
3265
|
-
* Parameters for streaming an output from an agent.
|
|
3266
|
-
*/
|
|
3267
|
-
type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS, TOOLS> & {
|
|
3268
|
-
/**
|
|
3269
|
-
* Optional stream transformations.
|
|
3270
|
-
* They are applied in the order they are provided.
|
|
3271
|
-
* The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
3272
|
-
*/
|
|
3273
|
-
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3274
|
-
};
|
|
3275
|
-
/**
|
|
3276
|
-
* An Agent receives a prompt (text or messages) and generates or streams an output
|
|
3277
|
-
* that consists of steps, tool calls, data parts, etc.
|
|
3278
|
-
*
|
|
3279
|
-
* You can implement your own Agent by implementing the `Agent` interface,
|
|
3280
|
-
* or use the `ToolLoopAgent` class.
|
|
3281
|
-
*/
|
|
3282
|
-
interface Agent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never> {
|
|
3283
|
-
/**
|
|
3284
|
-
* The specification version of the agent interface. This will enable
|
|
3285
|
-
* us to evolve the agent interface and retain backwards compatibility.
|
|
3286
|
-
*/
|
|
3287
|
-
readonly version: 'agent-v1';
|
|
3288
|
-
/**
|
|
3289
|
-
* The id of the agent.
|
|
3290
|
-
*/
|
|
3291
|
-
readonly id: string | undefined;
|
|
3292
|
-
/**
|
|
3293
|
-
* The tools that the agent can use.
|
|
3294
|
-
*/
|
|
3295
|
-
readonly tools: TOOLS;
|
|
3296
|
-
/**
|
|
3297
|
-
* Generates an output from the agent (non-streaming).
|
|
3298
|
-
*/
|
|
3299
|
-
generate(options: AgentCallParameters<CALL_OPTIONS, TOOLS>): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
3300
|
-
/**
|
|
3301
|
-
* Streams an output from the agent (streaming).
|
|
3302
|
-
*/
|
|
3303
|
-
stream(options: AgentStreamParameters<CALL_OPTIONS, TOOLS>): PromiseLike<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3304
|
-
}
|
|
3305
|
-
|
|
3306
|
-
/**
|
|
3307
|
-
* Callback that is set using the `onFinish` option.
|
|
3308
|
-
*
|
|
3309
|
-
* @param event - The event that is passed to the callback.
|
|
3310
|
-
*/
|
|
3311
|
-
type ToolLoopAgentOnFinishCallback<TOOLS extends ToolSet = {}> = (event: StepResult<TOOLS> & {
|
|
3312
|
-
/**
|
|
3313
|
-
* Details for all steps.
|
|
3314
|
-
*/
|
|
3315
|
-
readonly steps: StepResult<TOOLS>[];
|
|
3316
|
-
/**
|
|
3317
|
-
* Total usage for all steps. This is the sum of the usage of all steps.
|
|
3318
|
-
*/
|
|
3319
|
-
readonly totalUsage: LanguageModelUsage;
|
|
3320
|
-
/**
|
|
3321
|
-
* Context that is passed into tool execution.
|
|
3322
|
-
*
|
|
3323
|
-
* Experimental (can break in patch releases).
|
|
3324
|
-
*
|
|
3325
|
-
* @default undefined
|
|
3326
|
-
*/
|
|
3327
|
-
experimental_context: unknown;
|
|
3328
|
-
}) => PromiseLike<void> | void;
|
|
3329
|
-
|
|
3208
|
+
type ToolLoopAgentOnStartCallback<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output> = (event: OnStartEvent<TOOLS, OUTPUT>) => PromiseLike<void> | void;
|
|
3209
|
+
type ToolLoopAgentOnStepStartCallback<TOOLS extends ToolSet = ToolSet, OUTPUT extends Output = Output> = (event: OnStepStartEvent<TOOLS, OUTPUT>) => PromiseLike<void> | void;
|
|
3210
|
+
type ToolLoopAgentOnToolCallStartCallback<TOOLS extends ToolSet = ToolSet> = (event: OnToolCallStartEvent<TOOLS>) => PromiseLike<void> | void;
|
|
3211
|
+
type ToolLoopAgentOnToolCallFinishCallback<TOOLS extends ToolSet = ToolSet> = (event: OnToolCallFinishEvent<TOOLS>) => PromiseLike<void> | void;
|
|
3212
|
+
type ToolLoopAgentOnStepFinishCallback<TOOLS extends ToolSet = {}> = (stepResult: OnStepFinishEvent<TOOLS>) => Promise<void> | void;
|
|
3213
|
+
type ToolLoopAgentOnFinishCallback<TOOLS extends ToolSet = {}> = (event: OnFinishEvent<TOOLS>) => PromiseLike<void> | void;
|
|
3330
3214
|
/**
|
|
3331
3215
|
* Configuration options for an agent.
|
|
3332
3216
|
*/
|
|
@@ -3381,6 +3265,22 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
|
|
|
3381
3265
|
* A function that attempts to repair a tool call that failed to parse.
|
|
3382
3266
|
*/
|
|
3383
3267
|
experimental_repairToolCall?: ToolCallRepairFunction<NoInfer<TOOLS>>;
|
|
3268
|
+
/**
|
|
3269
|
+
* Callback that is called when the agent operation begins, before any LLM calls.
|
|
3270
|
+
*/
|
|
3271
|
+
experimental_onStart?: ToolLoopAgentOnStartCallback<NoInfer<TOOLS>, OUTPUT>;
|
|
3272
|
+
/**
|
|
3273
|
+
* Callback that is called when a step (LLM call) begins, before the provider is called.
|
|
3274
|
+
*/
|
|
3275
|
+
experimental_onStepStart?: ToolLoopAgentOnStepStartCallback<NoInfer<TOOLS>, OUTPUT>;
|
|
3276
|
+
/**
|
|
3277
|
+
* Callback that is called before each tool execution begins.
|
|
3278
|
+
*/
|
|
3279
|
+
experimental_onToolCallStart?: ToolLoopAgentOnToolCallStartCallback<NoInfer<TOOLS>>;
|
|
3280
|
+
/**
|
|
3281
|
+
* Callback that is called after each tool execution completes.
|
|
3282
|
+
*/
|
|
3283
|
+
experimental_onToolCallFinish?: ToolLoopAgentOnToolCallFinishCallback<NoInfer<TOOLS>>;
|
|
3384
3284
|
/**
|
|
3385
3285
|
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
3386
3286
|
*/
|
|
@@ -3421,6 +3321,117 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
|
|
|
3421
3321
|
prepareCall?: (options: Omit<AgentCallParameters<CALL_OPTIONS, NoInfer<TOOLS>>, 'onStepFinish'> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'> & Omit<Prompt, 'system'>>;
|
|
3422
3322
|
};
|
|
3423
3323
|
|
|
3324
|
+
/**
|
|
3325
|
+
* Parameters for calling an agent.
|
|
3326
|
+
*/
|
|
3327
|
+
type AgentCallParameters<CALL_OPTIONS, TOOLS extends ToolSet = {}> = ([
|
|
3328
|
+
CALL_OPTIONS
|
|
3329
|
+
] extends [never] ? {
|
|
3330
|
+
options?: never;
|
|
3331
|
+
} : {
|
|
3332
|
+
options: CALL_OPTIONS;
|
|
3333
|
+
}) & ({
|
|
3334
|
+
/**
|
|
3335
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
3336
|
+
*
|
|
3337
|
+
* You can either use `prompt` or `messages` but not both.
|
|
3338
|
+
*/
|
|
3339
|
+
prompt: string | Array<ModelMessage>;
|
|
3340
|
+
/**
|
|
3341
|
+
* A list of messages.
|
|
3342
|
+
*
|
|
3343
|
+
* You can either use `prompt` or `messages` but not both.
|
|
3344
|
+
*/
|
|
3345
|
+
messages?: never;
|
|
3346
|
+
} | {
|
|
3347
|
+
/**
|
|
3348
|
+
* A list of messages.
|
|
3349
|
+
*
|
|
3350
|
+
* You can either use `prompt` or `messages` but not both.
|
|
3351
|
+
*/
|
|
3352
|
+
messages: Array<ModelMessage>;
|
|
3353
|
+
/**
|
|
3354
|
+
* A prompt. It can be either a text prompt or a list of messages.
|
|
3355
|
+
*
|
|
3356
|
+
* You can either use `prompt` or `messages` but not both.
|
|
3357
|
+
*/
|
|
3358
|
+
prompt?: never;
|
|
3359
|
+
}) & {
|
|
3360
|
+
/**
|
|
3361
|
+
* Abort signal.
|
|
3362
|
+
*/
|
|
3363
|
+
abortSignal?: AbortSignal;
|
|
3364
|
+
/**
|
|
3365
|
+
* Timeout in milliseconds. Can be specified as a number or as an object with `totalMs`.
|
|
3366
|
+
*/
|
|
3367
|
+
timeout?: TimeoutConfiguration;
|
|
3368
|
+
/**
|
|
3369
|
+
* Callback that is called when the agent operation begins, before any LLM calls.
|
|
3370
|
+
*/
|
|
3371
|
+
experimental_onStart?: ToolLoopAgentOnStartCallback<TOOLS>;
|
|
3372
|
+
/**
|
|
3373
|
+
* Callback that is called when a step (LLM call) begins, before the provider is called.
|
|
3374
|
+
*/
|
|
3375
|
+
experimental_onStepStart?: ToolLoopAgentOnStepStartCallback<TOOLS>;
|
|
3376
|
+
/**
|
|
3377
|
+
* Callback that is called before each tool execution begins.
|
|
3378
|
+
*/
|
|
3379
|
+
experimental_onToolCallStart?: ToolLoopAgentOnToolCallStartCallback<TOOLS>;
|
|
3380
|
+
/**
|
|
3381
|
+
* Callback that is called after each tool execution completes.
|
|
3382
|
+
*/
|
|
3383
|
+
experimental_onToolCallFinish?: ToolLoopAgentOnToolCallFinishCallback<TOOLS>;
|
|
3384
|
+
/**
|
|
3385
|
+
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
3386
|
+
*/
|
|
3387
|
+
onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
|
|
3388
|
+
/**
|
|
3389
|
+
* Callback that is called when all steps are finished and the response is complete.
|
|
3390
|
+
*/
|
|
3391
|
+
onFinish?: ToolLoopAgentOnFinishCallback<TOOLS>;
|
|
3392
|
+
};
|
|
3393
|
+
/**
|
|
3394
|
+
* Parameters for streaming an output from an agent.
|
|
3395
|
+
*/
|
|
3396
|
+
type AgentStreamParameters<CALL_OPTIONS, TOOLS extends ToolSet> = AgentCallParameters<CALL_OPTIONS, TOOLS> & {
|
|
3397
|
+
/**
|
|
3398
|
+
* Optional stream transformations.
|
|
3399
|
+
* They are applied in the order they are provided.
|
|
3400
|
+
* The stream transformations must maintain the stream structure for streamText to work correctly.
|
|
3401
|
+
*/
|
|
3402
|
+
experimental_transform?: StreamTextTransform<TOOLS> | Array<StreamTextTransform<TOOLS>>;
|
|
3403
|
+
};
|
|
3404
|
+
/**
|
|
3405
|
+
* An Agent receives a prompt (text or messages) and generates or streams an output
|
|
3406
|
+
* that consists of steps, tool calls, data parts, etc.
|
|
3407
|
+
*
|
|
3408
|
+
* You can implement your own Agent by implementing the `Agent` interface,
|
|
3409
|
+
* or use the `ToolLoopAgent` class.
|
|
3410
|
+
*/
|
|
3411
|
+
interface Agent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never> {
|
|
3412
|
+
/**
|
|
3413
|
+
* The specification version of the agent interface. This will enable
|
|
3414
|
+
* us to evolve the agent interface and retain backwards compatibility.
|
|
3415
|
+
*/
|
|
3416
|
+
readonly version: 'agent-v1';
|
|
3417
|
+
/**
|
|
3418
|
+
* The id of the agent.
|
|
3419
|
+
*/
|
|
3420
|
+
readonly id: string | undefined;
|
|
3421
|
+
/**
|
|
3422
|
+
* The tools that the agent can use.
|
|
3423
|
+
*/
|
|
3424
|
+
readonly tools: TOOLS;
|
|
3425
|
+
/**
|
|
3426
|
+
* Generates an output from the agent (non-streaming).
|
|
3427
|
+
*/
|
|
3428
|
+
generate(options: AgentCallParameters<CALL_OPTIONS, TOOLS>): PromiseLike<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
3429
|
+
/**
|
|
3430
|
+
* Streams an output from the agent (streaming).
|
|
3431
|
+
*/
|
|
3432
|
+
stream(options: AgentStreamParameters<CALL_OPTIONS, TOOLS>): PromiseLike<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3424
3435
|
/**
|
|
3425
3436
|
* A tool loop agent is an agent that runs tools in a loop. In each step,
|
|
3426
3437
|
* it calls the LLM, and if there are tool calls, it executes the tools
|
|
@@ -3445,15 +3456,15 @@ declare class ToolLoopAgent<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OU
|
|
|
3445
3456
|
*/
|
|
3446
3457
|
get tools(): TOOLS;
|
|
3447
3458
|
private prepareCall;
|
|
3448
|
-
private
|
|
3459
|
+
private mergeCallbacks;
|
|
3449
3460
|
/**
|
|
3450
3461
|
* Generates an output from the agent (non-streaming).
|
|
3451
3462
|
*/
|
|
3452
|
-
generate({ abortSignal, timeout, onStepFinish, ...options }: AgentCallParameters<CALL_OPTIONS, TOOLS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
3463
|
+
generate({ abortSignal, timeout, experimental_onStart, experimental_onStepStart, experimental_onToolCallStart, experimental_onToolCallFinish, onStepFinish, onFinish, ...options }: AgentCallParameters<CALL_OPTIONS, TOOLS>): Promise<GenerateTextResult<TOOLS, OUTPUT>>;
|
|
3453
3464
|
/**
|
|
3454
3465
|
* Streams an output from the agent (streaming).
|
|
3455
3466
|
*/
|
|
3456
|
-
stream({ abortSignal, timeout, experimental_transform, onStepFinish, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3467
|
+
stream({ abortSignal, timeout, experimental_transform, experimental_onStart, experimental_onStepStart, experimental_onToolCallStart, experimental_onToolCallFinish, onStepFinish, onFinish, ...options }: AgentStreamParameters<CALL_OPTIONS, TOOLS>): Promise<StreamTextResult<TOOLS, OUTPUT>>;
|
|
3457
3468
|
}
|
|
3458
3469
|
|
|
3459
3470
|
/**
|
|
@@ -6369,4 +6380,4 @@ declare global {
|
|
|
6369
6380
|
var AI_SDK_LOG_WARNINGS: LogWarningsFunction | undefined | false;
|
|
6370
6381
|
}
|
|
6371
6382
|
|
|
6372
|
-
export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
|
|
6383
|
+
export { AbstractChat, Agent, AgentCallParameters, AgentStreamParameters, AsyncIterableStream, CallSettings, CallWarning, ChatAddToolApproveResponseFunction, ChatInit, ChatOnDataCallback, ChatOnErrorCallback, ChatOnFinishCallback, ChatOnToolCallCallback, ChatRequestOptions, ChatState, ChatStatus, ChatTransport, ChunkDetector, CompletionRequestOptions, ContentPart, CreateUIMessage, DataUIPart, DeepPartial, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DirectChatTransportOptions, DynamicToolCall, DynamicToolError, DynamicToolResult, DynamicToolUIPart, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingModelMiddleware, EmbeddingModelUsage, ErrorHandler, ToolLoopAgent as Experimental_Agent, ToolLoopAgentSettings as Experimental_AgentSettings, DownloadFunction as Experimental_DownloadFunction, Experimental_GenerateImageResult, GeneratedFile as Experimental_GeneratedImage, InferAgentUIMessage as Experimental_InferAgentUIMessage, LogWarningsFunction as Experimental_LogWarningsFunction, SpeechResult as Experimental_SpeechResult, TranscriptionResult as Experimental_TranscriptionResult, FileUIPart, FinishReason, GenerateImageResult, GenerateObjectResult, GenerateTextOnFinishCallback, GenerateTextOnStartCallback, GenerateTextOnStepFinishCallback, GenerateTextOnStepStartCallback, GenerateTextOnToolCallFinishCallback, GenerateTextOnToolCallStartCallback, GenerateTextResult, GenerateVideoPrompt, GenerateVideoResult, GeneratedAudioFile, GeneratedFile, HttpChatTransport, HttpChatTransportInitOptions, ImageModel, ImageModelMiddleware, ImageModelProviderMetadata, ImageModelResponseMetadata, ImageModelUsage, InferAgentUIMessage, InferCompleteOutput as InferGenerateOutput, InferPartialOutput as InferStreamOutput, InferUIDataParts, InferUIMessageChunk, InferUITool, InferUITools, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolInputError, JSONValue, JsonToSseTransformStream, LanguageModel, LanguageModelMiddleware, LanguageModelRequestMetadata, LanguageModelResponseMetadata, LanguageModelUsage, LogWarningsFunction, MessageConversionError, MissingToolResultsError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchProviderError, NoSuchToolError, NoTranscriptGeneratedError, NoVideoGeneratedError, ObjectStreamPart, output as Output, PrepareReconnectToStreamRequest, PrepareSendMessagesRequest, PrepareStepFunction, PrepareStepResult, Prompt, Provider, ProviderMetadata, ProviderRegistryProvider, ReasoningOutput, ReasoningUIPart, RepairTextFunction, RerankResult, RerankingModel, RetryError, SafeValidateUIMessagesResult, SerialJobExecutor, SourceDocumentUIPart, SourceUrlUIPart, SpeechModel, SpeechModelResponseMetadata, StaticToolCall, StaticToolError, StaticToolOutputDenied, StaticToolResult, StepResult, StepStartUIPart, StopCondition, StreamObjectOnFinishCallback, StreamObjectResult, StreamTextOnChunkCallback, StreamTextOnErrorCallback, StreamTextOnFinishCallback, StreamTextOnStartCallback, StreamTextOnStepFinishCallback, StreamTextOnStepStartCallback, StreamTextOnToolCallFinishCallback, StreamTextOnToolCallStartCallback, StreamTextResult, StreamTextTransform, TelemetrySettings, TextStreamChatTransport, TextStreamPart, TextUIPart, TimeoutConfiguration, ToolApprovalRequestOutput, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolCallRepairFunction, ToolChoice, ToolLoopAgent, ToolLoopAgentOnFinishCallback, ToolLoopAgentOnStartCallback, ToolLoopAgentOnStepFinishCallback, ToolLoopAgentOnStepStartCallback, ToolLoopAgentOnToolCallFinishCallback, ToolLoopAgentOnToolCallStartCallback, ToolLoopAgentSettings, ToolSet, ToolUIPart, TranscriptionModel, TranscriptionModelResponseMetadata, TypedToolCall, TypedToolError, TypedToolOutputDenied, TypedToolResult, UIDataPartSchemas, UIDataTypes, UIMessage, UIMessageChunk, UIMessagePart, UIMessageStreamError, UIMessageStreamOnFinishCallback, UIMessageStreamOnStepFinishCallback, UIMessageStreamOptions, UIMessageStreamWriter, UITool, UIToolInvocation, UITools, UI_MESSAGE_STREAM_HEADERS, UnsupportedModelVersionError, UseCompletionOptions, Warning, addToolInputExamplesMiddleware, assistantModelMessageSchema, callCompletionApi, consumeStream, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultSettingsMiddleware, embed, embedMany, experimental_createProviderRegistry, experimental_customProvider, experimental_generateImage, generateSpeech as experimental_generateSpeech, experimental_generateVideo, transcribe as experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, generateImage, generateObject, generateText, getStaticToolName, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, hasToolCall, isDataUIPart, isDeepEqualData, isFileUIPart, isReasoningUIPart, isStaticToolUIPart, isTextUIPart, isToolOrDynamicToolUIPart, isToolUIPart, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, stepCountIs, streamObject, streamText, systemModelMessageSchema, toolModelMessageSchema, uiMessageChunkSchema, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider };
|