Skip to content

Commit 0657976

Browse files
authored
Merge pull request #10 from get-convex/ian/fix-api
Ian/fix api
2 parents ef73105 + e7f948e commit 0657976

File tree

12 files changed

+484
-235
lines changed

12 files changed

+484
-235
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ AI Agent framework built on Convex.
1010
- RAG for chat context, via hybrid text & vector search, with configuration options.
1111
Or use the API to query the history yourself and do it your way.
1212
- Opt-in search for messages from other threads (for the same specified user).
13+
- Support for generating and storing objects in messages (as JSON).
1314
- Tool calls via the AI SDK, along with Convex-specific helpers.
1415
- Easy workflow integration with the [Workflow component](https://convex.dev/components/workflow).
1516
- Reactive & realtime updates to asynchronous threads.

example/convex/_generated/api.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export declare const components: {
179179
| string
180180
| string
181181
| string;
182+
error?: string;
182183
fileId?: string;
183184
id?: string;
184185
message?:
@@ -303,6 +304,7 @@ export declare const components: {
303304
| string
304305
| string
305306
| string;
307+
error?: string;
306308
fileId?: string;
307309
id?: string;
308310
message?:
@@ -1096,6 +1098,7 @@ export declare const components: {
10961098
| string
10971099
| string
10981100
| string;
1101+
error?: string;
10991102
fileId?: string;
11001103
id?: string;
11011104
message?:
@@ -1268,6 +1271,7 @@ export declare const components: {
12681271
| string
12691272
| string
12701273
| string;
1274+
error?: string;
12711275
fileId?: string;
12721276
id?: string;
12731277
message?:
@@ -1397,6 +1401,7 @@ export declare const components: {
13971401
| string
13981402
| string
13991403
| string;
1404+
error?: string;
14001405
fileId?: string;
14011406
id?: string;
14021407
message?:

example/convex/example.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import { components, internal } from "./_generated/api";
44
import { openai } from "@ai-sdk/openai";
55
import { action, query } from "./_generated/server";
66
import { v } from "convex/values";
7+
import { z } from "zod";
78

89
// Define an agent similarly to the AI SDK
910
const supportAgent = new Agent(components.agent, {
10-
thread: openai.chat("gpt-4o-mini"),
11+
chat: openai.chat("gpt-4o-mini"),
1112
textEmbedding: openai.embedding("text-embedding-3-small"),
1213
instructions: "You are a helpful assistant.",
1314
});
1415

1516
const wordsmithAgent = new Agent(components.agent, {
16-
thread: openai.chat("gpt-4o-mini"),
17+
chat: openai.chat("gpt-4o-mini"),
1718
textEmbedding: openai.embedding("text-embedding-3-small"),
1819
instructions: "You output a spiffy quirky version of what the user says.",
1920
});
@@ -117,3 +118,19 @@ export const searchMessages = action({
117118
});
118119
},
119120
});
121+
122+
export const generateObject = action({
123+
args: { prompt: v.string() },
124+
handler: async (ctx, { prompt }) => {
125+
const { threadId, thread } = await supportAgent.createThread(ctx, {});
126+
const result = await thread.streamObject({
127+
output: "object",
128+
schema: z.object({
129+
name: z.string(),
130+
age: z.number(),
131+
}),
132+
prompt,
133+
});
134+
return { threadId, object: result.object };
135+
},
136+
});

example/convex/ideaAgents.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const attachEntryToIdea = createTool({
7575

7676
const ideaManagerAgent = new Agent(components.agent, {
7777
name: "Idea Manager Agent",
78-
thread: openai.chat("gpt-4o"), // Fancier model for discerning between ideas
78+
chat: openai.chat("gpt-4o"), // Fancier model for discerning between ideas
7979
textEmbedding: openai.embedding("text-embedding-3-small"),
8080
instructions:
8181
"You are a helpful assistant that helps manage ideas. " +
@@ -96,7 +96,7 @@ const ideaManagerAgent = new Agent(components.agent, {
9696

9797
const ideaDevelopmentAgent = new Agent(components.agent, {
9898
name: "Idea Development Agent",
99-
thread: openai.chat("gpt-4o-mini"),
99+
chat: openai.chat("gpt-4o-mini"),
100100
textEmbedding: openai.embedding("text-embedding-3-small"),
101101
instructions:
102102
"You are a helpful assistant that helps develop ideas. " +
@@ -145,13 +145,22 @@ const ideaDeveloper = ideaDevelopmentAgent.asTool({
145145
maxSteps: 5,
146146
});
147147

148+
/**
149+
* AGENTS AS STANDALONE ACTIONS
150+
*/
151+
152+
export const ideaManagerAction = ideaManagerAgent.asAction();
153+
export const ideaDeveloperAction = ideaDevelopmentAgent.asAction({
154+
maxSteps: 5,
155+
});
156+
148157
/**
149158
* AGENT DISPATCHERS
150159
*/
151160

152161
const ideaTriageAgent = new Agent(components.agent, {
153162
name: "Idea Triage Agent",
154-
thread: openai.chat("gpt-4o-mini"),
163+
chat: openai.chat("gpt-4o-mini"),
155164
textEmbedding: openai.embedding("text-embedding-3-small"),
156165
instructions:
157166
"You are a helpful assistant that helps triage ideas. " +

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.1",
10+
"version": "0.0.3",
1111
"license": "Apache-2.0",
1212
"keywords": [
1313
"convex",

0 commit comments

Comments
 (0)