@convex-dev/agent 0.0.17-alpha.2 → 0.1.0-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 +25 -7
- package/dist/commonjs/client/index.d.ts +229 -756
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +135 -140
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/messages.d.ts +208 -896
- package/dist/commonjs/component/messages.d.ts.map +1 -1
- package/dist/commonjs/component/messages.js +117 -109
- package/dist/commonjs/component/messages.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +1278 -580
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +28 -21
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/commonjs/component/users.d.ts +5 -2
- package/dist/commonjs/component/users.d.ts.map +1 -1
- package/dist/commonjs/component/users.js +57 -27
- package/dist/commonjs/component/users.js.map +1 -1
- package/dist/commonjs/validators.d.ts +44 -59
- package/dist/commonjs/validators.d.ts.map +1 -1
- package/dist/commonjs/validators.js +10 -12
- package/dist/commonjs/validators.js.map +1 -1
- package/dist/esm/client/index.d.ts +229 -756
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +135 -140
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/messages.d.ts +208 -896
- package/dist/esm/component/messages.d.ts.map +1 -1
- package/dist/esm/component/messages.js +117 -109
- package/dist/esm/component/messages.js.map +1 -1
- package/dist/esm/component/schema.d.ts +1278 -580
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +28 -21
- package/dist/esm/component/schema.js.map +1 -1
- package/dist/esm/component/users.d.ts +5 -2
- package/dist/esm/component/users.d.ts.map +1 -1
- package/dist/esm/component/users.js +57 -27
- package/dist/esm/component/users.js.map +1 -1
- package/dist/esm/validators.d.ts +44 -59
- package/dist/esm/validators.d.ts.map +1 -1
- package/dist/esm/validators.js +10 -12
- package/dist/esm/validators.js.map +1 -1
- package/package.json +2 -2
- package/src/client/index.ts +215 -199
- package/src/component/_generated/api.d.ts +19 -94
- package/src/component/messages.test.ts +110 -3
- package/src/component/messages.ts +176 -154
- package/src/component/schema.ts +34 -21
- package/src/component/users.ts +57 -32
- package/src/validators.ts +12 -15
package/README.md
CHANGED
|
@@ -401,11 +401,25 @@ The [Workflow component](https://convex.dev/components/workflow) is a great way
|
|
|
401
401
|
It handles retries and guarantees of eventually completing, surviving server restarts, and more.
|
|
402
402
|
Read more about durable workflows in [this Stack post](https://stack.convex.dev/durable-workflows-and-strong-guarantees).
|
|
403
403
|
|
|
404
|
+
To use the agent alongside workflows, you can run indivdual idempotent steps
|
|
405
|
+
that the workflow can run, each with configurable retries, with guarantees that
|
|
406
|
+
the workflow will eventually complete. Even if the server crashes mid-workflow,
|
|
407
|
+
the workflow will pick up from where it left off and run the next step. If a
|
|
408
|
+
step fails and isn't caught by the workflow, the workflow's onComplete handler
|
|
409
|
+
will get the error result.
|
|
404
410
|
|
|
405
411
|
### Exposing the agent as Convex actions
|
|
406
412
|
|
|
407
|
-
You can expose the agent as
|
|
408
|
-
|
|
413
|
+
You can expose the agent's capabilities as Convex functions to be used as steps
|
|
414
|
+
in a workflow.
|
|
415
|
+
|
|
416
|
+
To create a thread as a standalone mutation, similar to `agent.createThread`:
|
|
417
|
+
|
|
418
|
+
```ts
|
|
419
|
+
export const createThread = supportAgent.createThreadMutation();
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
For an action that generates text in a thread, similar to `thread.generateText`:
|
|
409
423
|
|
|
410
424
|
```ts
|
|
411
425
|
export const getSupport = supportAgent.asTextAction({
|
|
@@ -424,12 +438,16 @@ export const getStructuredSupport = supportAgent.asObjectAction({
|
|
|
424
438
|
});
|
|
425
439
|
```
|
|
426
440
|
|
|
427
|
-
|
|
441
|
+
To save messages explicitly as a mutation, similar to `agent.saveMessages`:
|
|
428
442
|
|
|
429
443
|
```ts
|
|
430
|
-
export const
|
|
444
|
+
export const saveMessages = supportAgent.asSaveMessagesMutation();
|
|
431
445
|
```
|
|
432
446
|
|
|
447
|
+
This is useful for idempotency, as you can first create the user's message,
|
|
448
|
+
then generate a response in an unreliable action with retries, passing in the
|
|
449
|
+
existing messageId instead of a prompt.
|
|
450
|
+
|
|
433
451
|
### Using the agent actions within a workflow
|
|
434
452
|
|
|
435
453
|
You can use the [Workflow component](https://convex.dev/components/workflow)
|
|
@@ -449,11 +467,11 @@ export const supportAgentWorkflow = workflow.define({
|
|
|
449
467
|
const suggestion = await step.runAction(internal.example.getSupport, {
|
|
450
468
|
threadId, userId, prompt,
|
|
451
469
|
});
|
|
452
|
-
const
|
|
453
|
-
userId, suggestion,
|
|
470
|
+
const { object } = await step.runAction(internal.example.getStructuredSupport, {
|
|
471
|
+
userId, message: suggestion,
|
|
454
472
|
});
|
|
455
473
|
await step.runMutation(internal.example.sendUserMessage, {
|
|
456
|
-
userId, message:
|
|
474
|
+
userId, message: object.suggestion,
|
|
457
475
|
});
|
|
458
476
|
},
|
|
459
477
|
});
|