@convex-dev/agent 0.0.14 → 0.0.15-alpha.0
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/README.md +179 -64
- package/dist/commonjs/client/index.d.ts +149 -31
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +31 -23
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/esm/client/index.d.ts +149 -31
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +31 -23
- package/dist/esm/client/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client/index.ts +257 -77
package/src/client/index.ts
CHANGED
|
@@ -66,7 +66,7 @@ import type {
|
|
|
66
66
|
} from "./types.js";
|
|
67
67
|
import schema from "../component/schema.js";
|
|
68
68
|
|
|
69
|
-
export {
|
|
69
|
+
export type { Usage, ProviderMetadata };
|
|
70
70
|
export {
|
|
71
71
|
vUsage,
|
|
72
72
|
vProviderMetadata,
|
|
@@ -250,7 +250,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
250
250
|
* @param args The thread metadata.
|
|
251
251
|
* @returns The threadId of the new thread and the thread object.
|
|
252
252
|
*/
|
|
253
|
-
async createThread(
|
|
253
|
+
async createThread<ThreadTools extends ToolSet | undefined = undefined>(
|
|
254
254
|
ctx: RunActionCtx,
|
|
255
255
|
args?: {
|
|
256
256
|
/**
|
|
@@ -271,10 +271,15 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
271
271
|
* set in the agent constructor.
|
|
272
272
|
*/
|
|
273
273
|
usageHandler?: UsageHandler;
|
|
274
|
+
/**
|
|
275
|
+
* The tools to use for this thread.
|
|
276
|
+
* Overrides any tools passed in the agent constructor.
|
|
277
|
+
*/
|
|
278
|
+
tools?: ThreadTools;
|
|
274
279
|
}
|
|
275
280
|
): Promise<{
|
|
276
281
|
threadId: string;
|
|
277
|
-
thread: Thread<AgentTools>;
|
|
282
|
+
thread: Thread<ThreadTools extends undefined ? AgentTools : ThreadTools>;
|
|
278
283
|
}>;
|
|
279
284
|
/**
|
|
280
285
|
* Start a new thread with the agent. This will have a fresh history, though if
|
|
@@ -285,28 +290,48 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
285
290
|
* @param args The thread metadata.
|
|
286
291
|
* @returns The threadId of the new thread.
|
|
287
292
|
*/
|
|
288
|
-
async createThread(
|
|
293
|
+
async createThread<ThreadTools extends ToolSet | undefined = undefined>(
|
|
289
294
|
ctx: RunMutationCtx,
|
|
290
295
|
args?: {
|
|
296
|
+
/**
|
|
297
|
+
* The userId to associate with the thread. If not provided, the thread will be
|
|
298
|
+
* anonymous.
|
|
299
|
+
*/
|
|
291
300
|
userId?: string;
|
|
301
|
+
/**
|
|
302
|
+
* The title of the thread. Not currently used.
|
|
303
|
+
*/
|
|
292
304
|
title?: string;
|
|
305
|
+
/**
|
|
306
|
+
* The summary of the thread. Not currently used.
|
|
307
|
+
*/
|
|
293
308
|
summary?: string;
|
|
309
|
+
/**
|
|
310
|
+
* The usage handler to use for this thread. Overrides any handler
|
|
311
|
+
* set in the agent constructor.
|
|
312
|
+
*/
|
|
294
313
|
usageHandler?: UsageHandler;
|
|
314
|
+
/**
|
|
315
|
+
* The tools to use for this thread.
|
|
316
|
+
* Overrides any tools passed in the agent constructor.
|
|
317
|
+
*/
|
|
318
|
+
tools?: ThreadTools;
|
|
295
319
|
}
|
|
296
320
|
): Promise<{
|
|
297
321
|
threadId: string;
|
|
298
322
|
}>;
|
|
299
|
-
async createThread(
|
|
323
|
+
async createThread<ThreadTools extends ToolSet | undefined = undefined>(
|
|
300
324
|
ctx: RunActionCtx | RunMutationCtx,
|
|
301
325
|
args?: {
|
|
302
326
|
userId: string;
|
|
303
327
|
title?: string;
|
|
304
328
|
summary?: string;
|
|
305
329
|
usageHandler?: UsageHandler;
|
|
330
|
+
tools?: ThreadTools;
|
|
306
331
|
}
|
|
307
332
|
): Promise<{
|
|
308
333
|
threadId: string;
|
|
309
|
-
thread?: Thread<AgentTools>;
|
|
334
|
+
thread?: Thread<ThreadTools extends undefined ? AgentTools : ThreadTools>;
|
|
310
335
|
}> {
|
|
311
336
|
const threadDoc = await ctx.runMutation(
|
|
312
337
|
this.component.messages.createThread,
|
|
@@ -324,6 +349,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
324
349
|
threadId: threadDoc._id,
|
|
325
350
|
userId: args?.userId,
|
|
326
351
|
usageHandler: args?.usageHandler,
|
|
352
|
+
tools: args?.tools,
|
|
327
353
|
});
|
|
328
354
|
return {
|
|
329
355
|
threadId: threadDoc._id,
|
|
@@ -339,7 +365,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
339
365
|
* @param { threadId, userId }: the thread and user to associate the messages with.
|
|
340
366
|
* @returns Functions bound to the userId and threadId on a `{thread}` object.
|
|
341
367
|
*/
|
|
342
|
-
async continueThread(
|
|
368
|
+
async continueThread<ThreadTools extends ToolSet | undefined = undefined>(
|
|
343
369
|
ctx: RunActionCtx,
|
|
344
370
|
args: {
|
|
345
371
|
/**
|
|
@@ -356,9 +382,14 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
356
382
|
* set in the agent constructor.
|
|
357
383
|
*/
|
|
358
384
|
usageHandler?: UsageHandler;
|
|
385
|
+
/**
|
|
386
|
+
* The tools to use for this thread.
|
|
387
|
+
* Overrides any tools passed in the agent constructor.
|
|
388
|
+
*/
|
|
389
|
+
tools?: ThreadTools;
|
|
359
390
|
}
|
|
360
391
|
): Promise<{
|
|
361
|
-
thread: Thread<AgentTools>;
|
|
392
|
+
thread: Thread<ThreadTools extends undefined ? AgentTools : ThreadTools>;
|
|
362
393
|
}> {
|
|
363
394
|
return {
|
|
364
395
|
thread: {
|
|
@@ -367,7 +398,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
367
398
|
streamText: this.streamText.bind(this, ctx, args),
|
|
368
399
|
generateObject: this.generateObject.bind(this, ctx, args),
|
|
369
400
|
streamObject: this.streamObject.bind(this, ctx, args),
|
|
370
|
-
} as Thread<AgentTools>,
|
|
401
|
+
} as Thread<ThreadTools extends undefined ? AgentTools : ThreadTools>,
|
|
371
402
|
};
|
|
372
403
|
}
|
|
373
404
|
|
|
@@ -382,17 +413,18 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
382
413
|
async fetchContextMessages(
|
|
383
414
|
ctx: RunQueryCtx | RunActionCtx,
|
|
384
415
|
args: {
|
|
385
|
-
userId
|
|
386
|
-
threadId
|
|
416
|
+
userId: string | undefined;
|
|
417
|
+
threadId: string | undefined;
|
|
387
418
|
messages: CoreMessage[];
|
|
388
419
|
parentMessageId?: string;
|
|
389
|
-
|
|
420
|
+
contextOptions: ContextOptions | undefined;
|
|
421
|
+
}
|
|
390
422
|
): Promise<CoreMessage[]> {
|
|
391
423
|
assert(args.userId || args.threadId, "Specify userId or threadId");
|
|
392
424
|
// Fetch the latest messages from the thread
|
|
393
425
|
const contextMessages: MessageDoc[] = [];
|
|
394
426
|
let included: Set<string> | undefined;
|
|
395
|
-
const opts = this.mergedContextOptions(args);
|
|
427
|
+
const opts = this.mergedContextOptions(args.contextOptions);
|
|
396
428
|
if (opts.searchOptions?.textSearch || opts.searchOptions?.vectorSearch) {
|
|
397
429
|
if (!("runAction" in ctx)) {
|
|
398
430
|
throw new Error("searchUserMessages only works in an action");
|
|
@@ -400,7 +432,9 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
400
432
|
const searchMessages = await ctx.runAction(
|
|
401
433
|
this.component.messages.searchMessages,
|
|
402
434
|
{
|
|
403
|
-
userId: args.searchOtherThreads
|
|
435
|
+
userId: args.contextOptions?.searchOtherThreads
|
|
436
|
+
? args.userId
|
|
437
|
+
: undefined,
|
|
404
438
|
threadId: args.threadId,
|
|
405
439
|
parentMessageId: args.parentMessageId,
|
|
406
440
|
...(await this.searchOptionsWithDefaults(opts, args.messages)),
|
|
@@ -434,7 +468,12 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
434
468
|
.map((m) => deserializeMessage(m.message!));
|
|
435
469
|
}
|
|
436
470
|
|
|
437
|
-
|
|
471
|
+
/**
|
|
472
|
+
* Get the embeddings for a set of messages.
|
|
473
|
+
* @param messages The messages to get the embeddings for.
|
|
474
|
+
* @returns The embeddings for the messages.
|
|
475
|
+
*/
|
|
476
|
+
async generateEmbeddings(messages: CoreMessage[]) {
|
|
438
477
|
let embeddings:
|
|
439
478
|
| {
|
|
440
479
|
vectors: (number[] | null)[];
|
|
@@ -512,7 +551,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
512
551
|
lastMessageId: string;
|
|
513
552
|
messageIds: string[];
|
|
514
553
|
}> {
|
|
515
|
-
const embeddings = await this.
|
|
554
|
+
const embeddings = await this.generateEmbeddings(args.messages);
|
|
516
555
|
const result = await ctx.runMutation(this.component.messages.addMessages, {
|
|
517
556
|
threadId: args.threadId,
|
|
518
557
|
userId: args.userId,
|
|
@@ -574,7 +613,9 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
574
613
|
provider: args.provider ?? this.options.chat.provider,
|
|
575
614
|
model: args.model ?? this.options.chat.modelId,
|
|
576
615
|
});
|
|
577
|
-
const embeddings = await this.
|
|
616
|
+
const embeddings = await this.generateEmbeddings(
|
|
617
|
+
messages.map((m) => m.message)
|
|
618
|
+
);
|
|
578
619
|
if (embeddings) {
|
|
579
620
|
const { model, dimension, vectors } = embeddings;
|
|
580
621
|
for (let i = 0; i < messages.length; i++) {
|
|
@@ -635,7 +676,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
635
676
|
* @returns The result of the generateText function.
|
|
636
677
|
*/
|
|
637
678
|
async generateText<
|
|
638
|
-
TOOLS extends ToolSet,
|
|
679
|
+
TOOLS extends ToolSet | undefined = undefined,
|
|
639
680
|
OUTPUT = never,
|
|
640
681
|
OUTPUT_PARTIAL = never,
|
|
641
682
|
>(
|
|
@@ -644,6 +685,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
644
685
|
userId,
|
|
645
686
|
threadId,
|
|
646
687
|
usageHandler,
|
|
688
|
+
tools: threadTools,
|
|
647
689
|
}: {
|
|
648
690
|
userId?: string;
|
|
649
691
|
threadId?: string;
|
|
@@ -652,21 +694,25 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
652
694
|
* set in the agent constructor.
|
|
653
695
|
*/
|
|
654
696
|
usageHandler?: UsageHandler;
|
|
697
|
+
/**
|
|
698
|
+
* The tools to use for this thread. Overrides any tools passed in the agent constructor.
|
|
699
|
+
*/
|
|
700
|
+
tools?: ToolSet;
|
|
655
701
|
},
|
|
656
|
-
args: TextArgs<
|
|
657
|
-
AgentTools,
|
|
658
|
-
TOOLS,
|
|
659
|
-
Parameters<typeof generateText<TOOLS, OUTPUT, OUTPUT_PARTIAL>>[0]
|
|
660
|
-
>
|
|
702
|
+
args: TextArgs<AgentTools, TOOLS, OUTPUT, OUTPUT_PARTIAL>
|
|
661
703
|
): Promise<
|
|
662
|
-
GenerateTextResult<TOOLS
|
|
704
|
+
GenerateTextResult<TOOLS extends undefined ? AgentTools : TOOLS, OUTPUT> &
|
|
705
|
+
GenerationOutputMetadata
|
|
663
706
|
> {
|
|
664
707
|
const { args: aiArgs, messageId } = await this.saveMessagesAndFetchContext(
|
|
665
708
|
ctx,
|
|
666
709
|
{ ...args, userId, threadId }
|
|
667
710
|
);
|
|
668
711
|
const toolCtx = { ...ctx, userId, threadId, messageId };
|
|
669
|
-
const tools = wrapTools(
|
|
712
|
+
const tools = wrapTools(
|
|
713
|
+
toolCtx,
|
|
714
|
+
args.tools ?? threadTools ?? this.options.tools
|
|
715
|
+
) as TOOLS extends undefined ? AgentTools : TOOLS;
|
|
670
716
|
const saveOutputMessages =
|
|
671
717
|
args.saveOutputMessages ??
|
|
672
718
|
this.options.storageOptions?.saveOutputMessages;
|
|
@@ -679,8 +725,6 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
679
725
|
maxRetries: this.options.maxRetries,
|
|
680
726
|
...aiArgs,
|
|
681
727
|
model,
|
|
682
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
683
|
-
toolChoice: args.toolChoice as any,
|
|
684
728
|
tools,
|
|
685
729
|
onStepFinish: async (step) => {
|
|
686
730
|
if (threadId && messageId && saveOutputMessages !== false) {
|
|
@@ -704,7 +748,11 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
704
748
|
}
|
|
705
749
|
return args.onStepFinish?.(step);
|
|
706
750
|
},
|
|
707
|
-
})) as GenerateTextResult<
|
|
751
|
+
})) as GenerateTextResult<
|
|
752
|
+
TOOLS extends undefined ? AgentTools : TOOLS,
|
|
753
|
+
OUTPUT
|
|
754
|
+
> &
|
|
755
|
+
GenerationOutputMetadata;
|
|
708
756
|
result.messageId = messageId;
|
|
709
757
|
return result;
|
|
710
758
|
} catch (error) {
|
|
@@ -732,7 +780,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
732
780
|
* @returns The result of the streamText function.
|
|
733
781
|
*/
|
|
734
782
|
async streamText<
|
|
735
|
-
TOOLS extends ToolSet,
|
|
783
|
+
TOOLS extends ToolSet | undefined = undefined,
|
|
736
784
|
OUTPUT = never,
|
|
737
785
|
PARTIAL_OUTPUT = never,
|
|
738
786
|
>(
|
|
@@ -741,21 +789,34 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
741
789
|
userId,
|
|
742
790
|
threadId,
|
|
743
791
|
usageHandler,
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
792
|
+
/**
|
|
793
|
+
* @deprecated Pass `tools` in the next parameter instead.
|
|
794
|
+
* This is only intended to pass through thread-default tools.
|
|
795
|
+
*/
|
|
796
|
+
tools: threadTools,
|
|
797
|
+
}: {
|
|
798
|
+
userId?: string;
|
|
799
|
+
threadId?: string;
|
|
800
|
+
usageHandler?: UsageHandler;
|
|
801
|
+
tools?: ToolSet;
|
|
802
|
+
},
|
|
803
|
+
args: StreamingTextArgs<AgentTools, TOOLS, OUTPUT, PARTIAL_OUTPUT>
|
|
750
804
|
): Promise<
|
|
751
|
-
StreamTextResult<
|
|
805
|
+
StreamTextResult<
|
|
806
|
+
TOOLS extends undefined ? AgentTools : TOOLS,
|
|
807
|
+
PARTIAL_OUTPUT
|
|
808
|
+
> &
|
|
809
|
+
GenerationOutputMetadata
|
|
752
810
|
> {
|
|
753
811
|
const { args: aiArgs, messageId } = await this.saveMessagesAndFetchContext(
|
|
754
812
|
ctx,
|
|
755
813
|
{ ...args, userId, threadId }
|
|
756
814
|
);
|
|
757
815
|
const toolCtx = { ...ctx, userId, threadId, messageId };
|
|
758
|
-
const tools = wrapTools(
|
|
816
|
+
const tools = wrapTools(
|
|
817
|
+
toolCtx,
|
|
818
|
+
args.tools ?? threadTools ?? this.options.tools
|
|
819
|
+
) as TOOLS extends undefined ? AgentTools : TOOLS;
|
|
759
820
|
const saveOutputMessages =
|
|
760
821
|
args.saveOutputMessages ??
|
|
761
822
|
this.options.storageOptions?.saveOutputMessages;
|
|
@@ -767,8 +828,6 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
767
828
|
maxRetries: this.options.maxRetries,
|
|
768
829
|
...aiArgs,
|
|
769
830
|
model,
|
|
770
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
771
|
-
toolChoice: args.toolChoice as any,
|
|
772
831
|
tools,
|
|
773
832
|
onChunk: async (chunk) => {
|
|
774
833
|
// console.log("onChunk", chunk);
|
|
@@ -808,7 +867,11 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
808
867
|
}
|
|
809
868
|
return args.onStepFinish?.(step);
|
|
810
869
|
},
|
|
811
|
-
}) as StreamTextResult<
|
|
870
|
+
}) as StreamTextResult<
|
|
871
|
+
TOOLS extends undefined ? AgentTools : TOOLS,
|
|
872
|
+
PARTIAL_OUTPUT
|
|
873
|
+
> &
|
|
874
|
+
GenerationOutputMetadata;
|
|
812
875
|
result.messageId = messageId;
|
|
813
876
|
return result;
|
|
814
877
|
}
|
|
@@ -833,30 +896,28 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
833
896
|
userId: string | undefined;
|
|
834
897
|
threadId: string | undefined;
|
|
835
898
|
parentMessageId?: string;
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
} &
|
|
839
|
-
T
|
|
899
|
+
contextOptions?: ContextOptions;
|
|
900
|
+
storageOptions?: StorageOptions;
|
|
901
|
+
} & T
|
|
840
902
|
): Promise<{
|
|
841
903
|
args: T;
|
|
842
904
|
messageId: string | undefined;
|
|
843
905
|
}> {
|
|
844
|
-
const
|
|
845
|
-
args.
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
args.saveAllInputMessages ??
|
|
849
|
-
this.options.storageOptions?.saveAllInputMessages;
|
|
906
|
+
const contextOptions: ContextOptions | Record<string, unknown> =
|
|
907
|
+
args.contextOptions ?? this.options.contextOptions ?? args;
|
|
908
|
+
const storageOptions: StorageOptions | Record<string, unknown> =
|
|
909
|
+
args.storageOptions ?? this.options.storageOptions ?? args;
|
|
850
910
|
const messages = promptOrMessagesToCoreMessages(args);
|
|
851
911
|
const contextMessages = await this.fetchContextMessages(ctx, {
|
|
852
|
-
messages,
|
|
853
|
-
parentMessageId,
|
|
854
912
|
userId,
|
|
855
913
|
threadId,
|
|
856
|
-
|
|
914
|
+
messages,
|
|
915
|
+
parentMessageId,
|
|
916
|
+
contextOptions,
|
|
857
917
|
});
|
|
858
918
|
let messageId: string | undefined;
|
|
859
|
-
if (threadId &&
|
|
919
|
+
if (threadId && storageOptions?.saveAnyInputMessages !== false) {
|
|
920
|
+
const saveAll = storageOptions?.saveAllInputMessages;
|
|
860
921
|
const coreMessages = saveAll ? messages : messages.slice(-1);
|
|
861
922
|
const saved = await this.saveMessages(ctx, {
|
|
862
923
|
threadId,
|
|
@@ -1055,7 +1116,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
1055
1116
|
provider: this.options.chat.provider,
|
|
1056
1117
|
}
|
|
1057
1118
|
);
|
|
1058
|
-
const embeddings = await this.
|
|
1119
|
+
const embeddings = await this.generateEmbeddings([withoutEmbed[0].message]);
|
|
1059
1120
|
const messages = embeddings?.vectors[0]
|
|
1060
1121
|
? [
|
|
1061
1122
|
{
|
|
@@ -1078,10 +1139,10 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
1078
1139
|
});
|
|
1079
1140
|
}
|
|
1080
1141
|
|
|
1081
|
-
mergedContextOptions(opts: ContextOptions): ContextOptions {
|
|
1142
|
+
mergedContextOptions(opts: ContextOptions | undefined): ContextOptions {
|
|
1082
1143
|
const searchOptions = {
|
|
1083
1144
|
...this.options.contextOptions?.searchOptions,
|
|
1084
|
-
...opts
|
|
1145
|
+
...opts?.searchOptions,
|
|
1085
1146
|
};
|
|
1086
1147
|
return {
|
|
1087
1148
|
...this.options.contextOptions,
|
|
@@ -1313,33 +1374,137 @@ function wrapTools(
|
|
|
1313
1374
|
|
|
1314
1375
|
type TextArgs<
|
|
1315
1376
|
AgentTools extends ToolSet,
|
|
1316
|
-
TOOLS extends ToolSet,
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1377
|
+
TOOLS extends ToolSet | undefined = undefined,
|
|
1378
|
+
OUTPUT = never,
|
|
1379
|
+
OUTPUT_PARTIAL = never,
|
|
1380
|
+
> = Omit<
|
|
1381
|
+
Parameters<
|
|
1382
|
+
typeof generateText<
|
|
1383
|
+
TOOLS extends undefined ? AgentTools : TOOLS,
|
|
1384
|
+
OUTPUT,
|
|
1385
|
+
OUTPUT_PARTIAL
|
|
1386
|
+
>
|
|
1387
|
+
>[0],
|
|
1388
|
+
"toolChoice" | "tools" | "model"
|
|
1389
|
+
> & {
|
|
1390
|
+
/**
|
|
1391
|
+
* The model to use for the tool calls. This will override the model specified
|
|
1392
|
+
* in the Agent constructor.
|
|
1393
|
+
*/
|
|
1323
1394
|
model?: LanguageModelV1;
|
|
1395
|
+
/**
|
|
1396
|
+
* The tools to use for the tool calls. This will override tools specified
|
|
1397
|
+
* in the Agent constructor or createThread / continueThread.
|
|
1398
|
+
*/
|
|
1399
|
+
tools?: TOOLS;
|
|
1400
|
+
/**
|
|
1401
|
+
* The tool choice to use for the tool calls. This must be one of the tools
|
|
1402
|
+
* specified in the tools array. e.g. {toolName: "getWeather", type: "tool"}
|
|
1403
|
+
*/
|
|
1404
|
+
toolChoice?: ToolChoice<TOOLS extends undefined ? AgentTools : TOOLS>;
|
|
1405
|
+
// Non-AI SDK args
|
|
1406
|
+
/**
|
|
1407
|
+
* The parent message id to use for the tool calls.
|
|
1408
|
+
*/
|
|
1324
1409
|
parentMessageId?: string;
|
|
1325
|
-
|
|
1410
|
+
/**
|
|
1411
|
+
* The context options to use for passing in message history to the LLM.
|
|
1412
|
+
*/
|
|
1413
|
+
contextOptions?: ContextOptions;
|
|
1414
|
+
/**
|
|
1415
|
+
* The storage options to use for saving the input and output messages to the thread.
|
|
1416
|
+
*/
|
|
1417
|
+
storageOptions?: StorageOptions;
|
|
1418
|
+
} & ContextOptions &
|
|
1419
|
+
StorageOptions;
|
|
1420
|
+
|
|
1421
|
+
type StreamingTextArgs<
|
|
1422
|
+
AgentTools extends ToolSet,
|
|
1423
|
+
TOOLS extends ToolSet | undefined = undefined,
|
|
1424
|
+
OUTPUT = never,
|
|
1425
|
+
OUTPUT_PARTIAL = never,
|
|
1426
|
+
> = Omit<
|
|
1427
|
+
Parameters<
|
|
1428
|
+
typeof streamText<
|
|
1429
|
+
TOOLS extends undefined ? AgentTools : TOOLS,
|
|
1430
|
+
OUTPUT,
|
|
1431
|
+
OUTPUT_PARTIAL
|
|
1432
|
+
>
|
|
1433
|
+
>[0],
|
|
1434
|
+
"toolChoice" | "tools" | "model"
|
|
1435
|
+
> & {
|
|
1436
|
+
/**
|
|
1437
|
+
* The model to use for the tool calls. This will override the model specified
|
|
1438
|
+
* in the Agent constructor.
|
|
1439
|
+
*/
|
|
1440
|
+
model?: LanguageModelV1;
|
|
1441
|
+
/**
|
|
1442
|
+
* The tools to use for the tool calls. This will override tools specified
|
|
1443
|
+
* in the Agent constructor or createThread / continueThread.
|
|
1444
|
+
*/
|
|
1326
1445
|
tools?: TOOLS;
|
|
1327
|
-
|
|
1446
|
+
/**
|
|
1447
|
+
* The tool choice to use for the tool calls. This must be one of the tools
|
|
1448
|
+
* specified in the tools array. e.g. {toolName: "getWeather", type: "tool"}
|
|
1449
|
+
*/
|
|
1450
|
+
toolChoice?: ToolChoice<TOOLS extends undefined ? AgentTools : TOOLS>;
|
|
1451
|
+
// Non-AI SDK args
|
|
1452
|
+
/**
|
|
1453
|
+
* The parent message id to use for the tool calls.
|
|
1454
|
+
*/
|
|
1455
|
+
parentMessageId?: string;
|
|
1456
|
+
/**
|
|
1457
|
+
* The context options to use for passing in message history to the LLM.
|
|
1458
|
+
*/
|
|
1459
|
+
contextOptions?: ContextOptions;
|
|
1460
|
+
/**
|
|
1461
|
+
* The storage options to use for saving the input and output messages to the thread.
|
|
1462
|
+
*/
|
|
1463
|
+
storageOptions?: StorageOptions;
|
|
1328
1464
|
} & ContextOptions &
|
|
1329
1465
|
StorageOptions;
|
|
1330
1466
|
|
|
1331
1467
|
type BaseGenerateObjectOptions = StorageOptions &
|
|
1332
1468
|
ContextOptions &
|
|
1333
1469
|
CallSettings & {
|
|
1470
|
+
/**
|
|
1471
|
+
* The model to use for the object generation. This will override the model
|
|
1472
|
+
* specified in the Agent constructor.
|
|
1473
|
+
*/
|
|
1334
1474
|
model?: LanguageModelV1;
|
|
1335
|
-
|
|
1475
|
+
/**
|
|
1476
|
+
* The system prompt to use for the object generation. This will override the
|
|
1477
|
+
* system prompt specified in the Agent constructor.
|
|
1478
|
+
*/
|
|
1336
1479
|
system?: string;
|
|
1480
|
+
/**
|
|
1481
|
+
* The prompt to the LLM to use for the object generation.
|
|
1482
|
+
* Specify this or messages, but not both.
|
|
1483
|
+
*/
|
|
1337
1484
|
prompt?: string;
|
|
1485
|
+
/**
|
|
1486
|
+
* The messages to use for the object generation.
|
|
1487
|
+
* Note: recent messages are automatically added based on the thread it's
|
|
1488
|
+
* associated with and your contextOptions.
|
|
1489
|
+
*/
|
|
1338
1490
|
messages?: CoreMessage[];
|
|
1339
1491
|
experimental_repairText?: RepairTextFunction;
|
|
1340
1492
|
experimental_telemetry?: TelemetrySettings;
|
|
1341
1493
|
providerOptions?: ProviderOptions;
|
|
1342
1494
|
experimental_providerMetadata?: ProviderMetadata;
|
|
1495
|
+
// Non-AI SDK args
|
|
1496
|
+
/**
|
|
1497
|
+
* The parent message id to use for the object generation.
|
|
1498
|
+
*/
|
|
1499
|
+
parentMessageId?: string;
|
|
1500
|
+
/**
|
|
1501
|
+
* The context options to use for passing in message history to the LLM.
|
|
1502
|
+
*/
|
|
1503
|
+
contextOptions?: ContextOptions;
|
|
1504
|
+
/**
|
|
1505
|
+
* The storage options to use for saving the input and output messages to the thread.
|
|
1506
|
+
*/
|
|
1507
|
+
storageOptions?: StorageOptions;
|
|
1343
1508
|
};
|
|
1344
1509
|
|
|
1345
1510
|
type GenerateObjectObjectOptions<T extends Record<string, unknown>> =
|
|
@@ -1404,7 +1569,7 @@ type ThreadOutputMetadata = GenerationOutputMetadata & {
|
|
|
1404
1569
|
messageId: string;
|
|
1405
1570
|
};
|
|
1406
1571
|
|
|
1407
|
-
interface Thread<
|
|
1572
|
+
interface Thread<DefaultTools extends ToolSet> {
|
|
1408
1573
|
/**
|
|
1409
1574
|
* The target threadId, from the startThread or continueThread initializers.
|
|
1410
1575
|
*/
|
|
@@ -1419,14 +1584,20 @@ interface Thread<AgentTools extends ToolSet> {
|
|
|
1419
1584
|
* for the {@link ContextOptions} and {@link StorageOptions}.
|
|
1420
1585
|
* @returns The result of the generateText function.
|
|
1421
1586
|
*/
|
|
1422
|
-
generateText<
|
|
1587
|
+
generateText<
|
|
1588
|
+
TOOLS extends ToolSet | undefined = undefined,
|
|
1589
|
+
OUTPUT = never,
|
|
1590
|
+
OUTPUT_PARTIAL = never,
|
|
1591
|
+
>(
|
|
1423
1592
|
args: TextArgs<
|
|
1424
|
-
|
|
1593
|
+
TOOLS extends undefined ? DefaultTools : TOOLS,
|
|
1425
1594
|
TOOLS,
|
|
1426
|
-
|
|
1595
|
+
OUTPUT,
|
|
1596
|
+
OUTPUT_PARTIAL
|
|
1427
1597
|
>
|
|
1428
1598
|
): Promise<
|
|
1429
|
-
GenerateTextResult<TOOLS
|
|
1599
|
+
GenerateTextResult<TOOLS extends undefined ? DefaultTools : TOOLS, OUTPUT> &
|
|
1600
|
+
ThreadOutputMetadata
|
|
1430
1601
|
>;
|
|
1431
1602
|
|
|
1432
1603
|
/**
|
|
@@ -1439,14 +1610,23 @@ interface Thread<AgentTools extends ToolSet> {
|
|
|
1439
1610
|
* for the {@link ContextOptions} and {@link StorageOptions}.
|
|
1440
1611
|
* @returns The result of the streamText function.
|
|
1441
1612
|
*/
|
|
1442
|
-
streamText<
|
|
1443
|
-
|
|
1444
|
-
|
|
1613
|
+
streamText<
|
|
1614
|
+
TOOLS extends ToolSet | undefined = undefined,
|
|
1615
|
+
OUTPUT = never,
|
|
1616
|
+
PARTIAL_OUTPUT = never,
|
|
1617
|
+
>(
|
|
1618
|
+
args: StreamingTextArgs<
|
|
1619
|
+
TOOLS extends undefined ? DefaultTools : TOOLS,
|
|
1445
1620
|
TOOLS,
|
|
1446
|
-
|
|
1621
|
+
OUTPUT,
|
|
1622
|
+
PARTIAL_OUTPUT
|
|
1447
1623
|
>
|
|
1448
1624
|
): Promise<
|
|
1449
|
-
StreamTextResult<
|
|
1625
|
+
StreamTextResult<
|
|
1626
|
+
TOOLS extends undefined ? DefaultTools : TOOLS,
|
|
1627
|
+
PARTIAL_OUTPUT
|
|
1628
|
+
> &
|
|
1629
|
+
ThreadOutputMetadata
|
|
1450
1630
|
>;
|
|
1451
1631
|
/**
|
|
1452
1632
|
* This behaves like {@link generateObject} from the "ai" package except that
|