@convex-dev/agent 0.0.11-alpha.2 → 0.0.12
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 +34 -25
- package/dist/commonjs/client/index.d.ts +173 -967
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +29 -81
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/messages.js +1 -1
- package/dist/commonjs/component/messages.js.map +1 -1
- package/dist/commonjs/validators.d.ts +156 -2476
- package/dist/commonjs/validators.d.ts.map +1 -1
- package/dist/commonjs/validators.js +12 -31
- package/dist/commonjs/validators.js.map +1 -1
- package/dist/esm/client/index.d.ts +173 -967
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +29 -81
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/messages.js +1 -1
- package/dist/esm/component/messages.js.map +1 -1
- package/dist/esm/validators.d.ts +156 -2476
- package/dist/esm/validators.d.ts.map +1 -1
- package/dist/esm/validators.js +12 -31
- package/dist/esm/validators.js.map +1 -1
- package/package.json +1 -1
- package/src/client/index.ts +39 -83
- package/src/component/messages.ts +1 -1
- package/src/validators.ts +13 -43
package/README.md
CHANGED
|
@@ -52,21 +52,22 @@ export const continueThread = action({
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
// Or use it within a workflow, specific to a user:
|
|
55
|
-
export const
|
|
55
|
+
export const { generateText: getSupport } = supportAgent.asActions({ maxSteps: 10 });
|
|
56
56
|
|
|
57
57
|
const workflow = new WorkflowManager(components.workflow);
|
|
58
|
-
const s = internal.example; // where steps are defined
|
|
59
58
|
|
|
60
59
|
export const supportAgentWorkflow = workflow.define({
|
|
61
60
|
args: { prompt: v.string(), userId: v.string(), threadId: v.string() },
|
|
62
61
|
handler: async (step, { prompt, userId, threadId }) => {
|
|
63
|
-
const suggestion = await step.runAction(
|
|
64
|
-
threadId,
|
|
62
|
+
const suggestion = await step.runAction(internal.example.getSupport, {
|
|
63
|
+
threadId, userId, prompt,
|
|
65
64
|
});
|
|
66
|
-
const polished = await step.runAction(
|
|
67
|
-
|
|
65
|
+
const polished = await step.runAction(internal.example.adaptSuggestionForUser, {
|
|
66
|
+
userId, suggestion,
|
|
67
|
+
});
|
|
68
|
+
await step.runMutation(internal.example.sendUserMessage, {
|
|
69
|
+
userId, message: polished.message,
|
|
68
70
|
});
|
|
69
|
-
await step.runMutation(s.sendUserMessage, { userId, message: polished.message });
|
|
70
71
|
},
|
|
71
72
|
});
|
|
72
73
|
```
|
|
@@ -216,45 +217,53 @@ export const continueThread = action({
|
|
|
216
217
|
|
|
217
218
|
### Exposing the agent as a Convex action
|
|
218
219
|
|
|
220
|
+
You can expose the agent as a Convex internal action.
|
|
221
|
+
This is generally used from a workflow, where each step is a new thread message.
|
|
222
|
+
|
|
219
223
|
```ts
|
|
220
|
-
export const
|
|
224
|
+
export const getSupport = supportAgent.asTextAction({
|
|
225
|
+
maxSteps: 10,
|
|
226
|
+
});
|
|
227
|
+
```
|
|
221
228
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
})
|
|
229
|
-
},
|
|
229
|
+
You can also expose an action that generates an object.
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
export const getStructuredSupport = supportAgent.asObjectAction({
|
|
233
|
+
schema: z.object({
|
|
234
|
+
analysis: z.string().describe("A detailed analysis of the user's request."),
|
|
235
|
+
suggestion: z.string().describe("A suggested action to take.")}),
|
|
230
236
|
});
|
|
231
237
|
```
|
|
232
238
|
|
|
233
|
-
### Using the agent within a workflow
|
|
239
|
+
### Using the agent actions within a workflow
|
|
234
240
|
|
|
235
241
|
You can use the [Workflow component](https://convex.dev/components/workflow)
|
|
236
|
-
to run
|
|
237
|
-
and more. Read more about durable workflows
|
|
242
|
+
to run agent flows. It handles retries and guarantees of eventually completing,
|
|
243
|
+
surviving server restarts, and more. Read more about durable workflows
|
|
238
244
|
[in this Stack post](https://stack.convex.dev/durable-workflows-and-strong-guarantees).
|
|
239
245
|
|
|
240
246
|
```ts
|
|
241
247
|
const workflow = new WorkflowManager(components.workflow);
|
|
242
|
-
const s = internal.example; // where steps are defined
|
|
243
248
|
|
|
244
249
|
export const supportAgentWorkflow = workflow.define({
|
|
245
250
|
args: { prompt: v.string(), userId: v.string(), threadId: v.string() },
|
|
246
251
|
handler: async (step, { prompt, userId, threadId }) => {
|
|
247
|
-
const suggestion = await step.runAction(
|
|
248
|
-
threadId, userId,
|
|
252
|
+
const suggestion = await step.runAction(internal.example.getSupport, {
|
|
253
|
+
threadId, userId, prompt,
|
|
254
|
+
});
|
|
255
|
+
const polished = await step.runAction(internal.example.adaptSuggestionForUser, {
|
|
256
|
+
userId, suggestion,
|
|
249
257
|
});
|
|
250
|
-
|
|
251
|
-
|
|
258
|
+
await step.runMutation(internal.example.sendUserMessage, {
|
|
259
|
+
userId, message: polished.message,
|
|
252
260
|
});
|
|
253
|
-
await step.runMutation(s.sendUserMessage, { userId, message: polished.message });
|
|
254
261
|
},
|
|
255
262
|
});
|
|
256
263
|
```
|
|
257
264
|
|
|
265
|
+
See another example in [example.ts](./example/convex/example.ts#L120).
|
|
266
|
+
|
|
258
267
|
### Fetching thread history
|
|
259
268
|
|
|
260
269
|
```ts
|