@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.
Files changed (58) hide show
  1. package/README.md +35 -7
  2. package/dist/commonjs/client/index.d.ts +229 -756
  3. package/dist/commonjs/client/index.d.ts.map +1 -1
  4. package/dist/commonjs/client/index.js +135 -140
  5. package/dist/commonjs/client/index.js.map +1 -1
  6. package/dist/commonjs/component/messages.d.ts +208 -896
  7. package/dist/commonjs/component/messages.d.ts.map +1 -1
  8. package/dist/commonjs/component/messages.js +117 -109
  9. package/dist/commonjs/component/messages.js.map +1 -1
  10. package/dist/commonjs/component/schema.d.ts +1278 -580
  11. package/dist/commonjs/component/schema.d.ts.map +1 -1
  12. package/dist/commonjs/component/schema.js +28 -21
  13. package/dist/commonjs/component/schema.js.map +1 -1
  14. package/dist/commonjs/component/users.d.ts +5 -2
  15. package/dist/commonjs/component/users.d.ts.map +1 -1
  16. package/dist/commonjs/component/users.js +57 -27
  17. package/dist/commonjs/component/users.js.map +1 -1
  18. package/dist/commonjs/validators.d.ts +44 -59
  19. package/dist/commonjs/validators.d.ts.map +1 -1
  20. package/dist/commonjs/validators.js +10 -12
  21. package/dist/commonjs/validators.js.map +1 -1
  22. package/dist/esm/client/index.d.ts +229 -756
  23. package/dist/esm/client/index.d.ts.map +1 -1
  24. package/dist/esm/client/index.js +135 -140
  25. package/dist/esm/client/index.js.map +1 -1
  26. package/dist/esm/component/messages.d.ts +208 -896
  27. package/dist/esm/component/messages.d.ts.map +1 -1
  28. package/dist/esm/component/messages.js +117 -109
  29. package/dist/esm/component/messages.js.map +1 -1
  30. package/dist/esm/component/schema.d.ts +1278 -580
  31. package/dist/esm/component/schema.d.ts.map +1 -1
  32. package/dist/esm/component/schema.js +28 -21
  33. package/dist/esm/component/schema.js.map +1 -1
  34. package/dist/esm/component/users.d.ts +5 -2
  35. package/dist/esm/component/users.d.ts.map +1 -1
  36. package/dist/esm/component/users.js +57 -27
  37. package/dist/esm/component/users.js.map +1 -1
  38. package/dist/esm/validators.d.ts +44 -59
  39. package/dist/esm/validators.d.ts.map +1 -1
  40. package/dist/esm/validators.js +10 -12
  41. package/dist/esm/validators.js.map +1 -1
  42. package/package.json +2 -9
  43. package/src/client/index.ts +215 -199
  44. package/src/component/_generated/api.d.ts +19 -94
  45. package/src/component/messages.test.ts +110 -3
  46. package/src/component/messages.ts +176 -154
  47. package/src/component/schema.ts +34 -21
  48. package/src/component/users.ts +57 -32
  49. package/src/validators.ts +12 -15
  50. package/dist/commonjs/client/playground.d.ts +0 -609
  51. package/dist/commonjs/client/playground.d.ts.map +0 -1
  52. package/dist/commonjs/client/playground.js +0 -200
  53. package/dist/commonjs/client/playground.js.map +0 -1
  54. package/dist/esm/client/playground.d.ts +0 -609
  55. package/dist/esm/client/playground.d.ts.map +0 -1
  56. package/dist/esm/client/playground.js +0 -200
  57. package/dist/esm/client/playground.js.map +0 -1
  58. 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 a Convex internal action.
398
- This is generally used from a workflow, where each step is a new thread message.
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
- Create a thread from within a workflow, similar to agent.createThread.
441
+ To save messages explicitly as a mutation, similar to `agent.saveMessages`:
418
442
 
419
443
  ```ts
420
- export const createThread = supportAgent.createThreadMutation();
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 polished = await step.runAction(internal.example.adaptSuggestionForUser, {
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: polished.message,
474
+ userId, message: object.suggestion,
447
475
  });
448
476
  },
449
477
  });