@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.
Files changed (49) hide show
  1. package/README.md +25 -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 -2
  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
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 a Convex internal action.
408
- 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`:
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
- Create a thread from within a workflow, similar to agent.createThread.
441
+ To save messages explicitly as a mutation, similar to `agent.saveMessages`:
428
442
 
429
443
  ```ts
430
- export const createThread = supportAgent.createThreadMutation();
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 polished = await step.runAction(internal.example.adaptSuggestionForUser, {
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: polished.message,
474
+ userId, message: object.suggestion,
457
475
  });
458
476
  },
459
477
  });