Skip to content

Commit ea42dcd

Browse files
committed
multi-agent example and optional asAction arg
1 parent efa8417 commit ea42dcd

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

example/convex/example.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ const supportAgent = new Agent(components.agent, {
1212
instructions: "You are a helpful assistant.",
1313
});
1414

15+
const wordsmithAgent = new Agent(components.agent, {
16+
thread: openai.chat("gpt-4o-mini"),
17+
textEmbedding: openai.embedding("text-embedding-3-small"),
18+
instructions: "You output a spiffy quirky version of what the user says.",
19+
});
20+
1521
// Use the agent from within a normal action:
1622
export const createThread = action({
1723
args: { prompt: v.string(), userId: v.optional(v.string()) },
@@ -36,22 +42,26 @@ export const continueThread = action({
3642

3743
// Or use it within a workflow:
3844
export const supportAgentStep = supportAgent.asAction({ maxSteps: 10 });
45+
export const wordsmithAgentStep = wordsmithAgent.asAction();
3946

4047
const workflow = new WorkflowManager(components.workflow);
4148
const s = internal.example; // where steps are defined
4249

4350
export const supportAgentWorkflow = workflow.define({
4451
args: { prompt: v.string() },
45-
handler: async (step, { prompt }) => {
52+
handler: async (step, { prompt }): Promise<string> => {
4653
const { threadId } = await step.runAction(s.supportAgentStep, {
4754
createThread: {},
4855
});
49-
const result = await step.runAction(s.supportAgentStep, {
56+
const roughSuggestion = await step.runAction(s.supportAgentStep, {
5057
threadId,
5158
generateText: { prompt },
5259
});
53-
console.log(result);
54-
// Call other agents here
60+
const wordsmithSuggestion = await step.runAction(s.wordsmithAgentStep, {
61+
generateText: { prompt: roughSuggestion },
62+
});
63+
console.log(wordsmithSuggestion);
64+
return wordsmithSuggestion;
5565
},
5666
});
5767

src/client/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ export class Agent<AgentTools extends ToolSet> {
717717
/**
718718
*
719719
*/
720-
asAction(spec: { contextOptions?: ContextOptions; maxSteps?: number }) {
720+
asAction(spec?: { contextOptions?: ContextOptions; maxSteps?: number }) {
721721
return internalActionGeneric({
722722
args: {
723723
userId: v.optional(v.string()),
@@ -750,8 +750,9 @@ export class Agent<AgentTools extends ToolSet> {
750750
// eslint-disable-next-line @typescript-eslint/no-explicit-any
751751
handler: async (ctx, args): Promise<any> => {
752752
const contextOptions =
753-
spec.contextOptions && this.mergedContextOptions(spec.contextOptions);
754-
const maxSteps = spec.maxSteps ?? this.options.maxSteps;
753+
spec?.contextOptions &&
754+
this.mergedContextOptions(spec.contextOptions);
755+
const maxSteps = spec?.maxSteps ?? this.options.maxSteps;
755756
const maxRetries = args.maxRetries;
756757
const commonArgs = {
757758
userId: args.userId,

0 commit comments

Comments
 (0)