openloops 0.3.5 → 0.4.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 (217) hide show
  1. package/README.md +9 -8
  2. package/dist/db/index.d.ts +1 -0
  3. package/dist/db/index.js +3 -1
  4. package/dist/db/index.mjs +1 -0
  5. package/dist/db/indexes/automation-runs.d.ts +2 -0
  6. package/dist/db/indexes/automation-runs.js +33 -0
  7. package/dist/db/indexes/automation-runs.mjs +10 -0
  8. package/dist/db/indexes/automations.d.ts +2 -0
  9. package/dist/db/indexes/{agentic-jobs.js → automations.js} +6 -6
  10. package/dist/db/indexes/{agentic-jobs.mjs → automations.mjs} +2 -2
  11. package/dist/db/indexes/index.js +6 -4
  12. package/dist/db/indexes/index.mjs +6 -4
  13. package/dist/db/indexes/revoked-tokens.d.ts +2 -0
  14. package/dist/db/indexes/{agentic-job-runs.js → revoked-tokens.js} +8 -9
  15. package/dist/db/indexes/revoked-tokens.mjs +8 -0
  16. package/dist/db/migrations/automations.d.ts +12 -0
  17. package/dist/db/migrations/automations.js +70 -0
  18. package/dist/db/migrations/automations.mjs +47 -0
  19. package/dist/services/authentication/entities/index.d.ts +1 -0
  20. package/dist/services/authentication/entities/index.js +22 -0
  21. package/dist/services/authentication/entities/index.mjs +1 -0
  22. package/dist/services/authentication/entities/revoked-token.entity.d.ts +17 -0
  23. package/dist/services/authentication/entities/revoked-token.entity.js +67 -0
  24. package/dist/services/authentication/entities/revoked-token.entity.mjs +44 -0
  25. package/dist/services/authentication/index.d.ts +1 -0
  26. package/dist/services/authentication/index.js +3 -1
  27. package/dist/services/authentication/index.mjs +1 -0
  28. package/dist/services/authentication/module.d.ts +4 -0
  29. package/dist/services/authentication/module.js +16 -2
  30. package/dist/services/authentication/module.mjs +13 -1
  31. package/dist/services/authentication/repositories/index.d.ts +1 -0
  32. package/dist/services/{agentic-jobs → authentication}/repositories/index.js +2 -4
  33. package/dist/services/authentication/repositories/index.mjs +1 -0
  34. package/dist/services/authentication/repositories/revoked-token.repository.d.ts +7 -0
  35. package/dist/services/authentication/repositories/revoked-token.repository.js +55 -0
  36. package/dist/services/authentication/repositories/revoked-token.repository.mjs +26 -0
  37. package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +15 -0
  38. package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +55 -0
  39. package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +26 -0
  40. package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +14 -0
  41. package/dist/services/authentication/use-cases/revoke-token.use-case.js +65 -0
  42. package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +36 -0
  43. package/dist/services/automations/entities/automation-run.entity.d.ts +46 -0
  44. package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.js → automations/entities/automation-run.entity.js} +22 -14
  45. package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.mjs → automations/entities/automation-run.entity.mjs} +18 -10
  46. package/dist/services/automations/entities/automation.entity.d.ts +38 -0
  47. package/dist/services/{agentic-jobs/entities/agentic-job.entity.js → automations/entities/automation.entity.js} +17 -17
  48. package/dist/services/{agentic-jobs/entities/agentic-job.entity.mjs → automations/entities/automation.entity.mjs} +13 -13
  49. package/dist/services/automations/entities/index.d.ts +4 -0
  50. package/dist/services/{agentic-jobs → automations}/entities/index.js +6 -4
  51. package/dist/services/automations/entities/index.mjs +4 -0
  52. package/dist/services/automations/entities/trigger.d.ts +11 -0
  53. package/dist/services/automations/entities/trigger.js +49 -0
  54. package/dist/services/automations/entities/trigger.mjs +26 -0
  55. package/dist/services/automations/index.d.ts +5 -0
  56. package/dist/services/{agentic-jobs → automations}/index.js +9 -7
  57. package/dist/services/automations/index.mjs +5 -0
  58. package/dist/services/automations/module.d.ts +41 -0
  59. package/dist/services/automations/module.js +167 -0
  60. package/dist/services/automations/module.mjs +125 -0
  61. package/dist/services/automations/repositories/automation-run.repository.d.ts +14 -0
  62. package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.js → automations/repositories/automation-run.repository.js} +23 -11
  63. package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.mjs → automations/repositories/automation-run.repository.mjs} +19 -7
  64. package/dist/services/automations/repositories/automation.repository.d.ts +27 -0
  65. package/dist/services/{agentic-jobs/repositories/agentic-job.repository.js → automations/repositories/automation.repository.js} +17 -17
  66. package/dist/services/{agentic-jobs/repositories/agentic-job.repository.mjs → automations/repositories/automation.repository.mjs} +13 -13
  67. package/dist/services/automations/repositories/index.d.ts +2 -0
  68. package/dist/services/automations/repositories/index.js +24 -0
  69. package/dist/services/automations/repositories/index.mjs +2 -0
  70. package/dist/services/automations/runner/automation-runner.d.ts +49 -0
  71. package/dist/services/{agentic-jobs/runner/agentic-job-runner.js → automations/runner/automation-runner.js} +55 -45
  72. package/dist/services/{agentic-jobs/runner/agentic-job-runner.mjs → automations/runner/automation-runner.mjs} +50 -40
  73. package/dist/services/{agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.d.ts → automations/use-cases/attach-automation-run-chat.use-case.d.ts} +6 -6
  74. package/dist/services/{agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.js → automations/use-cases/attach-automation-run-chat.use-case.js} +14 -14
  75. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +29 -0
  76. package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +28 -0
  77. package/dist/services/{agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.js → automations/use-cases/claim-due-automations.use-case.js} +32 -43
  78. package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +70 -0
  79. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +27 -0
  80. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +106 -0
  81. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +77 -0
  82. package/dist/services/automations/use-cases/create-automation.use-case.d.ts +14 -0
  83. package/dist/services/{agentic-jobs/use-cases/create-agentic-job.use-case.js → automations/use-cases/create-automation.use-case.js} +24 -25
  84. package/dist/services/automations/use-cases/create-automation.use-case.mjs +43 -0
  85. package/dist/services/{agentic-jobs/use-cases/delete-agentic-job.use-case.d.ts → automations/use-cases/delete-automation.use-case.d.ts} +6 -6
  86. package/dist/services/{agentic-jobs/use-cases/delete-agentic-job.use-case.js → automations/use-cases/delete-automation.use-case.js} +17 -17
  87. package/dist/services/automations/use-cases/delete-automation.use-case.mjs +36 -0
  88. package/dist/services/{agentic-jobs/use-cases/finish-agentic-job-run.use-case.d.ts → automations/use-cases/finish-automation-run.use-case.d.ts} +8 -8
  89. package/dist/services/{agentic-jobs/use-cases/finish-agentic-job-run.use-case.js → automations/use-cases/finish-automation-run.use-case.js} +20 -20
  90. package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +46 -0
  91. package/dist/services/{agentic-jobs/use-cases/get-agentic-job-by-id.use-case.d.ts → automations/use-cases/get-automation-by-id.use-case.d.ts} +6 -6
  92. package/dist/services/{agentic-jobs/use-cases/get-agentic-job-by-id.use-case.js → automations/use-cases/get-automation-by-id.use-case.js} +13 -13
  93. package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +26 -0
  94. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +17 -0
  95. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +59 -0
  96. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +30 -0
  97. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.d.ts → automations/use-cases/list-automation-runs-by-automation.use-case.d.ts} +7 -7
  98. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.js → automations/use-cases/list-automation-runs-by-automation.use-case.js} +15 -15
  99. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +28 -0
  100. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.d.ts → automations/use-cases/list-automation-runs-by-user.use-case.d.ts} +7 -7
  101. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.js → automations/use-cases/list-automation-runs-by-user.use-case.js} +14 -14
  102. package/dist/services/{agentic-jobs/use-cases/list-agentic-job-runs-by-user.use-case.mjs → automations/use-cases/list-automation-runs-by-user.use-case.mjs} +11 -11
  103. package/dist/services/{agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.d.ts → automations/use-cases/list-automations-by-user.use-case.d.ts} +6 -6
  104. package/dist/services/{agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.js → automations/use-cases/list-automations-by-user.use-case.js} +14 -14
  105. package/dist/services/{agentic-jobs/use-cases/list-agentic-jobs-by-user.use-case.mjs → automations/use-cases/list-automations-by-user.use-case.mjs} +11 -11
  106. package/dist/services/{agentic-jobs/use-cases/preview-agentic-job-runs.use-case.d.ts → automations/use-cases/preview-automation-runs.use-case.d.ts} +1 -1
  107. package/dist/services/{agentic-jobs/use-cases/preview-agentic-job-runs.use-case.js → automations/use-cases/preview-automation-runs.use-case.js} +8 -8
  108. package/dist/services/{agentic-jobs/use-cases/preview-agentic-job-runs.use-case.mjs → automations/use-cases/preview-automation-runs.use-case.mjs} +4 -4
  109. package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +23 -0
  110. package/dist/services/automations/use-cases/receive-automation-event.use-case.js +97 -0
  111. package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +68 -0
  112. package/dist/services/{agentic-jobs/use-cases/renew-agentic-job-lease.use-case.d.ts → automations/use-cases/renew-automation-lease.use-case.d.ts} +5 -5
  113. package/dist/services/{agentic-jobs/use-cases/renew-agentic-job-lease.use-case.js → automations/use-cases/renew-automation-lease.use-case.js} +15 -15
  114. package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +29 -0
  115. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +16 -0
  116. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +65 -0
  117. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +36 -0
  118. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +14 -0
  119. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +63 -0
  120. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +34 -0
  121. package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +21 -0
  122. package/dist/services/{agentic-jobs/use-cases/start-agentic-job-run.use-case.js → automations/use-cases/start-automation-run.use-case.js} +24 -24
  123. package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +38 -0
  124. package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +20 -0
  125. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-run.use-case.js → automations/use-cases/sync-automation-run.use-case.js} +23 -23
  126. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-run.use-case.mjs → automations/use-cases/sync-automation-run.use-case.mjs} +21 -21
  127. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-runs.use-case.d.ts → automations/use-cases/sync-automation-runs.use-case.d.ts} +5 -5
  128. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-runs.use-case.js → automations/use-cases/sync-automation-runs.use-case.js} +16 -16
  129. package/dist/services/{agentic-jobs/use-cases/sync-agentic-job-runs.use-case.mjs → automations/use-cases/sync-automation-runs.use-case.mjs} +13 -13
  130. package/dist/services/automations/use-cases/update-automation.use-case.d.ts +15 -0
  131. package/dist/services/{agentic-jobs/use-cases/update-agentic-job.use-case.js → automations/use-cases/update-automation.use-case.js} +27 -27
  132. package/dist/services/automations/use-cases/update-automation.use-case.mjs +54 -0
  133. package/dist/services/automations/utils/automation-event-error.d.ts +6 -0
  134. package/dist/services/automations/utils/automation-event-error.js +37 -0
  135. package/dist/services/automations/utils/automation-event-error.mjs +14 -0
  136. package/dist/services/automations/utils/automation-fields.d.ts +14 -0
  137. package/dist/services/{agentic-jobs/utils/job-fields.js → automations/utils/automation-fields.js} +8 -10
  138. package/dist/services/{agentic-jobs/utils/job-fields.mjs → automations/utils/automation-fields.mjs} +4 -6
  139. package/dist/services/automations/utils/event-message.d.ts +1 -0
  140. package/dist/services/automations/utils/event-message.js +37 -0
  141. package/dist/services/automations/utils/event-message.mjs +14 -0
  142. package/dist/services/automations/utils/event-token.d.ts +18 -0
  143. package/dist/services/automations/utils/event-token.js +78 -0
  144. package/dist/services/automations/utils/event-token.mjs +43 -0
  145. package/dist/services/automations/utils/open-run.d.ts +14 -0
  146. package/dist/services/{agentic-jobs → automations}/utils/open-run.js +10 -8
  147. package/dist/services/automations/utils/open-run.mjs +26 -0
  148. package/dist/services/automations/utils/previous-run.d.ts +4 -0
  149. package/dist/services/automations/utils/previous-run.js +42 -0
  150. package/dist/services/automations/utils/previous-run.mjs +19 -0
  151. package/dist/services/{agentic-jobs → automations}/utils/settings.d.ts +1 -0
  152. package/dist/services/{agentic-jobs → automations}/utils/settings.js +6 -2
  153. package/dist/services/automations/utils/settings.mjs +13 -0
  154. package/docs/README.md +1 -1
  155. package/docs/agent.md +2 -2
  156. package/docs/authentication.md +18 -1
  157. package/docs/automations.md +341 -0
  158. package/docs/configuration.md +6 -5
  159. package/docs/harness.md +1 -1
  160. package/docs/integration-guide.md +22 -18
  161. package/docs/llms.txt +1 -1
  162. package/docs/mcp-servers.md +1 -1
  163. package/examples/{agentic-jobs/create-agentic-job.ts → automations/create-automation.ts} +10 -7
  164. package/examples/automations/create-event-automation.ts +24 -0
  165. package/examples/{agentic-jobs/list-agentic-job-runs.ts → automations/list-automation-runs.ts} +8 -8
  166. package/examples/automations/list-automations.ts +25 -0
  167. package/examples/{agentic-jobs/preview-agentic-job-runs.ts → automations/preview-automation-runs.ts} +2 -2
  168. package/examples/automations/receive-automation-event.ts +26 -0
  169. package/examples/automations/revoke-automation-event-token.ts +25 -0
  170. package/examples/{agentic-jobs/run-agentic-job-now.ts → automations/run-automation-now.ts} +3 -3
  171. package/examples/{agentic-jobs/run-agentic-job-worker.ts → automations/run-automation-worker.ts} +6 -6
  172. package/examples/{agentic-jobs/update-agentic-job.ts → automations/update-automation.ts} +10 -10
  173. package/package.json +14 -13
  174. package/dist/db/indexes/agentic-job-runs.d.ts +0 -2
  175. package/dist/db/indexes/agentic-job-runs.mjs +0 -9
  176. package/dist/db/indexes/agentic-jobs.d.ts +0 -2
  177. package/dist/services/agentic-jobs/entities/agentic-job-run.entity.d.ts +0 -42
  178. package/dist/services/agentic-jobs/entities/agentic-job.entity.d.ts +0 -39
  179. package/dist/services/agentic-jobs/entities/index.d.ts +0 -3
  180. package/dist/services/agentic-jobs/entities/index.mjs +0 -3
  181. package/dist/services/agentic-jobs/index.d.ts +0 -4
  182. package/dist/services/agentic-jobs/index.mjs +0 -4
  183. package/dist/services/agentic-jobs/module.d.ts +0 -31
  184. package/dist/services/agentic-jobs/module.js +0 -132
  185. package/dist/services/agentic-jobs/module.mjs +0 -95
  186. package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.d.ts +0 -11
  187. package/dist/services/agentic-jobs/repositories/agentic-job.repository.d.ts +0 -27
  188. package/dist/services/agentic-jobs/repositories/index.d.ts +0 -2
  189. package/dist/services/agentic-jobs/repositories/index.mjs +0 -2
  190. package/dist/services/agentic-jobs/runner/agentic-job-runner.d.ts +0 -48
  191. package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.mjs +0 -29
  192. package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.d.ts +0 -29
  193. package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.mjs +0 -81
  194. package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.d.ts +0 -14
  195. package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.mjs +0 -44
  196. package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.mjs +0 -36
  197. package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.mjs +0 -46
  198. package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.mjs +0 -26
  199. package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.mjs +0 -28
  200. package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.mjs +0 -29
  201. package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.d.ts +0 -21
  202. package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.mjs +0 -38
  203. package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.d.ts +0 -20
  204. package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.d.ts +0 -15
  205. package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.mjs +0 -54
  206. package/dist/services/agentic-jobs/utils/job-fields.d.ts +0 -14
  207. package/dist/services/agentic-jobs/utils/open-run.d.ts +0 -12
  208. package/dist/services/agentic-jobs/utils/open-run.mjs +0 -24
  209. package/dist/services/agentic-jobs/utils/settings.mjs +0 -10
  210. package/docs/agentic-jobs.md +0 -217
  211. package/examples/agentic-jobs/list-agentic-jobs.ts +0 -25
  212. /package/dist/services/{agentic-jobs → automations}/entities/recurrence.d.ts +0 -0
  213. /package/dist/services/{agentic-jobs → automations}/entities/recurrence.js +0 -0
  214. /package/dist/services/{agentic-jobs → automations}/entities/recurrence.mjs +0 -0
  215. /package/dist/services/{agentic-jobs → automations}/utils/next-run.d.ts +0 -0
  216. /package/dist/services/{agentic-jobs → automations}/utils/next-run.js +0 -0
  217. /package/dist/services/{agentic-jobs → automations}/utils/next-run.mjs +0 -0
@@ -0,0 +1,341 @@
1
+ # Automations
2
+
3
+ An automation is a task that your agent runs by itself, without anyone in the chat. You describe what it must do and what starts it, a schedule or an event that arrives from another system, and `openloops` runs it in [autonomous mode](agent.md#autonomous-mode), in a new chat each time, and keeps a history of every run.
4
+
5
+ ```typescript
6
+ import {
7
+ createAutomation,
8
+ updateAutomation,
9
+ getAutomationById,
10
+ listAutomationsByUser,
11
+ deleteAutomation,
12
+ previewAutomationRuns,
13
+ issueAutomationEventToken,
14
+ revokeAutomationEventToken,
15
+ rotateAutomationEventTokens,
16
+ receiveAutomationEvent,
17
+ listAutomationRunsByAutomation,
18
+ listAutomationRunsByUser,
19
+ createAutomationRunner,
20
+ } from 'openloops/automations'
21
+ ```
22
+
23
+ There are two parts. The use cases create and manage automations and read their history, and are called from your API. The runner is a worker that you start in your backend and that executes what is due.
24
+
25
+ ## Creating an automation
26
+
27
+ ```typescript
28
+ const result = await createAutomation({
29
+ payload: {
30
+ name: 'Morning report',
31
+ instructions: 'Summarize my open tickets and send the summary to my email',
32
+ trigger: {
33
+ type: 'schedule',
34
+ recurrence: { type: 'weekly', days: [1, 2, 3, 4, 5], time: '08:00' },
35
+ timezone: 'America/Lima',
36
+ },
37
+ modelProvider: 'anthropic',
38
+ modelName: 'claude-haiku-5-5',
39
+ },
40
+ currentUser,
41
+ })
42
+
43
+ result.data.nextRunAt
44
+ ```
45
+
46
+ | Field | Required | What it is |
47
+ | --- | --- | --- |
48
+ | `name` | yes | A name to recognize the automation. |
49
+ | `instructions` | yes | What the agent must do. It is sent to the agent as the message of the user, so write it as you would write it in a chat. If the task needs to notify someone, say so here and give the agent a tool for it. |
50
+ | `trigger` | yes | What starts it. A `schedule` or an `event`. See below. |
51
+ | `enabled` | no | `true` by default. An automation that is off never runs, and can be turned on again. |
52
+ | `modelProvider`, `modelName` | no | The model of the automation, both or none. Without them, the default model of the owner is used, then the fallbacks. See [configuration](configuration.md#which-model-a-chat-uses). |
53
+
54
+ `nextRunAt` is calculated when a scheduled automation is created and it is what you show to the user. An automation with an event trigger has no `nextRunAt`. The fields that the system manages (`nextRunAt`, `lastRunAt`, `lastRunStatus`, `lockedBy`, `lockedUntil`, `activeRunId`) are ignored if they come in the payload.
55
+
56
+ ## Triggers
57
+
58
+ An automation has one trigger. Its type is chosen when it is created and cannot be changed afterwards. To change it, create another automation.
59
+
60
+ | Type | Fields | Starts |
61
+ | --- | --- | --- |
62
+ | `schedule` | `recurrence`, `timezone` | On the dates of the recurrence. |
63
+ | `event` | `timezone` (optional) | When an external system sends an event to it. See [events](#events). |
64
+
65
+ You can always start any automation by hand with [`runNow`](#running-by-hand), whatever its trigger.
66
+
67
+ ### Recurrence
68
+
69
+ The recurrence of a `schedule` trigger is stored as a structured value, so a screen can offer simple choices and nobody has to write a cron expression. The `timezone` is an IANA timezone: the local time and the days of the recurrence are those of this timezone, and daylight saving time is respected. The time is in 24 hours.
70
+
71
+ | Type | Fields | Example |
72
+ | --- | --- | --- |
73
+ | `daily` | `time` | `{ type: 'daily', time: '08:00' }` |
74
+ | `weekly` | `days` (1 is Monday, 7 is Sunday), `time` | `{ type: 'weekly', days: [1, 2, 3, 4, 5], time: '09:30' }` is Monday to Friday |
75
+ | `monthly` | `day` (1 to 31 or `'last'`), `time` | `{ type: 'monthly', day: 15, time: '12:00' }` |
76
+ | `once` | `at` (`YYYY-MM-DDTHH:mm`, local time) | `{ type: 'once', at: '2026-12-25T10:00' }` |
77
+
78
+ - A monthly automation on day 29, 30 or 31 is skipped in the months that do not have that day. Use `'last'` for the last day of every month.
79
+ - A time that does not exist on a day because of daylight saving time runs at the first valid moment of that day, and a time that happens twice runs once.
80
+ - An automation of type `once` runs a single time and then has no next run.
81
+
82
+ ### Previewing
83
+
84
+ ```typescript
85
+ const { data } = await previewAutomationRuns({
86
+ recurrence: { type: 'weekly', days: [1, 5], time: '08:00' },
87
+ timezone: 'America/Lima',
88
+ count: 5,
89
+ })
90
+
91
+ data.runs
92
+ ```
93
+
94
+ It returns the next dates (at most 20) without saving anything, so a screen can show "it will run on Monday at 8:00, on Friday at 8:00...".
95
+
96
+ ## Managing automations
97
+
98
+ ```typescript
99
+ await updateAutomation({ id, payload: { enabled: false }, currentUser })
100
+
101
+ await updateAutomation({ id, payload: { enabled: true }, currentUser })
102
+
103
+ const automation = await getAutomationById({ id, currentUser })
104
+
105
+ const automations = await listAutomationsByUser({ options: { page: 1, limit: 10 }, currentUser })
106
+
107
+ await deleteAutomation({ id, currentUser })
108
+ ```
109
+
110
+ - **Turning an automation off** is how the user pauses it for a while. It has no next run until it is turned on again. Turning it on counts the next run from that moment, it does not catch up with what was missed.
111
+ - **Changing the trigger of a schedule** (its recurrence or timezone, you can send only the one that changes) **or turning it on** calculates `nextRunAt` again from now.
112
+ - **A run that is in progress is not interrupted** by turning the automation off or by deleting it.
113
+ - **`__v`** in the payload works as in the other use cases: if the automation changed since it was read, the update fails with a `VersionConflictError`.
114
+ - **Deleting** is a soft delete. An admin can delete for good with `hardDelete: true`.
115
+ - **The system never turns an automation off by itself.** An automation that fails keeps trying on every occurrence, so watch the history.
116
+
117
+ ## Events
118
+
119
+ An automation with an event trigger runs when another system sends it an event, for example an alarm of AWS that reaches a Lambda, which calls your backend. The event becomes a run in a queue and the runner executes it as soon as it can.
120
+
121
+ ```typescript
122
+ const { data: automation } = await createAutomation({
123
+ payload: {
124
+ name: 'Cost anomaly analysis',
125
+ instructions: 'Find the cause of the cost alert in AWS and send a summary to the channel #costs',
126
+ trigger: { type: 'event' },
127
+ },
128
+ currentUser,
129
+ })
130
+
131
+ const { data } = await issueAutomationEventToken({ id: String(automation._id), expiresIn: '90d', currentUser })
132
+
133
+ data.token
134
+ data.expiresAt
135
+ ```
136
+
137
+ `openloops` has no HTTP layer, so the endpoint is yours. It reads the token from the `Authorization: Bearer` header, so it does not end up in the logs of the URLs, and calls the use case:
138
+
139
+ ```typescript
140
+ import { AutomationEventError, receiveAutomationEvent } from 'openloops/automations'
141
+
142
+ app.post('/automations/events/:automationId', async (req, res) => {
143
+ try {
144
+ const { data } = await receiveAutomationEvent({
145
+ automationId: req.params.automationId,
146
+ token: req.headers.authorization?.replace(/^Bearer /, ''),
147
+ payload: req.body,
148
+ idempotencyKey: req.header('Idempotency-Key'),
149
+ })
150
+
151
+ res.status(202).json({ status: data.status, runId: data.run._id })
152
+ } catch (error) {
153
+ if (error instanceof AutomationEventError) {
154
+ logger.warn({ reason: error.reason }, 'Event rejected')
155
+ return res.status(error.statusCode).json({ error: error.message })
156
+ }
157
+
158
+ throw error
159
+ }
160
+ })
161
+ ```
162
+
163
+ The use case answers without running the agent. The run is created as `queued` and the runner takes it. If the runner lives in the same process as this endpoint, call `runner.wake()` after receiving to start it at once instead of waiting for the next check.
164
+
165
+ ### What the use case does
166
+
167
+ 1. Verifies the token. See below.
168
+ 2. Saves the payload in the run. It is stored as text and cannot be longer than 50000 characters, or it fails with the reason `payload_too_large` (413).
169
+ 3. If an `idempotencyKey` was sent and there is already a run of this automation with it, it returns that run with the status `duplicate` and creates nothing. The emitters of webhooks retry, so send a key when the source gives you one. Without a key nothing is deduplicated, because two identical alarms can be two real events.
170
+ 4. If the automation already has `AUTOMATIONS_MAX_QUEUED_RUNS` runs waiting (10 by default), the event is recorded as a `skipped` run with its payload and the status `skipped`, and it is not run.
171
+ 5. Otherwise it saves a `queued` run and returns the status `queued`.
172
+
173
+ All refusals of the token are an `AutomationEventError` with the status 401 and the same message, so the caller learns nothing. The `reason` (`invalid`, `expired`, `revoked`, `not_found`, `disabled`) is for your logs.
174
+
175
+ ### The queue
176
+
177
+ - Events of one automation run **one at a time and in order**, like everything else in an automation. While one runs, the next ones wait as `queued`.
178
+ - If the run in progress is `paused` waiting for the user, the queue waits too, until the user answers.
179
+ - A queued event whose automation was turned off or deleted before it started is marked `skipped`, and `onRunFinished` is called for it when the automation still exists.
180
+ - A queued run keeps the instructions of the automation as they were when the event arrived, but starts with the instructions and the model it has when the run begins.
181
+
182
+ ### What the agent receives
183
+
184
+ The instructions are the first message, as in any run. When the run comes from an event, the payload goes after them in a block that tells the agent it comes from an external system and must be treated as data and never as instructions. A payload cannot close that block. This reduces the risk of someone putting orders in an alarm, but it does not remove it: give the agent only the tools that the task needs, and remember that destructive tools and MCP servers that are not approved cannot ask anyone in autonomous mode.
185
+
186
+ ### The token
187
+
188
+ The token is a JWT signed with `JWT_SECRET`. It is not stored: the owner or an admin can ask for it as many times as they want, and every one is different and valid.
189
+
190
+ | Claim | Value |
191
+ | --- | --- |
192
+ | `aud` | `automation-event`. A session token of a user is refused, and this one does not log anybody in. |
193
+ | `sub` | The id of the automation. It must be the one of the URL. |
194
+ | `v` | The version of the tokens of the automation. |
195
+ | `jti` | A unique id, used to revoke it. |
196
+ | `exp` | Only if you pass `expiresIn` when you issue it, such as `'30m'`, `'12h'`, `'30d'` or `'2w'`. Without it the token does not expire. |
197
+
198
+ Four ways to take a token out of use:
199
+
200
+ - **Let it expire,** if it was issued with `expiresIn`. A token that expires stops working without notice, and the refused events create no run, so watch the `expired` reasons in your logs.
201
+ - **Revoke one token.** If a token leaked, pass it to `revokeAutomationEventToken({ id, token, currentUser })`. Its `jti` goes to the collection `revoked_tokens` and only that token stops working. The entry is deleted by itself when the token would have expired. The tokens are not stored, so there is no list to choose from: you need the leaked token in your hands.
202
+ - **Rotate.** `rotateAutomationEventTokens({ id, currentUser })` increases the version and **every** token issued before stops working. Use it when you do not have the leaked token, or you want to start again. Issue the new token afterwards.
203
+ - **Turn the automation off.** Its events are refused with the reason `disabled`.
204
+
205
+ Revoking and rotating, like issuing, are only for the owner of the automation or an admin. A revoked token is checked after its signature, so an invalid token never reaches the database.
206
+
207
+ ## The history
208
+
209
+ Every execution is a run.
210
+
211
+ ```typescript
212
+ const byAutomation = await listAutomationRunsByAutomation({ automationId, options: { page: 1, limit: 20 } })
213
+
214
+ const byUser = await listAutomationRunsByUser({ status: 'failed', currentUser })
215
+ ```
216
+
217
+ | Field | Meaning |
218
+ | --- | --- |
219
+ | `automationId`, `chatId` | The automation and the chat of the run. Open the chat to read everything that the agent did. |
220
+ | `trigger` | `schedule`, `manual` or `event`. |
221
+ | `scheduledFor`, `startedAt`, `finishedAt` | When it was due, when it started and when it ended. A queued run has no `startedAt` yet. |
222
+ | `payload`, `idempotencyKey` | The event that caused the run, as text, and the key it came with. |
223
+ | `status` | See below. |
224
+ | `error` | `code` and `message` when it failed. |
225
+ | `skipReason` | Why a run was skipped. |
226
+ | `instructions`, `modelProvider`, `modelName` | What was run, as it was when the run started, even if the automation was edited later. |
227
+
228
+ | Status | Meaning |
229
+ | --- | --- |
230
+ | `queued` | An event waiting for its turn. |
231
+ | `running` | In progress. |
232
+ | `completed` | The agent finished its task. |
233
+ | `paused` | The agent needs the user: it asked for the approval of a tool or an MCP server, or asked a question. The chat is waiting. When the user answers in the chat and it finishes, the run becomes `completed` or `failed`. |
234
+ | `failed` | It failed. `error` says why: the model did not answer in time, a guardrail blocked the instructions, the owner no longer exists, or the worker was lost. |
235
+ | `skipped` | It was not started and `skipReason` says why: a scheduled run was due but the previous one was still `paused`, an event found the queue full, or the automation was turned off or deleted while the event waited. It is recorded so you can notify the user. |
236
+
237
+ ## The runner
238
+
239
+ The runner is a worker that checks what is due and the events that are waiting, and runs them. You create it once, with the agent that your automations should use, and start it in your backend.
240
+
241
+ ```typescript
242
+ import { createAutomationRunner } from 'openloops/automations'
243
+ import { webSearchTool } from 'openloops/tools'
244
+ import { inputGuards } from 'openloops/guardrails'
245
+
246
+ const runner = createAutomationRunner({
247
+ agent: {
248
+ tools: [webSearchTool, sendEmailTool],
249
+ guards: [inputGuards.blockCard],
250
+ maxIterations: 30,
251
+ },
252
+ onRunFinished: async ({ automation, run, chat }) => {
253
+ if (run.status === 'failed' || run.status === 'skipped') await notifyTheOwner(automation, run)
254
+ },
255
+ })
256
+
257
+ runner.start()
258
+
259
+ process.on('SIGTERM', async () => {
260
+ await runner.stop()
261
+ process.exit(0)
262
+ })
263
+ ```
264
+
265
+ | Option | Default | What it does |
266
+ | --- | --- | --- |
267
+ | `agent` | `{}` | The options of the `Agent` used for every run: tools, guards, `maxIterations`, `strictMode`, `identity`... It can be a function `({ automation, currentUser }) => options` when they depend on the automation or on the user. The loop is `AgiLoop` unless you set `loop`. A custom loop must support autonomous mode (`harness.executionMode`). |
268
+ | `intervalMs` | `60000` | How often it checks. Also set with `AUTOMATIONS_POLL_INTERVAL_MS`. `runner.wake()` makes it check now. |
269
+ | `leaseMs` | `600000` | How long an automation stays locked while it runs, renewed while the run lasts. Also set with `AUTOMATIONS_LEASE_MS`. |
270
+ | `maxConcurrentRuns` | `3` | How many runs a runner executes at once. |
271
+ | `stopTimeoutMs` | `30000` | How long `stop()` waits for the runs in progress. |
272
+ | `workerId` | generated | An identifier of the worker, kept in the run. |
273
+ | `onRunFinished` | none | Called with `{ automation, run, chat }` when a run ends, is paused or is skipped. An error in it does not affect the run. |
274
+
275
+ A new `Agent` is created for every run, so the options are the same but nothing is shared between runs.
276
+
277
+ ### What every run does
278
+
279
+ - It runs as the owner of the automation, which must exist.
280
+ - It starts a new chat, in autonomous mode, with the model of the automation, and the instructions as the first message. The chat is recorded in the run as soon as it exists.
281
+ - It gives the agent the timezone of the automation, so the local time reaches the prompts.
282
+ - Guards of the agent apply to the instructions. If one blocks them, the run is `failed`.
283
+
284
+ ### Internal MCP servers in an automation
285
+
286
+ An automation runs without the session of its owner, so there is no token of theirs to send to your [internal MCP servers](mcp-servers.md#internal-mcp-servers). For automations, the runner uses one token for the whole deployment, taken from `INTERNAL_MCP_TOKEN`. It replaces `{{token}}` in the headers of every internal server, and the runner also sends the id of the owner of the automation in the header `X-User-Id`, so your MCP server knows on whose behalf it acts.
287
+
288
+ - Your MCP server must accept `X-User-Id` only together with this service token. Never trust it on a request that carries the token of a user.
289
+ - The header is added only in automations and only to internal servers that use `{{token}}`. It replaces any `X-User-Id` you configured. It is never sent to the servers added by the user.
290
+ - Without `INTERNAL_MCP_TOKEN`, the internal servers that need a token are unavailable in the automations, and the run continues without them.
291
+ - The value is read with the secret manager, so it can be encrypted with the `ENC:` prefix.
292
+ - One variable serves all the internal servers. If two of them need different credentials, that is not supported yet.
293
+
294
+ ### Running by hand
295
+
296
+ ```typescript
297
+ const { run } = await runner.runNow({ automationId })
298
+ ```
299
+
300
+ It starts the run at once and returns while it keeps running in the background. It does not change the next scheduled run. It is refused if the automation is already running. Any process that has a runner can call it, it does not need to be the one that called `start()`.
301
+
302
+ ### Several instances
303
+
304
+ You can run the worker in as many pods as you want. An automation is taken with a single atomic update in the database that only one worker wins, and the same update moves `nextRunAt` to the next occurrence. So:
305
+
306
+ - An automation is never started twice at the same time.
307
+ - A run that fails, or whose worker dies, is **not repeated** until the next occurrence.
308
+ - If the backend was down, an automation that was due runs **once**, and the next run is counted from now.
309
+ - The lease expires if a worker dies. The run it left in progress is marked as `failed` and the automation keeps its schedule.
310
+
311
+ If you prefer, start the runner in a single deployment and call `runNow` from the others.
312
+
313
+ ### Settling the runs that wait for the user
314
+
315
+ Someone answers a paused run in the chat, outside the runner. The runner checks the open runs on every pass and updates them from the state of their chat. If you want it faster, call `syncAutomationRun({ runId })` when your own events tell you that a chat ended.
316
+
317
+ ## Indexes
318
+
319
+ The collections are `automations` and `automation_runs`. `ensureIndexes` from `openloops/db` creates the indexes of the queries of the runner and of the lists (see [configuration](configuration.md#indexes)). They are:
320
+
321
+ - `automations`: `{ enabled: 1, nextRunAt: 1 }` and `{ ownerId: 1, createdAt: -1 }`.
322
+ - `automation_runs`: `{ automationId: 1, createdAt: -1 }`, `{ ownerId: 1, createdAt: -1 }`, `{ status: 1, createdAt: 1 }` and a unique index on `{ automationId: 1, idempotencyKey: 1 }` for the runs that have a key, which makes the deduplication of events safe when two requests arrive together.
323
+ - `revoked_tokens`: a unique index on `jti` and a TTL index on `expiresAt`. It belongs to [authentication](authentication.md#revoked-tokens).
324
+
325
+ ## Migrating from agentic jobs
326
+
327
+ Before 0.4.0 this module was called `agentic-jobs`. The import is now `openloops/automations`, the functions and types swap `AgenticJob` for `Automation`, the variables are `AUTOMATIONS_*`, the collections are `automations` and `automation_runs`, the runs point to their automation with `automationId`, and `recurrence` and `timezone` live inside `trigger`. The old names are not kept as aliases.
328
+
329
+ To move the data, run this once per database after deploying the new version, or before it if you prefer. It renames the collections, moves `recurrence` and `timezone` into a `schedule` trigger, renames `jobId` to `automationId`, drops the old index and creates the new ones. It can be run again without changing anything, and it refuses to rename a collection if the new name already exists.
330
+
331
+ ```typescript
332
+ import { migrateAutomations } from 'openloops/db'
333
+
334
+ const report = await migrateAutomations(db, { dryRun: true })
335
+ ```
336
+
337
+ With `dryRun` it only counts what it would change. In a checkout of this repository you can run `yarn migrate:automations --dry-run` and `yarn migrate:automations`, which read `OPENLOOPS_DB_URI` and `OPENLOOPS_DB_NAME`. Stop the runner of the old version first: a run that is in progress while the collection is renamed fails.
338
+
339
+ ## Limits
340
+
341
+ How many automations a user can have, how often they can run and how much they can spend is not decided here. That belongs to the module of usage limits.
@@ -10,12 +10,13 @@
10
10
  | `SECRET_MANAGER_KEY` | yes | Key used to decrypt values that start with `ENC:`. The library throws when it loads without it. |
11
11
  | `ANTHROPIC_API_KEY` | for the default model | API key of the default provider, `anthropic`. |
12
12
  | `OPENAI_API_KEY`, `GEMINI_API_KEY` | for those providers | API keys of the other providers you choose per chat. |
13
- | `JWT_SECRET` | for `login` | Secret that signs the tokens. See [authentication](authentication.md). |
13
+ | `JWT_SECRET` | for `login` and for event automations | Secret that signs the tokens of the users and the tokens of [event automations](automations.md#the-token). See [authentication](authentication.md). |
14
14
  | `SERPER_API_KEY` | for `webSearchTool` | See [tools](tools.md#built-in-tools). |
15
15
  | `SLACK_BOT_TOKEN` | for `sendSlackMessageTool` | See [tools](tools.md#built-in-tools). |
16
- | `INTERNAL_MCP_TOKEN` | for internal MCP servers in agentic jobs | Token sent to the internal MCP servers when a job runs without the session of its owner. See [agentic jobs](agentic-jobs.md#internal-mcp-servers-in-a-job). |
17
- | `AGENTIC_JOBS_POLL_INTERVAL_MS` | no | How often the runner of [agentic jobs](agentic-jobs.md) checks what is due, in milliseconds. Defaults to `60000`. |
18
- | `AGENTIC_JOBS_LEASE_MS` | no | How long a job stays locked while it runs, in milliseconds. Defaults to `600000`. |
16
+ | `INTERNAL_MCP_TOKEN` | for internal MCP servers in automations | Token sent to the internal MCP servers when an automation runs without the session of its owner. See [automations](automations.md#internal-mcp-servers-in-a-automation). |
17
+ | `AUTOMATIONS_POLL_INTERVAL_MS` | no | How often the runner of [automations](automations.md) checks what is due, in milliseconds. Defaults to `60000`. |
18
+ | `AUTOMATIONS_LEASE_MS` | no | How long an automation stays locked while it runs, in milliseconds. Defaults to `600000`. |
19
+ | `AUTOMATIONS_MAX_QUEUED_RUNS` | no | How many events of one automation can wait to run. The next ones are recorded as skipped. Defaults to `10`. Read by the endpoint that receives the events. |
19
20
  | `LLM_FALLBACK_PROVIDER`, `LLM_FALLBACK_MODEL` | no | The model to use when nothing else chooses one, for the whole deployment. Set both or neither. See [Which model a chat uses](#which-model-a-chat-uses). |
20
21
  | `LLM_CALL_TIMEOUT_MS` | no | Longest time to wait for one attempt of a model call, in milliseconds. Defaults to `60000`, and calls with the `high` thinking effort get twice as much. See [Timeouts](#timeouts). |
21
22
  | `MCP_TOOL_TIMEOUT_MS` | no | Longest time to wait for a tool of an MCP server, in milliseconds. Defaults to `60000`. See [Timeouts](#timeouts). |
@@ -93,7 +94,7 @@ console.log(await ensureIndexes(client.db(process.env.OPENLOOPS_DB_NAME || 'open
93
94
  await client.close()
94
95
  ```
95
96
 
96
- It covers `llm_calls`, `chats`, `agent_tasks`, `agent_actions`, `agent_traces`, `workspace_items`, `mcp_servers`, `agentic_jobs` and `agentic_job_runs`. It is safe to run again: an index that already exists is left as it is. Collections of your own application are not included.
97
+ It covers `llm_calls`, `chats`, `agent_tasks`, `agent_actions`, `agent_traces`, `workspace_items`, `mcp_servers`, `automations` and `automation_runs`. It is safe to run again: an index that already exists is left as it is. Collections of your own application are not included.
97
98
 
98
99
  ## What is recorded
99
100
 
package/docs/harness.md CHANGED
@@ -11,7 +11,7 @@ The harness is everything between a loop and the outside world. A loop decides w
11
11
  | **Transmission** | Takes the model to the outside world: the tools, found on demand and validated before they run. | [Tool pipeline](#tool-pipeline), [native tools](#native-tools), [tool discovery](#tool-discovery), [tools](tools.md), [MCP servers](mcp-servers.md) |
12
12
  | **Brakes** | Stops the agent when it should stop: approvals, guardrails, timeouts and limits. | [Approvals](#approvals), [limits](#limits), [guardrails](guardrails.md), [timeouts](configuration.md#timeouts) |
13
13
  | **Logbook** | Remembers and records: the workspace, the history of every task and the usage of every call. | [Workspace](#workspace), [observability](#observability), [chats](chats.md), [usage](usage.md) |
14
- | **Steering** | Decides how the agent is driven: interactive or autonomous, scheduled, and with which model. | [Autonomous runs](#autonomous-runs), [language](#language), [the Agent](agent.md), [agentic jobs](agentic-jobs.md) |
14
+ | **Steering** | Decides how the agent is driven: interactive or autonomous, scheduled, and with which model. | [Autonomous runs](#autonomous-runs), [language](#language), [the Agent](agent.md), [automations](automations.md) |
15
15
 
16
16
  ## Tool pipeline
17
17
 
@@ -23,8 +23,8 @@ The package has no controllers: the authorization of every endpoint is the respo
23
23
 
24
24
  The use cases trust the `currentUser` you pass and the ids you give them.
25
25
 
26
- - Functions that list by user (`listChatsByUser`, `listMcpServersByUser`, `listAgenticJobsByUser`, `listAgenticJobRunsByUser`) only return records of that user.
27
- - Functions that take an **id** (`getChatById`, `updateChat`, `deleteChat`, `getMcpServerById`, `updateMcpServer`, `deleteMcpServer`, `decideMcpServerTrust`, `getAgenticJobById`, `updateAgenticJob`, `deleteAgenticJob`, `listAgenticJobRunsByJob`, `runner.runNow`) **do not check who owns the record**.
26
+ - Functions that list by user (`listChatsByUser`, `listMcpServersByUser`, `listAutomationsByUser`, `listAutomationRunsByUser`) only return records of that user.
27
+ - Functions that take an **id** (`getChatById`, `updateChat`, `deleteChat`, `getMcpServerById`, `updateMcpServer`, `deleteMcpServer`, `decideMcpServerTrust`, `getAutomationById`, `updateAutomation`, `deleteAutomation`, `listAutomationRunsByAutomation`, `runner.runNow`) **do not check who owns the record**. The use cases that issue, revoke or rotate the tokens of an automation do check that the user is the owner or an admin.
28
28
 
29
29
  So, before calling any of the second kind, load the record and check that `ownerId` is the user of the request. Do it in one place, a middleware or a helper, and never pass an id from a request straight to a use case.
30
30
 
@@ -42,9 +42,11 @@ Also note that `getChatById` returns `{}` in `data` when the chat does not exist
42
42
  | Approve or block an MCP server from a screen | `decideMcpServerTrust` |
43
43
  | Usage of a chat or of an answer | `getLLMUsageByChat`, `getLLMUsageByMessage` |
44
44
  | Usage statistics of a user | `getLLMUsageStats` |
45
- | Create the schedule of an agent | `createAgenticJob`, `updateAgenticJob`, `listAgenticJobsByUser`, `getAgenticJobById`, `deleteAgenticJob`, `previewAgenticJobRuns` |
46
- | History of scheduled runs | `listAgenticJobRunsByJob`, `listAgenticJobRunsByUser` |
47
- | "Run now" | `runner.runNow({ jobId })` |
45
+ | Create the schedule or the event trigger of an agent | `createAutomation`, `updateAutomation`, `listAutomationsByUser`, `getAutomationById`, `deleteAutomation`, `previewAutomationRuns` |
46
+ | Receive an event from another system | `receiveAutomationEvent`, public endpoint, authenticated only by the token of the automation |
47
+ | Tokens of an event automation | `issueAutomationEventToken`, `revokeAutomationEventToken`, `rotateAutomationEventTokens` |
48
+ | History of runs | `listAutomationRunsByAutomation`, `listAutomationRunsByUser` |
49
+ | "Run now" | `runner.runNow({ automationId })` |
48
50
  | Sign in, users | `login`, `createUser`, `getUserById`, `updateUser`, `deleteUser` |
49
51
 
50
52
  ## Running the agent for a message
@@ -95,28 +97,29 @@ Your users register their own servers, and every server must be approved before
95
97
 
96
98
  **Do not send `headers` or `history` of an MCP server to the client as they are.** `headers` hold credentials and `history` holds the full manifests. Mask the header values and send only what the screen needs, such as the name, `trust`, `status`, `lastError` and the hash of the latest manifest.
97
99
 
98
- ## Scheduled agents (agentic jobs)
100
+ ## Automations (scheduled and by event)
99
101
 
100
- Two parts, as described in [agentic jobs](agentic-jobs.md):
102
+ Three parts, as described in [automations](automations.md):
101
103
 
102
- 1. Endpoints that create and manage jobs and read their runs, from the table above.
103
- 2. A worker process that you start once, with the options of the agent your jobs should use:
104
+ 1. Endpoints that create and manage automations and read their runs, from the table above.
105
+ 2. If you use event triggers, one public endpoint that calls `receiveAutomationEvent` with the token of the `Authorization` header. It answers 202 without running the agent, and it is the only call that does not need a `CurrentUser`.
106
+ 3. A worker process that you start once, with the options of the agent your automations should use:
104
107
 
105
108
  ```typescript
106
- import { createAgenticJobRunner } from 'openloops/agentic-jobs'
109
+ import { createAutomationRunner } from 'openloops/automations'
107
110
 
108
- const runner = createAgenticJobRunner({
111
+ const runner = createAutomationRunner({
109
112
  agent: { tools: yourTools, guards: yourGuards },
110
- onRunFinished: async ({ job, run }) => { /* notify the owner */ },
113
+ onRunFinished: async ({ automation, run }) => { /* notify the owner */ },
111
114
  })
112
115
 
113
116
  runner.start()
114
117
  ```
115
118
 
116
- - It is safe to start the worker in several instances: a due job is taken by one of them.
119
+ - It is safe to start the worker in several instances: a due automation or a queued event is taken by one of them.
117
120
  - Stop it with `runner.stop()` when the process receives `SIGTERM`.
118
- - Create the indexes with `ensureIndexes` from `openloops/db`, see [configuration](configuration.md#indexes). The ones of the jobs are listed in [agentic jobs](agentic-jobs.md#indexes).
119
- - A job that needs the user (a destructive tool, an unapproved server, a question) pauses its run, and the user answers in the chat of that run. Show those runs, which you can list with `listAgenticJobRunsByUser({ status: 'paused' })`.
121
+ - Create the indexes with `ensureIndexes` from `openloops/db`, see [configuration](configuration.md#indexes). The ones of the automations are listed in [automations](automations.md#indexes).
122
+ - An automation that needs the user (a destructive tool, an unapproved server, a question) pauses its run, and the user answers in the chat of that run. Show those runs, which you can list with `listAutomationRunsByUser({ status: 'paused' })`.
120
123
 
121
124
  ## Security checklist
122
125
 
@@ -126,14 +129,15 @@ runner.start()
126
129
  - Mark your own destructive tools with `destructive: true`. The agent asks for confirmation before running them. Do not rely on a tool being treated as destructive by default, because it is not.
127
130
  - Use `strictMode: true` in the agent when the tools of an MCP server must be reviewed by the user on every change.
128
131
  - Keep API keys and the secrets of [configuration](configuration.md) out of the code. Values can be stored encrypted with the `ENC:` prefix.
129
- - Set limits on how many scheduled jobs and how often they run in your own layer, since `openloops` does not limit them yet.
132
+ - Set limits on how many automations and how often they run in your own layer, since `openloops` does not limit them yet.
130
133
 
131
134
  ## Common mistakes
132
135
 
133
136
  - Sharing one `Agent` between concurrent requests.
134
137
  - Waiting for `agent.run` inside a request with a short timeout.
135
- - Passing `chatId`, `jobId` or `mcpServerId` from the client without checking the owner.
138
+ - Passing `chatId`, `automationId` or `mcpServerId` from the client without checking the owner.
136
139
  - Treating `error` as an exception that is thrown. It is returned.
137
140
  - Forgetting that a run in `awaiting_user_confirmation` is waiting for the next message of the user, and that the next message is the answer.
138
- - Starting the scheduled jobs worker without creating its indexes.
141
+ - Starting the automations worker without creating its indexes.
142
+ - Exposing the endpoint of events without logging the rejected ones, or sending the token in the URL instead of the `Authorization` header.
139
143
  - Running the package on a real database without calling `ensureIndexes`.
package/docs/llms.txt CHANGED
@@ -26,7 +26,7 @@ Start with the integration guide, then read only the pages you need. All pages a
26
26
  ## Connect and schedule
27
27
 
28
28
  - [MCP servers](mcp-servers.md): registering servers, the trust flow, approving and blocking, internal servers of your own
29
- - [Agentic jobs](agentic-jobs.md): scheduled agent runs, recurrence, history and the runner
29
+ - [Automations](automations.md): agent runs by schedule or by event, tokens, queue, history and the runner
30
30
 
31
31
  ## Users and cost
32
32
 
@@ -179,7 +179,7 @@ await agent.run({
179
179
  - If a server of the user has the same name as an internal one, the one of the user is ignored for that run, so nobody can impersonate an internal server.
180
180
  - The tools are named `<name>__<tool>`, like any other MCP tool.
181
181
 
182
- In an agentic job there is no session of the user, so there is no token of theirs. See [agentic jobs](agentic-jobs.md#internal-mcp-servers-in-a-job).
182
+ In an automation there is no session of the user, so there is no token of theirs. See [automations](automations.md#internal-mcp-servers-in-a-automation).
183
183
 
184
184
  ## Tools of MCP servers
185
185
 
@@ -1,24 +1,27 @@
1
1
  import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
- import { createAgenticJob } from 'openloops/agentic-jobs'
3
+ import { createAutomation } from 'openloops/automations'
4
4
 
5
- async function createJob () {
5
+ async function createSchedule () {
6
6
  const logger = new Logger()
7
7
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
8
8
 
9
- const result = await createAgenticJob({
9
+ const result = await createAutomation({
10
10
  payload: {
11
11
  name: 'Morning report',
12
12
  instructions: 'Summarize the news about the bitcoin price and keep the summary short',
13
- recurrence: { type: 'weekly', days: [1, 2, 3, 4, 5], time: '08:00' },
14
- timezone: 'America/Lima',
13
+ trigger: {
14
+ type: 'schedule',
15
+ recurrence: { type: 'weekly', days: [1, 2, 3, 4, 5], time: '08:00' },
16
+ timezone: 'America/Lima',
17
+ },
15
18
  modelProvider: 'anthropic',
16
19
  modelName: 'claude-haiku-5-5',
17
20
  },
18
21
  currentUser,
19
22
  })
20
23
 
21
- logger.info({ id: result.data._id, nextRunAt: result.data.nextRunAt }, '[Demo] Created agentic job')
24
+ logger.info({ id: result.data._id, nextRunAt: result.data.nextRunAt }, '[Demo] Created automation')
22
25
  }
23
26
 
24
- createJob()
27
+ createSchedule()
@@ -0,0 +1,24 @@
1
+ import { Logger } from 'openloops/common'
2
+ import { CurrentUser } from 'openloops/base'
3
+ import { createAutomation, issueAutomationEventToken } from 'openloops/automations'
4
+
5
+ async function createEventAutomation () {
6
+ const logger = new Logger()
7
+ const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
8
+
9
+ const created = await createAutomation({
10
+ payload: {
11
+ name: 'Cost anomaly analysis',
12
+ instructions: 'Find the cause of the cost alert in AWS and send a short summary to the channel #costs',
13
+ trigger: { type: 'event' },
14
+ },
15
+ currentUser,
16
+ })
17
+
18
+ const id = String(created.data._id)
19
+ const issued = await issueAutomationEventToken({ id, expiresIn: '90d', currentUser })
20
+
21
+ logger.info({ id, token: issued.data.token, expiresAt: issued.data.expiresAt }, '[Demo] Created automation, send events to it with this token')
22
+ }
23
+
24
+ createEventAutomation()
@@ -1,28 +1,28 @@
1
1
  import { Logger } from 'openloops/common'
2
2
  import { CurrentUser } from 'openloops/base'
3
- import { listAgenticJobRunsByJob, listAgenticJobRunsByUser } from 'openloops/agentic-jobs'
3
+ import { listAutomationRunsByAutomation, listAutomationRunsByUser } from 'openloops/automations'
4
4
 
5
- async function listRunsOfAJob () {
5
+ async function listRunsOfAnAutomation () {
6
6
  const logger = new Logger()
7
7
 
8
- const result = await listAgenticJobRunsByJob({
9
- jobId: '6ad0c9a6d3ea4199c9b7ba10',
8
+ const result = await listAutomationRunsByAutomation({
9
+ automationId: '6ad0c9a6d3ea4199c9b7ba10',
10
10
  options: { page: 1, limit: 20 },
11
11
  })
12
12
 
13
- logger.info(result.data.map(run => ({ status: run.status, startedAt: run.startedAt, chatId: run.chatId, error: run.error })), '[Demo] Runs of the job')
13
+ logger.info(result.data.map(run => ({ status: run.status, startedAt: run.startedAt, chatId: run.chatId, error: run.error })), '[Demo] Runs of the automation')
14
14
  }
15
15
 
16
16
  async function listRunsThatNeedAttention () {
17
17
  const logger = new Logger()
18
18
  const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
19
19
 
20
- const paused = await listAgenticJobRunsByUser({ status: 'paused', currentUser })
21
- const failed = await listAgenticJobRunsByUser({ status: 'failed', currentUser })
20
+ const paused = await listAutomationRunsByUser({ status: 'paused', currentUser })
21
+ const failed = await listAutomationRunsByUser({ status: 'failed', currentUser })
22
22
 
23
23
  logger.info({ paused: paused.data.length, failed: failed.data.length }, '[Demo] Runs that need attention')
24
24
  }
25
25
 
26
- listRunsOfAJob()
26
+ listRunsOfAnAutomation()
27
27
 
28
28
  // listRunsThatNeedAttention()
@@ -0,0 +1,25 @@
1
+ import { Logger } from 'openloops/common'
2
+ import { CurrentUser } from 'openloops/base'
3
+ import { listAutomationsByUser } from 'openloops/automations'
4
+
5
+ async function listAutomations () {
6
+ const logger = new Logger()
7
+ const currentUser = await CurrentUser.asyncFromDB('6ab56894eb20887d1ef7942c')
8
+
9
+ const result = await listAutomationsByUser({
10
+ options: {
11
+ page: 1,
12
+ limit: 20,
13
+ },
14
+ currentUser,
15
+ })
16
+
17
+ logger.info(result.data.map(automation => ({
18
+ name: automation.name,
19
+ enabled: automation.enabled,
20
+ nextRunAt: automation.nextRunAt,
21
+ lastRunStatus: automation.lastRunStatus,
22
+ })), '[Demo] Automations')
23
+ }
24
+
25
+ listAutomations()
@@ -1,10 +1,10 @@
1
1
  import { Logger } from 'openloops/common'
2
- import { previewAgenticJobRuns } from 'openloops/agentic-jobs'
2
+ import { previewAutomationRuns } from 'openloops/automations'
3
3
 
4
4
  async function previewRuns () {
5
5
  const logger = new Logger()
6
6
 
7
- const result = await previewAgenticJobRuns({
7
+ const result = await previewAutomationRuns({
8
8
  recurrence: { type: 'monthly', day: 'last', time: '18:00' },
9
9
  timezone: 'America/Lima',
10
10
  count: 5,