openloops 0.3.4 → 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 (240) hide show
  1. package/README.md +9 -8
  2. package/dist/clients/llm/llm-client.js +6 -5
  3. package/dist/clients/llm/llm-client.mjs +6 -5
  4. package/dist/clients/llm/llm-types.d.ts +3 -0
  5. package/dist/clients/llm/llm-types.js +15 -0
  6. package/dist/clients/llm/llm-types.mjs +7 -0
  7. package/dist/db/index.d.ts +1 -0
  8. package/dist/db/index.js +3 -1
  9. package/dist/db/index.mjs +1 -0
  10. package/dist/db/indexes/automation-runs.d.ts +2 -0
  11. package/dist/db/indexes/automation-runs.js +33 -0
  12. package/dist/db/indexes/automation-runs.mjs +10 -0
  13. package/dist/db/indexes/automations.d.ts +2 -0
  14. package/dist/db/indexes/{agentic-jobs.js → automations.js} +6 -6
  15. package/dist/db/indexes/{agentic-jobs.mjs → automations.mjs} +2 -2
  16. package/dist/db/indexes/index.js +6 -4
  17. package/dist/db/indexes/index.mjs +6 -4
  18. package/dist/db/indexes/revoked-tokens.d.ts +2 -0
  19. package/dist/db/indexes/{agentic-job-runs.js → revoked-tokens.js} +8 -9
  20. package/dist/db/indexes/revoked-tokens.mjs +8 -0
  21. package/dist/db/migrations/automations.d.ts +12 -0
  22. package/dist/db/migrations/automations.js +70 -0
  23. package/dist/db/migrations/automations.mjs +47 -0
  24. package/dist/harness/agent-loop.d.ts +2 -0
  25. package/dist/harness/agent.d.ts +1 -0
  26. package/dist/harness/agent.js +8 -0
  27. package/dist/harness/agent.mjs +8 -0
  28. package/dist/loops/agi/loop.js +2 -1
  29. package/dist/loops/agi/loop.mjs +2 -1
  30. package/dist/loops/agi/skills/reasoning-engine.js +3 -2
  31. package/dist/loops/agi/skills/reasoning-engine.mjs +3 -2
  32. package/dist/loops/shared/skills/fast-responder.js +2 -2
  33. package/dist/loops/shared/skills/fast-responder.mjs +2 -2
  34. package/dist/services/authentication/entities/index.d.ts +1 -0
  35. package/dist/services/authentication/entities/index.js +22 -0
  36. package/dist/services/authentication/entities/index.mjs +1 -0
  37. package/dist/services/authentication/entities/revoked-token.entity.d.ts +17 -0
  38. package/dist/services/authentication/entities/revoked-token.entity.js +67 -0
  39. package/dist/services/authentication/entities/revoked-token.entity.mjs +44 -0
  40. package/dist/services/authentication/index.d.ts +1 -0
  41. package/dist/services/authentication/index.js +3 -1
  42. package/dist/services/authentication/index.mjs +1 -0
  43. package/dist/services/authentication/module.d.ts +4 -0
  44. package/dist/services/authentication/module.js +16 -2
  45. package/dist/services/authentication/module.mjs +13 -1
  46. package/dist/services/authentication/repositories/index.d.ts +1 -0
  47. package/dist/services/{agentic-jobs → authentication}/repositories/index.js +2 -4
  48. package/dist/services/authentication/repositories/index.mjs +1 -0
  49. package/dist/services/authentication/repositories/revoked-token.repository.d.ts +7 -0
  50. package/dist/services/authentication/repositories/revoked-token.repository.js +55 -0
  51. package/dist/services/authentication/repositories/revoked-token.repository.mjs +26 -0
  52. package/dist/services/authentication/use-cases/is-token-revoked.use-case.d.ts +15 -0
  53. package/dist/services/authentication/use-cases/is-token-revoked.use-case.js +55 -0
  54. package/dist/services/authentication/use-cases/is-token-revoked.use-case.mjs +26 -0
  55. package/dist/services/authentication/use-cases/revoke-token.use-case.d.ts +14 -0
  56. package/dist/services/authentication/use-cases/revoke-token.use-case.js +65 -0
  57. package/dist/services/authentication/use-cases/revoke-token.use-case.mjs +36 -0
  58. package/dist/services/automations/entities/automation-run.entity.d.ts +46 -0
  59. package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.js → automations/entities/automation-run.entity.js} +22 -14
  60. package/dist/services/{agentic-jobs/entities/agentic-job-run.entity.mjs → automations/entities/automation-run.entity.mjs} +18 -10
  61. package/dist/services/automations/entities/automation.entity.d.ts +38 -0
  62. package/dist/services/{agentic-jobs/entities/agentic-job.entity.js → automations/entities/automation.entity.js} +17 -17
  63. package/dist/services/{agentic-jobs/entities/agentic-job.entity.mjs → automations/entities/automation.entity.mjs} +13 -13
  64. package/dist/services/automations/entities/index.d.ts +4 -0
  65. package/dist/services/{agentic-jobs → automations}/entities/index.js +6 -4
  66. package/dist/services/automations/entities/index.mjs +4 -0
  67. package/dist/services/automations/entities/trigger.d.ts +11 -0
  68. package/dist/services/automations/entities/trigger.js +49 -0
  69. package/dist/services/automations/entities/trigger.mjs +26 -0
  70. package/dist/services/automations/index.d.ts +5 -0
  71. package/dist/services/{agentic-jobs → automations}/index.js +9 -7
  72. package/dist/services/automations/index.mjs +5 -0
  73. package/dist/services/automations/module.d.ts +41 -0
  74. package/dist/services/automations/module.js +167 -0
  75. package/dist/services/automations/module.mjs +125 -0
  76. package/dist/services/automations/repositories/automation-run.repository.d.ts +14 -0
  77. package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.js → automations/repositories/automation-run.repository.js} +23 -11
  78. package/dist/services/{agentic-jobs/repositories/agentic-job-run.repository.mjs → automations/repositories/automation-run.repository.mjs} +19 -7
  79. package/dist/services/automations/repositories/automation.repository.d.ts +27 -0
  80. package/dist/services/{agentic-jobs/repositories/agentic-job.repository.js → automations/repositories/automation.repository.js} +17 -17
  81. package/dist/services/{agentic-jobs/repositories/agentic-job.repository.mjs → automations/repositories/automation.repository.mjs} +13 -13
  82. package/dist/services/automations/repositories/index.d.ts +2 -0
  83. package/dist/services/automations/repositories/index.js +24 -0
  84. package/dist/services/automations/repositories/index.mjs +2 -0
  85. package/dist/services/automations/runner/automation-runner.d.ts +49 -0
  86. package/dist/services/{agentic-jobs/runner/agentic-job-runner.js → automations/runner/automation-runner.js} +55 -45
  87. package/dist/services/{agentic-jobs/runner/agentic-job-runner.mjs → automations/runner/automation-runner.mjs} +50 -40
  88. 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
  89. 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
  90. package/dist/services/automations/use-cases/attach-automation-run-chat.use-case.mjs +29 -0
  91. package/dist/services/automations/use-cases/claim-due-automations.use-case.d.ts +28 -0
  92. 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
  93. package/dist/services/automations/use-cases/claim-due-automations.use-case.mjs +70 -0
  94. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.d.ts +27 -0
  95. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.js +106 -0
  96. package/dist/services/automations/use-cases/claim-queued-automation-runs.use-case.mjs +77 -0
  97. package/dist/services/automations/use-cases/create-automation.use-case.d.ts +14 -0
  98. package/dist/services/{agentic-jobs/use-cases/create-agentic-job.use-case.js → automations/use-cases/create-automation.use-case.js} +24 -25
  99. package/dist/services/automations/use-cases/create-automation.use-case.mjs +43 -0
  100. 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
  101. package/dist/services/{agentic-jobs/use-cases/delete-agentic-job.use-case.js → automations/use-cases/delete-automation.use-case.js} +17 -17
  102. package/dist/services/automations/use-cases/delete-automation.use-case.mjs +36 -0
  103. 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
  104. 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
  105. package/dist/services/automations/use-cases/finish-automation-run.use-case.mjs +46 -0
  106. 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
  107. 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
  108. package/dist/services/automations/use-cases/get-automation-by-id.use-case.mjs +26 -0
  109. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.d.ts +17 -0
  110. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.js +59 -0
  111. package/dist/services/automations/use-cases/issue-automation-event-token.use-case.mjs +30 -0
  112. 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
  113. 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
  114. package/dist/services/automations/use-cases/list-automation-runs-by-automation.use-case.mjs +28 -0
  115. 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
  116. 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
  117. 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
  118. 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
  119. 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
  120. 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
  121. 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
  122. 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
  123. 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
  124. package/dist/services/automations/use-cases/receive-automation-event.use-case.d.ts +23 -0
  125. package/dist/services/automations/use-cases/receive-automation-event.use-case.js +97 -0
  126. package/dist/services/automations/use-cases/receive-automation-event.use-case.mjs +68 -0
  127. 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
  128. 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
  129. package/dist/services/automations/use-cases/renew-automation-lease.use-case.mjs +29 -0
  130. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.d.ts +16 -0
  131. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.js +65 -0
  132. package/dist/services/automations/use-cases/revoke-automation-event-token.use-case.mjs +36 -0
  133. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.d.ts +14 -0
  134. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.js +63 -0
  135. package/dist/services/automations/use-cases/rotate-automation-event-tokens.use-case.mjs +34 -0
  136. package/dist/services/automations/use-cases/start-automation-run.use-case.d.ts +21 -0
  137. 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
  138. package/dist/services/automations/use-cases/start-automation-run.use-case.mjs +38 -0
  139. package/dist/services/automations/use-cases/sync-automation-run.use-case.d.ts +20 -0
  140. 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
  141. 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
  142. 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
  143. 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
  144. 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
  145. package/dist/services/automations/use-cases/update-automation.use-case.d.ts +15 -0
  146. package/dist/services/{agentic-jobs/use-cases/update-agentic-job.use-case.js → automations/use-cases/update-automation.use-case.js} +27 -27
  147. package/dist/services/automations/use-cases/update-automation.use-case.mjs +54 -0
  148. package/dist/services/automations/utils/automation-event-error.d.ts +6 -0
  149. package/dist/services/automations/utils/automation-event-error.js +37 -0
  150. package/dist/services/automations/utils/automation-event-error.mjs +14 -0
  151. package/dist/services/automations/utils/automation-fields.d.ts +14 -0
  152. package/dist/services/{agentic-jobs/utils/job-fields.js → automations/utils/automation-fields.js} +8 -10
  153. package/dist/services/{agentic-jobs/utils/job-fields.mjs → automations/utils/automation-fields.mjs} +4 -6
  154. package/dist/services/automations/utils/event-message.d.ts +1 -0
  155. package/dist/services/automations/utils/event-message.js +37 -0
  156. package/dist/services/automations/utils/event-message.mjs +14 -0
  157. package/dist/services/automations/utils/event-token.d.ts +18 -0
  158. package/dist/services/automations/utils/event-token.js +78 -0
  159. package/dist/services/automations/utils/event-token.mjs +43 -0
  160. package/dist/services/automations/utils/open-run.d.ts +14 -0
  161. package/dist/services/{agentic-jobs → automations}/utils/open-run.js +10 -8
  162. package/dist/services/automations/utils/open-run.mjs +26 -0
  163. package/dist/services/automations/utils/previous-run.d.ts +4 -0
  164. package/dist/services/automations/utils/previous-run.js +42 -0
  165. package/dist/services/automations/utils/previous-run.mjs +19 -0
  166. package/dist/services/{agentic-jobs → automations}/utils/settings.d.ts +1 -0
  167. package/dist/services/{agentic-jobs → automations}/utils/settings.js +6 -2
  168. package/dist/services/automations/utils/settings.mjs +13 -0
  169. package/dist/services/chats/entities/chat-settings.entity.d.ts +5 -1
  170. package/dist/services/chats/entities/chat-settings.entity.js +10 -3
  171. package/dist/services/chats/entities/chat-settings.entity.mjs +10 -3
  172. package/dist/skills/skill.d.ts +2 -1
  173. package/dist/skills/skill.js +4 -3
  174. package/dist/skills/skill.mjs +4 -3
  175. package/docs/README.md +1 -1
  176. package/docs/agent.md +3 -2
  177. package/docs/authentication.md +18 -1
  178. package/docs/automations.md +341 -0
  179. package/docs/chats.md +1 -1
  180. package/docs/configuration.md +8 -7
  181. package/docs/harness.md +1 -1
  182. package/docs/integration-guide.md +22 -18
  183. package/docs/llms.txt +1 -1
  184. package/docs/mcp-servers.md +1 -1
  185. package/docs/skills.md +1 -1
  186. package/examples/{agentic-jobs/create-agentic-job.ts → automations/create-automation.ts} +10 -7
  187. package/examples/automations/create-event-automation.ts +24 -0
  188. package/examples/{agentic-jobs/list-agentic-job-runs.ts → automations/list-automation-runs.ts} +8 -8
  189. package/examples/automations/list-automations.ts +25 -0
  190. package/examples/{agentic-jobs/preview-agentic-job-runs.ts → automations/preview-automation-runs.ts} +2 -2
  191. package/examples/automations/receive-automation-event.ts +26 -0
  192. package/examples/automations/revoke-automation-event-token.ts +25 -0
  193. package/examples/{agentic-jobs/run-agentic-job-now.ts → automations/run-automation-now.ts} +3 -3
  194. package/examples/{agentic-jobs/run-agentic-job-worker.ts → automations/run-automation-worker.ts} +6 -6
  195. package/examples/{agentic-jobs/update-agentic-job.ts → automations/update-automation.ts} +10 -10
  196. package/package.json +14 -13
  197. package/dist/db/indexes/agentic-job-runs.d.ts +0 -2
  198. package/dist/db/indexes/agentic-job-runs.mjs +0 -9
  199. package/dist/db/indexes/agentic-jobs.d.ts +0 -2
  200. package/dist/services/agentic-jobs/entities/agentic-job-run.entity.d.ts +0 -42
  201. package/dist/services/agentic-jobs/entities/agentic-job.entity.d.ts +0 -39
  202. package/dist/services/agentic-jobs/entities/index.d.ts +0 -3
  203. package/dist/services/agentic-jobs/entities/index.mjs +0 -3
  204. package/dist/services/agentic-jobs/index.d.ts +0 -4
  205. package/dist/services/agentic-jobs/index.mjs +0 -4
  206. package/dist/services/agentic-jobs/module.d.ts +0 -31
  207. package/dist/services/agentic-jobs/module.js +0 -132
  208. package/dist/services/agentic-jobs/module.mjs +0 -95
  209. package/dist/services/agentic-jobs/repositories/agentic-job-run.repository.d.ts +0 -11
  210. package/dist/services/agentic-jobs/repositories/agentic-job.repository.d.ts +0 -27
  211. package/dist/services/agentic-jobs/repositories/index.d.ts +0 -2
  212. package/dist/services/agentic-jobs/repositories/index.mjs +0 -2
  213. package/dist/services/agentic-jobs/runner/agentic-job-runner.d.ts +0 -48
  214. package/dist/services/agentic-jobs/use-cases/attach-agentic-job-run-chat.use-case.mjs +0 -29
  215. package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.d.ts +0 -29
  216. package/dist/services/agentic-jobs/use-cases/claim-due-agentic-jobs.use-case.mjs +0 -81
  217. package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.d.ts +0 -14
  218. package/dist/services/agentic-jobs/use-cases/create-agentic-job.use-case.mjs +0 -44
  219. package/dist/services/agentic-jobs/use-cases/delete-agentic-job.use-case.mjs +0 -36
  220. package/dist/services/agentic-jobs/use-cases/finish-agentic-job-run.use-case.mjs +0 -46
  221. package/dist/services/agentic-jobs/use-cases/get-agentic-job-by-id.use-case.mjs +0 -26
  222. package/dist/services/agentic-jobs/use-cases/list-agentic-job-runs-by-job.use-case.mjs +0 -28
  223. package/dist/services/agentic-jobs/use-cases/renew-agentic-job-lease.use-case.mjs +0 -29
  224. package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.d.ts +0 -21
  225. package/dist/services/agentic-jobs/use-cases/start-agentic-job-run.use-case.mjs +0 -38
  226. package/dist/services/agentic-jobs/use-cases/sync-agentic-job-run.use-case.d.ts +0 -20
  227. package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.d.ts +0 -15
  228. package/dist/services/agentic-jobs/use-cases/update-agentic-job.use-case.mjs +0 -54
  229. package/dist/services/agentic-jobs/utils/job-fields.d.ts +0 -14
  230. package/dist/services/agentic-jobs/utils/open-run.d.ts +0 -12
  231. package/dist/services/agentic-jobs/utils/open-run.mjs +0 -24
  232. package/dist/services/agentic-jobs/utils/settings.mjs +0 -10
  233. package/docs/agentic-jobs.md +0 -217
  234. package/examples/agentic-jobs/list-agentic-jobs.ts +0 -25
  235. /package/dist/services/{agentic-jobs → automations}/entities/recurrence.d.ts +0 -0
  236. /package/dist/services/{agentic-jobs → automations}/entities/recurrence.js +0 -0
  237. /package/dist/services/{agentic-jobs → automations}/entities/recurrence.mjs +0 -0
  238. /package/dist/services/{agentic-jobs → automations}/utils/next-run.d.ts +0 -0
  239. /package/dist/services/{agentic-jobs → automations}/utils/next-run.js +0 -0
  240. /package/dist/services/{agentic-jobs → automations}/utils/next-run.mjs +0 -0
@@ -1,6 +1,6 @@
1
1
  import "../../../chunk-CF3WOMB3.mjs";
2
2
  class ChatSettings {
3
- constructor(props, notifyOnCompletion, isPrivateSession, modelProvider, modelName, loopName, executionMode) {
3
+ constructor(props, notifyOnCompletion, isPrivateSession, modelProvider, modelName, loopName, executionMode, thinkingEffort) {
4
4
  this.props = props;
5
5
  this.notifyOnCompletion = notifyOnCompletion;
6
6
  this.isPrivateSession = isPrivateSession;
@@ -8,6 +8,7 @@ class ChatSettings {
8
8
  this.modelName = modelName;
9
9
  this.loopName = loopName;
10
10
  this.executionMode = executionMode;
11
+ this.thinkingEffort = thinkingEffort;
11
12
  }
12
13
  props;
13
14
  notifyOnCompletion;
@@ -16,6 +17,7 @@ class ChatSettings {
16
17
  modelName;
17
18
  loopName;
18
19
  executionMode;
20
+ thinkingEffort;
19
21
  static fromJSON(props) {
20
22
  return new ChatSettings(
21
23
  props,
@@ -24,7 +26,8 @@ class ChatSettings {
24
26
  props.modelProvider,
25
27
  props.modelName,
26
28
  props.loopName,
27
- props.executionMode
29
+ props.executionMode,
30
+ props.thinkingEffort
28
31
  );
29
32
  }
30
33
  toJSON() {
@@ -34,7 +37,8 @@ class ChatSettings {
34
37
  modelProvider: this.modelProvider,
35
38
  modelName: this.modelName,
36
39
  loopName: this.loopName,
37
- executionMode: this.executionMode
40
+ executionMode: this.executionMode,
41
+ thinkingEffort: this.thinkingEffort
38
42
  };
39
43
  }
40
44
  setLoopName(loopName) {
@@ -43,6 +47,9 @@ class ChatSettings {
43
47
  setExecutionMode(executionMode) {
44
48
  this.executionMode = executionMode;
45
49
  }
50
+ setThinkingEffort(thinkingEffort) {
51
+ this.thinkingEffort = thinkingEffort;
52
+ }
46
53
  setModelProvider(modelProvider) {
47
54
  this.modelProvider = modelProvider;
48
55
  }
@@ -32,6 +32,7 @@ export interface SkillRunOptions<TInput = Record<string, any>> {
32
32
  chatHistory?: ChatTurn[];
33
33
  tools?: LLMToolDefinition[];
34
34
  mode?: SkillMode;
35
+ thinking?: ThinkingEffort;
35
36
  }
36
37
  export interface SkillCallInfo {
37
38
  skill: string;
@@ -47,7 +48,7 @@ export declare class Skill<TResponse = Record<string, any>> {
47
48
  readonly version?: string;
48
49
  readonly description?: string;
49
50
  readonly temperature?: number;
50
- readonly thinking?: ThinkingEffort;
51
+ readonly thinking: ThinkingEffort;
51
52
  readonly systemInstructions: Record<string, any>;
52
53
  readonly systemRole: boolean;
53
54
  readonly mode: SkillMode;
@@ -31,6 +31,7 @@ var import_runtime_context = require("./runtime-context");
31
31
  var import_call_modes = require("./call-modes");
32
32
  var import_call_modes2 = require("./call-modes");
33
33
  const RAW_RESPONSE_CHARS = 300;
34
+ const DEFAULT_THINKING_EFFORT = "low";
34
35
  const RESERVED_CONTEXT_KEYS = ["tools", "mode", "history", "chatHistory"];
35
36
  class Skill {
36
37
  name;
@@ -46,13 +47,13 @@ class Skill {
46
47
  this.version = props.version;
47
48
  this.description = props.description;
48
49
  this.temperature = props.temperature;
49
- this.thinking = props.thinking;
50
+ this.thinking = props.thinking ?? DEFAULT_THINKING_EFFORT;
50
51
  this.systemInstructions = props.systemInstructions;
51
52
  this.systemRole = props.systemRole ?? true;
52
53
  this.mode = props.mode ?? import_call_modes.DEFAULT_SKILL_MODE;
53
54
  }
54
55
  async run(options) {
55
- const { provider, modelName, sessionId, answerId, userMessage, currentUser, currentSession, contextInjection = {}, input = {}, chat, history = [], chatHistory = [], tools, mode = this.mode } = options;
56
+ const { provider, modelName, sessionId, answerId, userMessage, currentUser, currentSession, contextInjection = {}, input = {}, chat, history = [], chatHistory = [], tools, mode = this.mode, thinking = this.thinking } = options;
56
57
  const misplaced = RESERVED_CONTEXT_KEYS.filter((key) => key in contextInjection);
57
58
  if (misplaced.length) throw new Error(`[SKILL:${this.name}] ${misplaced.join(", ")} must be passed as run options, not inside contextInjection`);
58
59
  if (history.length && chatHistory.length) throw new Error(`[SKILL:${this.name}] history and chatHistory cannot be used together`);
@@ -81,7 +82,7 @@ class Skill {
81
82
  tools: call.tools,
82
83
  toolChoice: call.toolChoice,
83
84
  temperature: this.temperature ?? 0.7,
84
- ...this.thinking ? { thinking: this.thinking } : {}
85
+ thinking
85
86
  });
86
87
  const reading = (0, import_call_modes.readModeResponse)(mode, this.name, response, { expectActions: Boolean(tools?.length) });
87
88
  if (reading.blocks > 1) {
@@ -7,6 +7,7 @@ import { buildRuntimeContext } from "./runtime-context";
7
7
  import { DEFAULT_SKILL_MODE, buildModeCall, readModeResponse } from "./call-modes";
8
8
  import { SkillMode as SkillMode2, DEFAULT_SKILL_MODE as DEFAULT_SKILL_MODE2 } from "./call-modes";
9
9
  const RAW_RESPONSE_CHARS = 300;
10
+ const DEFAULT_THINKING_EFFORT = "low";
10
11
  const RESERVED_CONTEXT_KEYS = ["tools", "mode", "history", "chatHistory"];
11
12
  class Skill {
12
13
  name;
@@ -22,13 +23,13 @@ class Skill {
22
23
  this.version = props.version;
23
24
  this.description = props.description;
24
25
  this.temperature = props.temperature;
25
- this.thinking = props.thinking;
26
+ this.thinking = props.thinking ?? DEFAULT_THINKING_EFFORT;
26
27
  this.systemInstructions = props.systemInstructions;
27
28
  this.systemRole = props.systemRole ?? true;
28
29
  this.mode = props.mode ?? DEFAULT_SKILL_MODE;
29
30
  }
30
31
  async run(options) {
31
- const { provider, modelName, sessionId, answerId, userMessage, currentUser, currentSession, contextInjection = {}, input = {}, chat, history = [], chatHistory = [], tools, mode = this.mode } = options;
32
+ const { provider, modelName, sessionId, answerId, userMessage, currentUser, currentSession, contextInjection = {}, input = {}, chat, history = [], chatHistory = [], tools, mode = this.mode, thinking = this.thinking } = options;
32
33
  const misplaced = RESERVED_CONTEXT_KEYS.filter((key) => key in contextInjection);
33
34
  if (misplaced.length) throw new Error(`[SKILL:${this.name}] ${misplaced.join(", ")} must be passed as run options, not inside contextInjection`);
34
35
  if (history.length && chatHistory.length) throw new Error(`[SKILL:${this.name}] history and chatHistory cannot be used together`);
@@ -57,7 +58,7 @@ class Skill {
57
58
  tools: call.tools,
58
59
  toolChoice: call.toolChoice,
59
60
  temperature: this.temperature ?? 0.7,
60
- ...this.thinking ? { thinking: this.thinking } : {}
61
+ thinking
61
62
  });
62
63
  const reading = readModeResponse(mode, this.name, response, { expectActions: Boolean(tools?.length) });
63
64
  if (reading.blocks > 1) {
package/docs/README.md CHANGED
@@ -14,7 +14,7 @@ Start with the [README](../README.md) for what `openloops` is and how to run it.
14
14
  | --- | --- |
15
15
  | [The `Agent`](agent.md) | Options, running a turn, the result and its statuses, confirmations, autonomous mode, hooks and interruption. |
16
16
  | [Configuration](configuration.md) | Environment variables, choosing the model and what is recorded. |
17
- | [Agentic jobs](agentic-jobs.md) | Tasks that the agent runs by itself on a schedule: recurrence, the history of runs and the runner that executes them. |
17
+ | [Automations](automations.md) | Tasks that the agent runs by itself, on a schedule or when an event arrives: triggers, tokens, the queue, the history of runs and the runner that executes them. |
18
18
  | [Chats](chats.md) | The chat record, its messages and their `source`, listing, reading and deleting chats. |
19
19
 
20
20
  ## Shape how the agent works
package/docs/agent.md CHANGED
@@ -64,6 +64,7 @@ Omit `chatId` to start a brand-new chat. Pass an existing `chatId` to continue a
64
64
  | Option | What it does |
65
65
  | --- | --- |
66
66
  | `modelProvider`, `modelName` | Model for this run, always together. It is saved in the chat and used by the next runs that do not send one. Without it, the model comes from the chat, the preference of the user and the fallbacks. See [configuration](configuration.md#which-model-a-chat-uses). |
67
+ | `thinkingEffort` | `low`, `medium` or `high`: how much the reasoning engine thinks before each response. Any other value makes the run fail before calling the model. It is saved in the chat only when you send it, and the next runs that do not send one reuse it. Without it, the reasoning engine uses `medium`. `high` is slower, so its model calls get twice the time limit (see [Timeouts](configuration.md#timeouts)). It does not change the fast responder, which always uses `low`. |
67
68
  | `loopName` | Name of the loop driving the chat. Set automatically from the loop. |
68
69
  | `executionMode` | `interactive` (default) or `autonomous`. See [Autonomous mode](#autonomous-mode). |
69
70
  | `notifyOnCompletion` | Exposed as `agent.notifyOnCompletion` so a post execution hook can notify the user. |
@@ -71,7 +72,7 @@ Omit `chatId` to start a brand-new chat. Pass an existing `chatId` to continue a
71
72
 
72
73
  `currentSession` is optional. It carries device, location and locale, which skills use to answer in the right time zone and language.
73
74
 
74
- `mcpTokens` is optional. It gives the token of the user to each [internal MCP server](mcp-servers.md#internal-mcp-servers), by name. It is never saved. `serviceToken` is the token that the runner of [agentic jobs](agentic-jobs.md#internal-mcp-servers-in-a-job) passes when there is no session of the user. You do not need it unless you write your own scheduler.
75
+ `mcpTokens` is optional. It gives the token of the user to each [internal MCP server](mcp-servers.md#internal-mcp-servers), by name. It is never saved. `serviceToken` is the token that the runner of [automations](automations.md#internal-mcp-servers-in-a-automation) passes when there is no session of the user. You do not need it unless you write your own scheduler.
75
76
 
76
77
  ## Autonomous mode
77
78
 
@@ -99,7 +100,7 @@ The mode is saved in `chat.settings.executionMode` when the chat is created and
99
100
 
100
101
  Only `AgiLoop` supports autonomous mode.
101
102
 
102
- To run an agent on a schedule, see [agentic jobs](agentic-jobs.md).
103
+ To run an agent on a schedule, see [automations](automations.md).
103
104
 
104
105
  ## The result
105
106
 
@@ -3,7 +3,7 @@
3
3
  `openloops` can log a user in against its own user records and issue a token. Verifying that token on each request, and deciding who may call what, is up to your backend.
4
4
 
5
5
  ```typescript
6
- import { login } from 'openloops/authentication'
6
+ import { login, revokeToken, isTokenRevoked } from 'openloops/authentication'
7
7
  ```
8
8
 
9
9
  ## Logging in
@@ -38,3 +38,20 @@ const currentUser = await CurrentUser.asyncFromDB(payload.userId)
38
38
  ```
39
39
 
40
40
  See [users](users.md).
41
+
42
+ ## Revoked tokens
43
+
44
+ A signed token cannot be taken back, so `openloops` keeps a list of the ids (`jti`) of the tokens that must stop working, in the collection `revoked_tokens`.
45
+
46
+ ```typescript
47
+ await revokeToken({ payload: { jti, audience: 'automation-event', subject: automationId, expiresAt }, currentUser })
48
+
49
+ const { data } = await isTokenRevoked({ jti })
50
+
51
+ data.revoked
52
+ ```
53
+
54
+ - Revoking the same `jti` twice does nothing. `expiresAt` is optional: when it is set, the entry is deleted by itself on that date, which is when the token would have stopped working anyway.
55
+ - Today only the tokens of [event automations](automations.md#the-token) use it, through `revokeAutomationEventToken`, and the use case of events checks the list for you.
56
+ - The tokens of `login` carry no `jti`, and `openloops` does not verify them, your backend does. To revoke sessions you would add a `jti` when the token is signed and call `isTokenRevoked` in the middleware of your backend. That is not done by the package.
57
+
@@ -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.
package/docs/chats.md CHANGED
@@ -11,7 +11,7 @@ import { createChat, getChatById, listChatsByUser, updateChat, deleteChat } from
11
11
  | Field | Meaning |
12
12
  | --- | --- |
13
13
  | `state` | `status`, detected `language`, `activeTaskId`, `lastError` and `stopRequested`. See [agent](agent.md#the-result) for the statuses. It also has `currentActivity`, which is deprecated (see below). |
14
- | `settings` | `modelProvider` and `modelName` (the model the chat uses, saved on every run), `loopName`, `executionMode`, `notifyOnCompletion` and `isPrivateSession`. |
14
+ | `settings` | `modelProvider` and `modelName` (the model the chat uses, saved on every run), `thinkingEffort` (only when a run sent it), `loopName`, `executionMode`, `notifyOnCompletion` and `isPrivateSession`. |
15
15
  | `messages` | The conversation. Each message has `role` (`user` or `assistant`), `source`, `content`, `answerId` and `excludeFromContext`. |
16
16
 
17
17
  ### `state.currentActivity` is deprecated
@@ -10,14 +10,15 @@
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
- | `LLM_CALL_TIMEOUT_MS` | no | Longest time to wait for one attempt of a model call, in milliseconds. Defaults to `60000`. See [Timeouts](#timeouts). |
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). |
22
23
  | `SENTRY_DSN` | no | Errors are reported to Sentry when set, unless `IS_LOCAL` is `true` or `NODE_ENV` is `development`. |
23
24
  | `LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_BASE_URL` | no | Traces every LLM call in Langfuse when all three are set. |
@@ -57,7 +58,7 @@ It is in the low price tier, it makes the most of the prompt cache, which matter
57
58
 
58
59
  A model call that never answers would block the whole run, so every attempt has a time limit:
59
60
 
60
- - **Model calls.** An attempt that does not answer within `LLM_CALL_TIMEOUT_MS` (60 seconds by default) is cancelled and the same call is made again, up to 3 attempts in total. When all of them time out, the run fails with the error code `LLM_TIMEOUT` and a message for the user, and the chat is left as `failed` so the user can send the message again. Waiting for a provider that asks to slow down is a separate mechanism and is not affected.
61
+ - **Model calls.** An attempt that does not answer within `LLM_CALL_TIMEOUT_MS` (60 seconds by default) is cancelled and the same call is made again, up to 3 attempts in total. A call with the `high` thinking effort, which thinks for longer, gets twice that time. When all of them time out, the run fails with the error code `LLM_TIMEOUT` and a message for the user, and the chat is left as `failed` so the user can send the message again. Waiting for a provider that asks to slow down is a separate mechanism and is not affected.
61
62
  - **Tools of MCP servers.** A tool that does not answer within `MCP_TOOL_TIMEOUT_MS` (60 seconds by default) fails. The time starts again every time the server reports progress, so a long tool that is alive is not cut off. A tool call is never repeated automatically, because it may have changed something. The model is told that the result is unknown and that it must check before repeating it.
62
63
  - **Langfuse.** Sending the trace of a call to Langfuse waits at most 5 seconds. If it takes longer or fails, the run continues without it.
63
64
 
@@ -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