ai 6.0.134 → 6.0.136
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 +4 -44
- package/dist/index.d.ts +4 -44
- package/dist/index.js +12 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -69
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/03-agents/02-building-agents.mdx +6 -48
- package/docs/07-reference/01-ai-sdk-core/15-agent.mdx +0 -25
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +0 -475
- package/package.json +3 -3
- package/src/agent/agent.ts +1 -33
- package/src/agent/index.ts +0 -4
- package/src/agent/tool-loop-agent-settings.ts +0 -49
- package/src/agent/tool-loop-agent.ts +23 -82
package/dist/internal/index.js
CHANGED
|
@@ -153,7 +153,7 @@ var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
|
153
153
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
154
154
|
|
|
155
155
|
// src/version.ts
|
|
156
|
-
var VERSION = true ? "6.0.
|
|
156
|
+
var VERSION = true ? "6.0.136" : "0.0.0-test";
|
|
157
157
|
|
|
158
158
|
// src/util/download/download.ts
|
|
159
159
|
var download = async ({
|
package/dist/internal/index.mjs
CHANGED
|
@@ -329,68 +329,26 @@ export async function POST(request: Request) {
|
|
|
329
329
|
}
|
|
330
330
|
```
|
|
331
331
|
|
|
332
|
-
###
|
|
332
|
+
### Track Step Progress
|
|
333
333
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
releases.
|
|
337
|
-
</Note>
|
|
338
|
-
|
|
339
|
-
Agents provide lifecycle callbacks that let you hook into different phases of the agent execution.
|
|
340
|
-
These are useful for logging, observability, debugging, and custom telemetry.
|
|
334
|
+
Use `onStepFinish` to track each step's progress, including token usage.
|
|
335
|
+
The callback receives a `stepNumber` (zero-based) to identify which step just completed:
|
|
341
336
|
|
|
342
337
|
```ts
|
|
343
338
|
const result = await myAgent.generate({
|
|
344
339
|
prompt: 'Research and summarize the latest AI trends',
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
console.log('Agent started', { model: model.modelId, functionId });
|
|
348
|
-
},
|
|
349
|
-
|
|
350
|
-
experimental_onStepStart({ stepNumber, model }) {
|
|
351
|
-
console.log(`Step ${stepNumber} starting`, { model: model.modelId });
|
|
352
|
-
},
|
|
353
|
-
|
|
354
|
-
experimental_onToolCallStart({ toolCall }) {
|
|
355
|
-
console.log(`Tool call starting: ${toolCall.toolName}`);
|
|
356
|
-
},
|
|
357
|
-
|
|
358
|
-
experimental_onToolCallFinish({ toolCall, durationMs, success }) {
|
|
359
|
-
console.log(`Tool call finished: ${toolCall.toolName} (${durationMs}ms)`, {
|
|
360
|
-
success,
|
|
361
|
-
});
|
|
362
|
-
},
|
|
363
|
-
|
|
364
|
-
onStepFinish({ stepNumber, usage, finishReason, toolCalls }) {
|
|
365
|
-
console.log(`Step ${stepNumber} completed:`, {
|
|
340
|
+
onStepFinish: async ({ stepNumber, usage, finishReason, toolCalls }) => {
|
|
341
|
+
console.log(`Step ${stepNumber} completed:`, {
|
|
366
342
|
inputTokens: usage.inputTokens,
|
|
367
343
|
outputTokens: usage.outputTokens,
|
|
368
344
|
finishReason,
|
|
369
345
|
toolsUsed: toolCalls?.map(tc => tc.toolName),
|
|
370
346
|
});
|
|
371
347
|
},
|
|
372
|
-
|
|
373
|
-
onFinish({ totalUsage, steps }) {
|
|
374
|
-
console.log('Agent finished:', {
|
|
375
|
-
totalSteps: steps.length,
|
|
376
|
-
totalTokens: totalUsage.totalTokens,
|
|
377
|
-
});
|
|
378
|
-
},
|
|
379
348
|
});
|
|
380
349
|
```
|
|
381
350
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
- **`experimental_onStart`**: Called once when the agent operation begins, before any LLM calls. Receives model info, prompt, settings, and telemetry metadata.
|
|
385
|
-
- **`experimental_onStepStart`**: Called before each step (LLM call). Receives the step number, model, messages being sent, tools, and prior steps.
|
|
386
|
-
- **`experimental_onToolCallStart`**: Called right before a tool's `execute` function runs. Receives the tool call object with tool name, call ID, and input.
|
|
387
|
-
- **`experimental_onToolCallFinish`**: Called right after a tool's `execute` function completes or errors. Receives the tool call, `durationMs`, and a `success` discriminator (`output` when successful, `error` when failed).
|
|
388
|
-
- **`onStepFinish`**: Called after each step finishes. Receives step results including usage, finish reason, and tool calls.
|
|
389
|
-
- **`onFinish`**: Called when all steps are finished and the response is complete. Receives all step results, total usage, and telemetry metadata.
|
|
390
|
-
|
|
391
|
-
#### Constructor vs. Method Callbacks
|
|
392
|
-
|
|
393
|
-
All lifecycle callbacks can be defined in the constructor for agent-wide tracking, in the `generate()`/`stream()` call for per-call tracking, or both. When both are provided, both are called (constructor first, then the method callback):
|
|
351
|
+
You can also define `onStepFinish` in the constructor for agent-wide tracking. When both constructor and method callbacks are provided, both are called (constructor first, then the method callback):
|
|
394
352
|
|
|
395
353
|
```ts
|
|
396
354
|
const agent = new ToolLoopAgent({
|
|
@@ -65,30 +65,10 @@ export type AgentCallParameters<CALL_OPTIONS, TOOLS extends ToolSet = {}> = ([
|
|
|
65
65
|
* Can be used alongside abortSignal.
|
|
66
66
|
*/
|
|
67
67
|
timeout?: number | { totalMs?: number };
|
|
68
|
-
/**
|
|
69
|
-
* Callback that is called when the agent operation begins, before any LLM calls.
|
|
70
|
-
*/
|
|
71
|
-
experimental_onStart?: ToolLoopAgentOnStartCallback<TOOLS>;
|
|
72
|
-
/**
|
|
73
|
-
* Callback that is called when a step (LLM call) begins, before the provider is called.
|
|
74
|
-
*/
|
|
75
|
-
experimental_onStepStart?: ToolLoopAgentOnStepStartCallback<TOOLS>;
|
|
76
|
-
/**
|
|
77
|
-
* Callback that is called before each tool execution begins.
|
|
78
|
-
*/
|
|
79
|
-
experimental_onToolCallStart?: ToolLoopAgentOnToolCallStartCallback<TOOLS>;
|
|
80
|
-
/**
|
|
81
|
-
* Callback that is called after each tool execution completes.
|
|
82
|
-
*/
|
|
83
|
-
experimental_onToolCallFinish?: ToolLoopAgentOnToolCallFinishCallback<TOOLS>;
|
|
84
68
|
/**
|
|
85
69
|
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
86
70
|
*/
|
|
87
71
|
onStepFinish?: ToolLoopAgentOnStepFinishCallback<TOOLS>;
|
|
88
|
-
/**
|
|
89
|
-
* Callback that is called when all steps are finished and the response is complete.
|
|
90
|
-
*/
|
|
91
|
-
onFinish?: ToolLoopAgentOnFinishCallback<TOOLS>;
|
|
92
72
|
};
|
|
93
73
|
|
|
94
74
|
/**
|
|
@@ -162,12 +142,7 @@ Both `generate()` and `stream()` accept an `AgentCallParameters<CALL_OPTIONS, TO
|
|
|
162
142
|
- `options` (optional): Additional call options when `CALL_OPTIONS` is not `never`
|
|
163
143
|
- `abortSignal` (optional): An `AbortSignal` to cancel the operation
|
|
164
144
|
- `timeout` (optional): A timeout in milliseconds. Can be specified as a number or as an object with a `totalMs` property. The call will be aborted if it takes longer than the specified timeout. Can be used alongside `abortSignal`.
|
|
165
|
-
- `experimental_onStart` (optional): Callback invoked when the agent operation begins, before any LLM calls. Experimental.
|
|
166
|
-
- `experimental_onStepStart` (optional): Callback invoked when a step (LLM call) begins, before the provider is called. Experimental.
|
|
167
|
-
- `experimental_onToolCallStart` (optional): Callback invoked right before a tool's execute function runs. Experimental.
|
|
168
|
-
- `experimental_onToolCallFinish` (optional): Callback invoked right after a tool's execute function completes or errors. Experimental.
|
|
169
145
|
- `onStepFinish` (optional): A callback invoked after each agent step (LLM/tool call) completes. Useful for tracking token usage or logging.
|
|
170
|
-
- `onFinish` (optional): A callback invoked when all steps are finished and the response is complete.
|
|
171
146
|
|
|
172
147
|
## Example: Custom Agent Implementation
|
|
173
148
|
|
|
@@ -104,411 +104,6 @@ To see `ToolLoopAgent` in action, check out [these examples](#examples).
|
|
|
104
104
|
description:
|
|
105
105
|
'Optional callback to attempt automatic recovery when a tool call cannot be parsed.',
|
|
106
106
|
},
|
|
107
|
-
{
|
|
108
|
-
name: 'experimental_onStart',
|
|
109
|
-
type: 'ToolLoopAgentOnStartCallback',
|
|
110
|
-
isOptional: true,
|
|
111
|
-
description:
|
|
112
|
-
'Callback that is called when the agent operation begins, before any LLM calls are made. Useful for logging, analytics, or initializing state. If also specified in `generate()` or `stream()`, both callbacks are called (constructor first). Experimental (can break in patch releases).',
|
|
113
|
-
properties: [
|
|
114
|
-
{
|
|
115
|
-
type: 'OnStartEvent',
|
|
116
|
-
parameters: [
|
|
117
|
-
{
|
|
118
|
-
name: 'model',
|
|
119
|
-
type: '{ provider: string; modelId: string }',
|
|
120
|
-
description: 'The model being used for the generation.',
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
name: 'system',
|
|
124
|
-
type: 'string | SystemModelMessage | Array<SystemModelMessage> | undefined',
|
|
125
|
-
description: 'The system message(s) provided to the model.',
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: 'prompt',
|
|
129
|
-
type: 'string | Array<ModelMessage> | undefined',
|
|
130
|
-
description:
|
|
131
|
-
'The prompt string or array of messages if using the prompt option.',
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
name: 'messages',
|
|
135
|
-
type: 'Array<ModelMessage> | undefined',
|
|
136
|
-
description: 'The messages array if using the messages option.',
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
name: 'tools',
|
|
140
|
-
type: 'TOOLS | undefined',
|
|
141
|
-
description: 'The tools available for this generation.',
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: 'toolChoice',
|
|
145
|
-
type: 'ToolChoice<TOOLS> | undefined',
|
|
146
|
-
description: 'The tool choice strategy for this generation.',
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
name: 'activeTools',
|
|
150
|
-
type: 'Array<keyof TOOLS> | undefined',
|
|
151
|
-
description:
|
|
152
|
-
'Limits which tools are available for the model to call.',
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
name: 'maxOutputTokens',
|
|
156
|
-
type: 'number | undefined',
|
|
157
|
-
description: 'Maximum number of tokens to generate.',
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
name: 'temperature',
|
|
161
|
-
type: 'number | undefined',
|
|
162
|
-
description: 'Sampling temperature for generation.',
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: 'topP',
|
|
166
|
-
type: 'number | undefined',
|
|
167
|
-
description: 'Top-p (nucleus) sampling parameter.',
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
name: 'topK',
|
|
171
|
-
type: 'number | undefined',
|
|
172
|
-
description: 'Top-k sampling parameter.',
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
name: 'presencePenalty',
|
|
176
|
-
type: 'number | undefined',
|
|
177
|
-
description: 'Presence penalty for generation.',
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
name: 'frequencyPenalty',
|
|
181
|
-
type: 'number | undefined',
|
|
182
|
-
description: 'Frequency penalty for generation.',
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
name: 'stopSequences',
|
|
186
|
-
type: 'string[] | undefined',
|
|
187
|
-
description: 'Sequences that will stop generation.',
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
name: 'seed',
|
|
191
|
-
type: 'number | undefined',
|
|
192
|
-
description: 'Random seed for reproducible generation.',
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
name: 'maxRetries',
|
|
196
|
-
type: 'number',
|
|
197
|
-
description: 'Maximum number of retries for failed requests.',
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
name: 'timeout',
|
|
201
|
-
type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined',
|
|
202
|
-
description: 'Timeout configuration for the generation.',
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
name: 'headers',
|
|
206
|
-
type: 'Record<string, string | undefined> | undefined',
|
|
207
|
-
description: 'Additional HTTP headers sent with the request.',
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
name: 'providerOptions',
|
|
211
|
-
type: 'ProviderOptions | undefined',
|
|
212
|
-
description: 'Additional provider-specific options.',
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
name: 'stopWhen',
|
|
216
|
-
type: 'StopCondition<TOOLS> | Array<StopCondition<TOOLS>> | undefined',
|
|
217
|
-
description: 'Condition(s) for stopping the generation.',
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
name: 'output',
|
|
221
|
-
type: 'OUTPUT | undefined',
|
|
222
|
-
description:
|
|
223
|
-
'The output specification for structured outputs, if configured.',
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
name: 'abortSignal',
|
|
227
|
-
type: 'AbortSignal | undefined',
|
|
228
|
-
description: 'Abort signal for cancelling the operation.',
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
name: 'include',
|
|
232
|
-
type: '{ requestBody?: boolean; responseBody?: boolean } | undefined',
|
|
233
|
-
description:
|
|
234
|
-
'Settings for controlling what data is included in step results.',
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
name: 'functionId',
|
|
238
|
-
type: 'string | undefined',
|
|
239
|
-
description:
|
|
240
|
-
'Identifier from telemetry settings for grouping related operations.',
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
name: 'metadata',
|
|
244
|
-
type: 'Record<string, unknown> | undefined',
|
|
245
|
-
description: 'Additional metadata passed to the generation.',
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
name: 'experimental_context',
|
|
249
|
-
type: 'unknown',
|
|
250
|
-
description:
|
|
251
|
-
'User-defined context object that flows through the entire generation lifecycle.',
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
},
|
|
255
|
-
],
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
name: 'experimental_onStepStart',
|
|
259
|
-
type: 'ToolLoopAgentOnStepStartCallback',
|
|
260
|
-
isOptional: true,
|
|
261
|
-
description:
|
|
262
|
-
'Callback that is called when a step (LLM call) begins, before the provider is called. Each step represents a single LLM invocation. If also specified in `generate()` or `stream()`, both callbacks are called (constructor first). Experimental (can break in patch releases).',
|
|
263
|
-
properties: [
|
|
264
|
-
{
|
|
265
|
-
type: 'OnStepStartEvent',
|
|
266
|
-
parameters: [
|
|
267
|
-
{
|
|
268
|
-
name: 'stepNumber',
|
|
269
|
-
type: 'number',
|
|
270
|
-
description: 'Zero-based index of the current step.',
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
name: 'model',
|
|
274
|
-
type: '{ provider: string; modelId: string }',
|
|
275
|
-
description: 'The model being used for this step.',
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
name: 'system',
|
|
279
|
-
type: 'string | SystemModelMessage | Array<SystemModelMessage> | undefined',
|
|
280
|
-
description: 'The system message for this step.',
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
name: 'messages',
|
|
284
|
-
type: 'Array<ModelMessage>',
|
|
285
|
-
description:
|
|
286
|
-
'The messages that will be sent to the model for this step.',
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
name: 'tools',
|
|
290
|
-
type: 'TOOLS | undefined',
|
|
291
|
-
description: 'The tools available for this generation.',
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
name: 'toolChoice',
|
|
295
|
-
type: 'LanguageModelV3ToolChoice | undefined',
|
|
296
|
-
description: 'The tool choice configuration for this step.',
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
name: 'activeTools',
|
|
300
|
-
type: 'Array<keyof TOOLS> | undefined',
|
|
301
|
-
description: 'Limits which tools are available for this step.',
|
|
302
|
-
},
|
|
303
|
-
{
|
|
304
|
-
name: 'steps',
|
|
305
|
-
type: 'ReadonlyArray<StepResult<TOOLS>>',
|
|
306
|
-
description:
|
|
307
|
-
'Array of results from previous steps (empty for first step).',
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
name: 'providerOptions',
|
|
311
|
-
type: 'ProviderOptions | undefined',
|
|
312
|
-
description:
|
|
313
|
-
'Additional provider-specific options for this step.',
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
name: 'timeout',
|
|
317
|
-
type: 'number | { totalMs?: number; stepMs?: number; chunkMs?: number } | undefined',
|
|
318
|
-
description: 'Timeout configuration for the generation.',
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
name: 'headers',
|
|
322
|
-
type: 'Record<string, string | undefined> | undefined',
|
|
323
|
-
description: 'Additional HTTP headers sent with the request.',
|
|
324
|
-
},
|
|
325
|
-
{
|
|
326
|
-
name: 'stopWhen',
|
|
327
|
-
type: 'StopCondition<TOOLS> | Array<StopCondition<TOOLS>> | undefined',
|
|
328
|
-
description: 'Condition(s) for stopping the generation.',
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
name: 'output',
|
|
332
|
-
type: 'OUTPUT | undefined',
|
|
333
|
-
description:
|
|
334
|
-
'The output specification for structured outputs, if configured.',
|
|
335
|
-
},
|
|
336
|
-
{
|
|
337
|
-
name: 'abortSignal',
|
|
338
|
-
type: 'AbortSignal | undefined',
|
|
339
|
-
description: 'Abort signal for cancelling the operation.',
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
name: 'include',
|
|
343
|
-
type: '{ requestBody?: boolean; responseBody?: boolean } | undefined',
|
|
344
|
-
description:
|
|
345
|
-
'Settings for controlling what data is included in step results.',
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
name: 'functionId',
|
|
349
|
-
type: 'string | undefined',
|
|
350
|
-
description:
|
|
351
|
-
'Identifier from telemetry settings for grouping related operations.',
|
|
352
|
-
},
|
|
353
|
-
{
|
|
354
|
-
name: 'metadata',
|
|
355
|
-
type: 'Record<string, unknown> | undefined',
|
|
356
|
-
description: 'Additional metadata from telemetry settings.',
|
|
357
|
-
},
|
|
358
|
-
{
|
|
359
|
-
name: 'experimental_context',
|
|
360
|
-
type: 'unknown',
|
|
361
|
-
description:
|
|
362
|
-
'User-defined context object. May be updated from prepareStep between steps.',
|
|
363
|
-
},
|
|
364
|
-
],
|
|
365
|
-
},
|
|
366
|
-
],
|
|
367
|
-
},
|
|
368
|
-
{
|
|
369
|
-
name: 'experimental_onToolCallStart',
|
|
370
|
-
type: 'ToolLoopAgentOnToolCallStartCallback',
|
|
371
|
-
isOptional: true,
|
|
372
|
-
description:
|
|
373
|
-
"Callback that is called right before a tool's execute function runs. If also specified in `generate()` or `stream()`, both callbacks are called (constructor first). Experimental (can break in patch releases).",
|
|
374
|
-
properties: [
|
|
375
|
-
{
|
|
376
|
-
type: 'OnToolCallStartEvent',
|
|
377
|
-
parameters: [
|
|
378
|
-
{
|
|
379
|
-
name: 'stepNumber',
|
|
380
|
-
type: 'number | undefined',
|
|
381
|
-
description:
|
|
382
|
-
'The zero-based index of the current step where this tool call occurs. May be undefined in streaming contexts.',
|
|
383
|
-
},
|
|
384
|
-
{
|
|
385
|
-
name: 'model',
|
|
386
|
-
type: '{ provider: string; modelId: string } | undefined',
|
|
387
|
-
description:
|
|
388
|
-
'Information about the model being used. May be undefined in streaming contexts.',
|
|
389
|
-
},
|
|
390
|
-
{
|
|
391
|
-
name: 'toolCall',
|
|
392
|
-
type: 'TypedToolCall<TOOLS>',
|
|
393
|
-
description:
|
|
394
|
-
'The full tool call object containing toolName, toolCallId, input, and metadata.',
|
|
395
|
-
},
|
|
396
|
-
{
|
|
397
|
-
name: 'messages',
|
|
398
|
-
type: 'Array<ModelMessage>',
|
|
399
|
-
description:
|
|
400
|
-
'The conversation messages available at tool execution time.',
|
|
401
|
-
},
|
|
402
|
-
{
|
|
403
|
-
name: 'abortSignal',
|
|
404
|
-
type: 'AbortSignal | undefined',
|
|
405
|
-
description: 'Signal for cancelling the operation.',
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
name: 'functionId',
|
|
409
|
-
type: 'string | undefined',
|
|
410
|
-
description:
|
|
411
|
-
'Identifier from telemetry settings for grouping related operations.',
|
|
412
|
-
},
|
|
413
|
-
{
|
|
414
|
-
name: 'metadata',
|
|
415
|
-
type: 'Record<string, unknown> | undefined',
|
|
416
|
-
description: 'Additional metadata from telemetry settings.',
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
name: 'experimental_context',
|
|
420
|
-
type: 'unknown',
|
|
421
|
-
description:
|
|
422
|
-
'User-defined context object flowing through the generation.',
|
|
423
|
-
},
|
|
424
|
-
],
|
|
425
|
-
},
|
|
426
|
-
],
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
name: 'experimental_onToolCallFinish',
|
|
430
|
-
type: 'ToolLoopAgentOnToolCallFinishCallback',
|
|
431
|
-
isOptional: true,
|
|
432
|
-
description:
|
|
433
|
-
"Callback that is called right after a tool's execute function completes (or errors). Uses a discriminated union on the `success` field: when `success: true`, `output` contains the tool result; when `success: false`, `error` contains the error. If also specified in `generate()` or `stream()`, both callbacks are called (constructor first). Experimental (can break in patch releases).",
|
|
434
|
-
properties: [
|
|
435
|
-
{
|
|
436
|
-
type: 'OnToolCallFinishEvent',
|
|
437
|
-
parameters: [
|
|
438
|
-
{
|
|
439
|
-
name: 'stepNumber',
|
|
440
|
-
type: 'number | undefined',
|
|
441
|
-
description:
|
|
442
|
-
'The zero-based index of the current step where this tool call occurred. May be undefined in streaming contexts.',
|
|
443
|
-
},
|
|
444
|
-
{
|
|
445
|
-
name: 'model',
|
|
446
|
-
type: '{ provider: string; modelId: string } | undefined',
|
|
447
|
-
description:
|
|
448
|
-
'Information about the model being used. May be undefined in streaming contexts.',
|
|
449
|
-
},
|
|
450
|
-
{
|
|
451
|
-
name: 'toolCall',
|
|
452
|
-
type: 'TypedToolCall<TOOLS>',
|
|
453
|
-
description:
|
|
454
|
-
'The full tool call object containing toolName, toolCallId, input, and metadata.',
|
|
455
|
-
},
|
|
456
|
-
{
|
|
457
|
-
name: 'messages',
|
|
458
|
-
type: 'Array<ModelMessage>',
|
|
459
|
-
description:
|
|
460
|
-
'The conversation messages available at tool execution time.',
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
name: 'abortSignal',
|
|
464
|
-
type: 'AbortSignal | undefined',
|
|
465
|
-
description: 'Signal for cancelling the operation.',
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
name: 'durationMs',
|
|
469
|
-
type: 'number',
|
|
470
|
-
description:
|
|
471
|
-
'The wall-clock duration of the tool execution in milliseconds.',
|
|
472
|
-
},
|
|
473
|
-
{
|
|
474
|
-
name: 'functionId',
|
|
475
|
-
type: 'string | undefined',
|
|
476
|
-
description:
|
|
477
|
-
'Identifier from telemetry settings for grouping related operations.',
|
|
478
|
-
},
|
|
479
|
-
{
|
|
480
|
-
name: 'metadata',
|
|
481
|
-
type: 'Record<string, unknown> | undefined',
|
|
482
|
-
description: 'Additional metadata from telemetry settings.',
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
name: 'experimental_context',
|
|
486
|
-
type: 'unknown',
|
|
487
|
-
description:
|
|
488
|
-
'User-defined context object flowing through the generation.',
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
name: 'success',
|
|
492
|
-
type: 'boolean',
|
|
493
|
-
description:
|
|
494
|
-
'Discriminator indicating whether the tool call succeeded. When true, output is available. When false, error is available.',
|
|
495
|
-
},
|
|
496
|
-
{
|
|
497
|
-
name: 'output',
|
|
498
|
-
type: 'unknown',
|
|
499
|
-
description:
|
|
500
|
-
"The tool's return value (only present when `success: true`).",
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
name: 'error',
|
|
504
|
-
type: 'unknown',
|
|
505
|
-
description:
|
|
506
|
-
'The error that occurred during tool execution (only present when `success: false`).',
|
|
507
|
-
},
|
|
508
|
-
],
|
|
509
|
-
},
|
|
510
|
-
],
|
|
511
|
-
},
|
|
512
107
|
{
|
|
513
108
|
name: 'onStepFinish',
|
|
514
109
|
type: 'ToolLoopAgentOnStepFinishCallback',
|
|
@@ -681,34 +276,6 @@ const result = await agent.generate({
|
|
|
681
276
|
description:
|
|
682
277
|
'Custom call options when the agent is configured with a callOptionsSchema.',
|
|
683
278
|
},
|
|
684
|
-
{
|
|
685
|
-
name: 'experimental_onStart',
|
|
686
|
-
type: 'ToolLoopAgentOnStartCallback',
|
|
687
|
-
isOptional: true,
|
|
688
|
-
description:
|
|
689
|
-
'Callback that is called when the agent operation begins, before any LLM calls are made. If also specified in the constructor, both callbacks are called (constructor first). Experimental (can break in patch releases).',
|
|
690
|
-
},
|
|
691
|
-
{
|
|
692
|
-
name: 'experimental_onStepStart',
|
|
693
|
-
type: 'ToolLoopAgentOnStepStartCallback',
|
|
694
|
-
isOptional: true,
|
|
695
|
-
description:
|
|
696
|
-
'Callback that is called when a step (LLM call) begins, before the provider is called. If also specified in the constructor, both callbacks are called (constructor first). Experimental (can break in patch releases).',
|
|
697
|
-
},
|
|
698
|
-
{
|
|
699
|
-
name: 'experimental_onToolCallStart',
|
|
700
|
-
type: 'ToolLoopAgentOnToolCallStartCallback',
|
|
701
|
-
isOptional: true,
|
|
702
|
-
description:
|
|
703
|
-
"Callback that is called right before a tool's execute function runs. If also specified in the constructor, both callbacks are called (constructor first). Experimental (can break in patch releases).",
|
|
704
|
-
},
|
|
705
|
-
{
|
|
706
|
-
name: 'experimental_onToolCallFinish',
|
|
707
|
-
type: 'ToolLoopAgentOnToolCallFinishCallback',
|
|
708
|
-
isOptional: true,
|
|
709
|
-
description:
|
|
710
|
-
"Callback that is called right after a tool's execute function completes (or errors). If also specified in the constructor, both callbacks are called (constructor first). Experimental (can break in patch releases).",
|
|
711
|
-
},
|
|
712
279
|
{
|
|
713
280
|
name: 'onStepFinish',
|
|
714
281
|
type: 'ToolLoopAgentOnStepFinishCallback',
|
|
@@ -716,13 +283,6 @@ const result = await agent.generate({
|
|
|
716
283
|
description:
|
|
717
284
|
'Callback invoked after each agent step (LLM/tool call) completes. If also specified in the constructor, both callbacks are called (constructor first, then this one).',
|
|
718
285
|
},
|
|
719
|
-
{
|
|
720
|
-
name: 'onFinish',
|
|
721
|
-
type: 'ToolLoopAgentOnFinishCallback',
|
|
722
|
-
isOptional: true,
|
|
723
|
-
description:
|
|
724
|
-
'Callback that is called when all agent steps are finished and the response is complete. If also specified in the constructor, both callbacks are called (constructor first, then this one).',
|
|
725
|
-
},
|
|
726
286
|
]}
|
|
727
287
|
/>
|
|
728
288
|
|
|
@@ -784,34 +344,6 @@ for await (const chunk of stream.textStream) {
|
|
|
784
344
|
description:
|
|
785
345
|
'Optional stream transformation(s). They are applied in the order provided and must maintain the stream structure. See `streamText` docs for details.',
|
|
786
346
|
},
|
|
787
|
-
{
|
|
788
|
-
name: 'experimental_onStart',
|
|
789
|
-
type: 'ToolLoopAgentOnStartCallback',
|
|
790
|
-
isOptional: true,
|
|
791
|
-
description:
|
|
792
|
-
'Callback that is called when the agent operation begins, before any LLM calls are made. If also specified in the constructor, both callbacks are called (constructor first). Experimental (can break in patch releases).',
|
|
793
|
-
},
|
|
794
|
-
{
|
|
795
|
-
name: 'experimental_onStepStart',
|
|
796
|
-
type: 'ToolLoopAgentOnStepStartCallback',
|
|
797
|
-
isOptional: true,
|
|
798
|
-
description:
|
|
799
|
-
'Callback that is called when a step (LLM call) begins, before the provider is called. If also specified in the constructor, both callbacks are called (constructor first). Experimental (can break in patch releases).',
|
|
800
|
-
},
|
|
801
|
-
{
|
|
802
|
-
name: 'experimental_onToolCallStart',
|
|
803
|
-
type: 'ToolLoopAgentOnToolCallStartCallback',
|
|
804
|
-
isOptional: true,
|
|
805
|
-
description:
|
|
806
|
-
"Callback that is called right before a tool's execute function runs. If also specified in the constructor, both callbacks are called (constructor first). Experimental (can break in patch releases).",
|
|
807
|
-
},
|
|
808
|
-
{
|
|
809
|
-
name: 'experimental_onToolCallFinish',
|
|
810
|
-
type: 'ToolLoopAgentOnToolCallFinishCallback',
|
|
811
|
-
isOptional: true,
|
|
812
|
-
description:
|
|
813
|
-
"Callback that is called right after a tool's execute function completes (or errors). If also specified in the constructor, both callbacks are called (constructor first). Experimental (can break in patch releases).",
|
|
814
|
-
},
|
|
815
347
|
{
|
|
816
348
|
name: 'onStepFinish',
|
|
817
349
|
type: 'ToolLoopAgentOnStepFinishCallback',
|
|
@@ -819,13 +351,6 @@ for await (const chunk of stream.textStream) {
|
|
|
819
351
|
description:
|
|
820
352
|
'Callback invoked after each agent step (LLM/tool call) completes. If also specified in the constructor, both callbacks are called (constructor first, then this one).',
|
|
821
353
|
},
|
|
822
|
-
{
|
|
823
|
-
name: 'onFinish',
|
|
824
|
-
type: 'ToolLoopAgentOnFinishCallback',
|
|
825
|
-
isOptional: true,
|
|
826
|
-
description:
|
|
827
|
-
'Callback that is called when all agent steps are finished and the response is complete. If also specified in the constructor, both callbacks are called (constructor first, then this one).',
|
|
828
|
-
},
|
|
829
354
|
]}
|
|
830
355
|
/>
|
|
831
356
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.136",
|
|
4
4
|
"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.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@opentelemetry/api": "1.9.0",
|
|
48
|
-
"@ai-sdk/gateway": "3.0.77",
|
|
49
48
|
"@ai-sdk/provider": "3.0.8",
|
|
50
|
-
"@ai-sdk/provider-utils": "4.0.21"
|
|
49
|
+
"@ai-sdk/provider-utils": "4.0.21",
|
|
50
|
+
"@ai-sdk/gateway": "3.0.78"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@edge-runtime/vm": "^5.0.0",
|