@convex-dev/agent 0.0.1-alpha.4 → 0.0.2

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 (66) hide show
  1. package/README.md +35 -7
  2. package/dist/commonjs/client/index.d.ts +800 -84
  3. package/dist/commonjs/client/index.d.ts.map +1 -1
  4. package/dist/commonjs/client/index.js +176 -130
  5. package/dist/commonjs/client/index.js.map +1 -1
  6. package/dist/commonjs/component/messages.d.ts +124 -105
  7. package/dist/commonjs/component/messages.d.ts.map +1 -1
  8. package/dist/commonjs/component/messages.js +145 -247
  9. package/dist/commonjs/component/messages.js.map +1 -1
  10. package/dist/commonjs/component/schema.d.ts +822 -746
  11. package/dist/commonjs/component/schema.d.ts.map +1 -1
  12. package/dist/commonjs/component/schema.js +13 -3
  13. package/dist/commonjs/component/schema.js.map +1 -1
  14. package/dist/commonjs/component/vector/index.d.ts +21 -6
  15. package/dist/commonjs/component/vector/index.d.ts.map +1 -1
  16. package/dist/commonjs/component/vector/index.js +32 -20
  17. package/dist/commonjs/component/vector/index.js.map +1 -1
  18. package/dist/commonjs/component/vector/tables.d.ts +25 -5
  19. package/dist/commonjs/component/vector/tables.d.ts.map +1 -1
  20. package/dist/commonjs/component/vector/tables.js +14 -6
  21. package/dist/commonjs/component/vector/tables.js.map +1 -1
  22. package/dist/commonjs/mapping.d.ts +3 -2
  23. package/dist/commonjs/mapping.d.ts.map +1 -1
  24. package/dist/commonjs/mapping.js +45 -13
  25. package/dist/commonjs/mapping.js.map +1 -1
  26. package/dist/commonjs/validators.d.ts +2817 -145
  27. package/dist/commonjs/validators.d.ts.map +1 -1
  28. package/dist/commonjs/validators.js +79 -7
  29. package/dist/commonjs/validators.js.map +1 -1
  30. package/dist/esm/client/index.d.ts +800 -84
  31. package/dist/esm/client/index.d.ts.map +1 -1
  32. package/dist/esm/client/index.js +176 -130
  33. package/dist/esm/client/index.js.map +1 -1
  34. package/dist/esm/component/messages.d.ts +124 -105
  35. package/dist/esm/component/messages.d.ts.map +1 -1
  36. package/dist/esm/component/messages.js +145 -247
  37. package/dist/esm/component/messages.js.map +1 -1
  38. package/dist/esm/component/schema.d.ts +822 -746
  39. package/dist/esm/component/schema.d.ts.map +1 -1
  40. package/dist/esm/component/schema.js +13 -3
  41. package/dist/esm/component/schema.js.map +1 -1
  42. package/dist/esm/component/vector/index.d.ts +21 -6
  43. package/dist/esm/component/vector/index.d.ts.map +1 -1
  44. package/dist/esm/component/vector/index.js +32 -20
  45. package/dist/esm/component/vector/index.js.map +1 -1
  46. package/dist/esm/component/vector/tables.d.ts +25 -5
  47. package/dist/esm/component/vector/tables.d.ts.map +1 -1
  48. package/dist/esm/component/vector/tables.js +14 -6
  49. package/dist/esm/component/vector/tables.js.map +1 -1
  50. package/dist/esm/mapping.d.ts +3 -2
  51. package/dist/esm/mapping.d.ts.map +1 -1
  52. package/dist/esm/mapping.js +45 -13
  53. package/dist/esm/mapping.js.map +1 -1
  54. package/dist/esm/validators.d.ts +2817 -145
  55. package/dist/esm/validators.d.ts.map +1 -1
  56. package/dist/esm/validators.js +79 -7
  57. package/dist/esm/validators.js.map +1 -1
  58. package/package.json +7 -7
  59. package/src/client/index.ts +347 -170
  60. package/src/component/_generated/api.d.ts +33 -16
  61. package/src/component/messages.ts +177 -290
  62. package/src/component/schema.ts +14 -3
  63. package/src/component/vector/index.ts +59 -26
  64. package/src/component/vector/tables.ts +38 -6
  65. package/src/mapping.ts +60 -19
  66. package/src/validators.ts +112 -12
package/README.md CHANGED
@@ -6,16 +6,18 @@
6
6
 
7
7
  AI Agent framework built on Convex.
8
8
 
9
- - Automatic storage of chat history, per-user or per-thread.
9
+ - Automatic storage of chat history, per-user or per-thread, that can span multiple agents.
10
10
  - RAG for chat context, via hybrid text & vector search, with configuration options.
11
11
  Or use the API to query the history yourself and do it your way.
12
- - Opt-in search for messages from other threads (for the same specifieduser).
12
+ - Opt-in search for messages from other threads (for the same specified user).
13
13
  - Tool calls via the AI SDK, along with Convex-specific helpers.
14
14
  - Easy workflow integration with the [Workflow component](https://convex.dev/components/workflow).
15
15
  - Reactive & realtime updates to asynchronous threads.
16
16
  - Support for streaming text and storing the result in the database.
17
17
  - Optionally filter tool calls out of the thread history.
18
18
 
19
+ [Read the associated Stack post here](https://stack.convex.dev/ai-agents).
20
+
19
21
  Example usage:
20
22
 
21
23
  ```ts
@@ -31,18 +33,18 @@ const supportAgent = new Agent(components.agent, {
31
33
  export const createThread = action({
32
34
  args: { prompt: v.string() },
33
35
  handler: async (ctx, { prompt }) => {
34
- const { threadId, thread } = await supportAgent.createThread(ctx, {});
36
+ const { threadId, thread } = await supportAgent.createThread(ctx);
35
37
  const result = await thread.generateText({ prompt });
36
38
  return { threadId, text: result.text };
37
39
  },
38
40
  });
39
41
 
40
- // Pick up where you left off:
42
+ // Pick up where you left off, with the same or a different agent:
41
43
  export const continueThread = action({
42
44
  args: { prompt: v.string(), threadId: v.string() },
43
45
  handler: async (ctx, { prompt, threadId }) => {
44
46
  // This includes previous message history from the thread automatically.
45
- const { thread } = await supportAgent.continueThread(ctx, { threadId });
47
+ const { thread } = await anotherAgent.continueThread(ctx, { threadId });
46
48
  const result = await thread.generateText({ prompt });
47
49
  return result.text;
48
50
  },
@@ -68,7 +70,7 @@ export const supportAgentWorkflow = workflow.define({
68
70
  });
69
71
  ```
70
72
 
71
- Also see the [Stack article](https://stack.convex.dev/ai-agent).
73
+ Also see the [Stack article](https://stack.convex.dev/ai-agents).
72
74
 
73
75
  Coming soon:
74
76
 
@@ -333,10 +335,36 @@ const messages = await ctx.runQuery(components.agent.embeddings.deleteBatch, {
333
335
  ```
334
336
 
335
337
  See example usage in [example.ts](./example/convex/example.ts).
336
- Read more in [this Stack post](https://stack.convex.dev/ai-agent).
338
+ Read more in [this Stack post](https://stack.convex.dev/ai-agents).
337
339
 
338
340
  ```sh
339
341
  npm i @convex-dev/agent
340
342
  ```
341
343
 
344
+ ## Troubleshooting
345
+
346
+ ### Circular dependencies
347
+
348
+ Having the return value of workflows depend on other Convex functions can lead to circular dependencies due to the
349
+ `internal.foo.bar` way of specifying functions. The way to fix this is to explicitly type the return value of the
350
+ workflow. When in doubt, add return types to more `handler` functions, like this:
351
+
352
+ ```diff
353
+ export const supportAgentWorkflow = workflow.define({
354
+ args: { prompt: v.string(), userId: v.string(), threadId: v.string() },
355
+ + handler: async (step, { prompt, userId, threadId }): Promise<string> => {
356
+ // ...
357
+ },
358
+ });
359
+
360
+ // And regular functions too:
361
+ export const myFunction = action({
362
+ args: { prompt: v.string() },
363
+ + handler: async (ctx, { prompt }): Promise<string> => {
364
+ // ...
365
+ },
366
+ });
367
+ ```
368
+
369
+
342
370
  <!-- END: Include on https://convex.dev/components -->