@convex-dev/agent 0.0.17-alpha.0 → 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 +35 -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 -9
- 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/dist/commonjs/client/playground.d.ts +0 -609
- package/dist/commonjs/client/playground.d.ts.map +0 -1
- package/dist/commonjs/client/playground.js +0 -200
- package/dist/commonjs/client/playground.js.map +0 -1
- package/dist/esm/client/playground.d.ts +0 -609
- package/dist/esm/client/playground.d.ts.map +0 -1
- package/dist/esm/client/playground.js +0 -200
- package/dist/esm/client/playground.js.map +0 -1
- package/src/client/playground.ts +0 -257
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
AI Agent framework built on Convex.
|
|
8
8
|
|
|
9
9
|
- Automatic storage of chat history, per-user or per-thread, that can span multiple agents.
|
|
10
|
+
- Playground UI for testing, debugging, and development. See [playground/README.md](playground/README.md) for more.
|
|
10
11
|
- RAG for chat context, via hybrid text & vector search, with configuration options.
|
|
11
12
|
Use the API to query the history yourself and do it your way.
|
|
12
13
|
- Opt-in search for messages from other threads (for the same specified user).
|
|
@@ -385,17 +386,40 @@ await ctx.runMutation(components.agent.threads.updateThread, {
|
|
|
385
386
|
});
|
|
386
387
|
```
|
|
387
388
|
|
|
389
|
+
## Using the Playground UI
|
|
390
|
+
|
|
391
|
+
The Playground UI is a simple way to test, debug, and develop with the agent.
|
|
392
|
+
- First configure it with instructions [here](./playground/README.md).
|
|
393
|
+
- Then you can use the [hosted version on GitHub pages](https://get-convex.github.io/agent/)
|
|
394
|
+
or run it locally with `npx @convex-dev/agent-playground`.
|
|
395
|
+
|
|
396
|
+
[Playground UI Screenshot](./playground/screenshot.png)
|
|
397
|
+
|
|
388
398
|
## Using the Workflow component for long-lived durable workflows
|
|
389
399
|
|
|
390
400
|
The [Workflow component](https://convex.dev/components/workflow) is a great way to build long-lived, durable workflows.
|
|
391
401
|
It handles retries and guarantees of eventually completing, surviving server restarts, and more.
|
|
392
402
|
Read more about durable workflows in [this Stack post](https://stack.convex.dev/durable-workflows-and-strong-guarantees).
|
|
393
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.
|
|
394
410
|
|
|
395
411
|
### Exposing the agent as Convex actions
|
|
396
412
|
|
|
397
|
-
You can expose the agent as
|
|
398
|
-
|
|
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`:
|
|
399
423
|
|
|
400
424
|
```ts
|
|
401
425
|
export const getSupport = supportAgent.asTextAction({
|
|
@@ -414,12 +438,16 @@ export const getStructuredSupport = supportAgent.asObjectAction({
|
|
|
414
438
|
});
|
|
415
439
|
```
|
|
416
440
|
|
|
417
|
-
|
|
441
|
+
To save messages explicitly as a mutation, similar to `agent.saveMessages`:
|
|
418
442
|
|
|
419
443
|
```ts
|
|
420
|
-
export const
|
|
444
|
+
export const saveMessages = supportAgent.asSaveMessagesMutation();
|
|
421
445
|
```
|
|
422
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
|
+
|
|
423
451
|
### Using the agent actions within a workflow
|
|
424
452
|
|
|
425
453
|
You can use the [Workflow component](https://convex.dev/components/workflow)
|
|
@@ -439,11 +467,11 @@ export const supportAgentWorkflow = workflow.define({
|
|
|
439
467
|
const suggestion = await step.runAction(internal.example.getSupport, {
|
|
440
468
|
threadId, userId, prompt,
|
|
441
469
|
});
|
|
442
|
-
const
|
|
443
|
-
userId, suggestion,
|
|
470
|
+
const { object } = await step.runAction(internal.example.getStructuredSupport, {
|
|
471
|
+
userId, message: suggestion,
|
|
444
472
|
});
|
|
445
473
|
await step.runMutation(internal.example.sendUserMessage, {
|
|
446
|
-
userId, message:
|
|
474
|
+
userId, message: object.suggestion,
|
|
447
475
|
});
|
|
448
476
|
},
|
|
449
477
|
});
|