Skip to content

Commit aaacf8c

Browse files
committed
Merge tag 'v0.0.5'
0.0.5
2 parents 5f6f280 + 9f52478 commit aaacf8c

File tree

3 files changed

+40
-24
lines changed

3 files changed

+40
-24
lines changed

example/convex/example.ts

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -245,48 +245,64 @@ export const generateObject = action({
245245
},
246246
});
247247

248-
export const t = action({
248+
export const runAgentAsTool = action({
249249
args: {},
250250
handler: async (ctx) => {
251-
const fastAgent = new Agent(components.agent, {
251+
const agentWithTools = new Agent(components.agent, {
252252
chat: openai.chat("gpt-4o-mini"),
253253
textEmbedding: openai.embedding("text-embedding-3-small"),
254254
instructions: "You are a helpful assistant.",
255255
tools: {
256256
doSomething: tool({
257257
description: "Call this function when asked to do something",
258258
parameters: z.object({}),
259-
execute: async (args) => {
260-
console.log("doSomething", args);
259+
execute: async (args, options) => {
260+
console.log("doingSomething", options.toolCallId);
261261
return "hello";
262262
},
263263
}),
264264
doSomethingElse: tool({
265265
description: "Call this function when asked to do something else",
266266
parameters: z.object({}),
267-
execute: async (args) => {
268-
console.log("doSomethingElse", args);
267+
execute: async (args, options) => {
268+
console.log("doSomethingElse", options.toolCallId);
269269
return "hello";
270270
},
271271
}),
272272
},
273273
maxSteps: 20,
274274
});
275-
276-
// // eslint-disable-next-line @typescript-eslint/no-floating-promises
277-
await Promise.all(
278-
Array.from({ length: 10 }).map(async (i) => {
279-
const { threadId, thread } = await fastAgent.createThread(ctx, {
280-
userId: "123",
281-
});
282-
const s = await thread.streamText({
283-
prompt: "Do something twice",
284-
});
285-
console.log("agent", i);
286-
await s.response;
275+
const agentWithToolsAsTool = agentWithTools.asTool({
276+
description:
277+
"agentWithTools which can either doSomething or doSomethingElse",
278+
args: v.object({
279+
whatToDo: v.union(
280+
v.literal("doSomething"),
281+
v.literal("doSomethingElse"),
282+
),
287283
}),
288-
);
289-
console.log("done");
290-
// return result.text;
284+
});
285+
const dispatchAgent = new Agent(components.agent, {
286+
chat: openai.chat("gpt-4o-mini"),
287+
textEmbedding: openai.embedding("text-embedding-3-small"),
288+
instructions:
289+
"You can call agentWithToolsAsTool as many times as told with the argument whatToDo.",
290+
tools: { agentWithToolsAsTool },
291+
maxSteps: 5,
292+
});
293+
294+
const { thread } = await dispatchAgent.createThread(ctx);
295+
console.time("overall");
296+
const result = await thread.generateText({
297+
messages: [
298+
{
299+
role: "user",
300+
content:
301+
"Call fastAgent with whatToDo set to doSomething three times and doSomethingElse one time",
302+
},
303+
],
304+
});
305+
console.timeEnd("overall");
306+
return result.text;
291307
},
292308
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"email": "support@convex.dev",
88
"url": "https://github.com/get-convex/agent/issues"
99
},
10-
"version": "0.0.5-alpha.1",
10+
"version": "0.0.5",
1111
"license": "Apache-2.0",
1212
"keywords": [
1313
"convex",

0 commit comments

Comments
 (0)