workflow 5.0.0-beta.5 → 5.0.0-beta.51

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 (256) hide show
  1. package/README.md +68 -23
  2. package/dist/api-workflow.d.ts +1 -1
  3. package/dist/api-workflow.d.ts.map +1 -1
  4. package/dist/api-workflow.js +1 -1
  5. package/dist/api.d.ts +3 -3
  6. package/dist/api.d.ts.map +1 -1
  7. package/dist/api.js +5 -7
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +6 -1
  11. package/dist/internal/builtins.d.ts +20 -3
  12. package/dist/internal/builtins.d.ts.map +1 -1
  13. package/dist/internal/builtins.js +68 -4
  14. package/dist/internal/errors.d.ts +1 -1
  15. package/dist/internal/errors.d.ts.map +1 -1
  16. package/dist/internal/errors.js +2 -2
  17. package/dist/nest-builder.d.ts +2 -0
  18. package/dist/nest-builder.d.ts.map +1 -0
  19. package/dist/nest-builder.js +2 -0
  20. package/dist/nest-vercel-builder.d.ts +2 -0
  21. package/dist/nest-vercel-builder.d.ts.map +1 -0
  22. package/dist/nest-vercel-builder.js +2 -0
  23. package/dist/observability.d.ts +1 -1
  24. package/dist/observability.js +2 -2
  25. package/dist/runtime.d.ts +2 -1
  26. package/dist/runtime.d.ts.map +1 -1
  27. package/dist/runtime.js +4 -1
  28. package/docs/ai/chat-session-modeling.mdx +176 -422
  29. package/docs/ai/defining-tools.mdx +6 -7
  30. package/docs/ai/human-in-the-loop.mdx +11 -11
  31. package/docs/ai/index.mdx +71 -75
  32. package/docs/ai/message-queueing.mdx +71 -110
  33. package/docs/ai/meta.json +1 -0
  34. package/docs/ai/resumable-streams.mdx +40 -28
  35. package/docs/ai/sleep-and-delays.mdx +10 -10
  36. package/docs/ai/streaming-updates-from-tools.mdx +6 -6
  37. package/docs/api-reference/index.mdx +25 -1
  38. package/docs/api-reference/meta.json +8 -0
  39. package/docs/api-reference/vitest/index.mdx +9 -15
  40. package/docs/api-reference/workflow/create-hook.mdx +89 -10
  41. package/docs/api-reference/workflow/create-webhook.mdx +16 -15
  42. package/docs/api-reference/workflow/define-hook.mdx +35 -33
  43. package/docs/api-reference/workflow/fatal-error.mdx +30 -8
  44. package/docs/api-reference/workflow/fetch.mdx +14 -10
  45. package/docs/api-reference/workflow/get-step-metadata.mdx +2 -2
  46. package/docs/api-reference/workflow/get-workflow-metadata.mdx +3 -3
  47. package/docs/api-reference/workflow/get-writable.mdx +7 -7
  48. package/docs/api-reference/workflow/index.mdx +4 -1
  49. package/docs/api-reference/workflow/retryable-error.mdx +1 -1
  50. package/docs/api-reference/workflow/set-attributes.mdx +61 -0
  51. package/docs/api-reference/workflow/sleep.mdx +4 -4
  52. package/docs/api-reference/workflow-ai/durable-agent.mdx +63 -101
  53. package/docs/api-reference/workflow-ai/index.mdx +5 -5
  54. package/docs/api-reference/workflow-ai/workflow-chat-transport.mdx +67 -24
  55. package/docs/api-reference/workflow-api/get-hook-by-token.mdx +26 -12
  56. package/docs/api-reference/workflow-api/get-run.mdx +43 -8
  57. package/docs/api-reference/workflow-api/index.mdx +6 -10
  58. package/docs/api-reference/workflow-api/resume-hook.mdx +73 -12
  59. package/docs/api-reference/workflow-api/resume-webhook.mdx +11 -9
  60. package/docs/api-reference/workflow-api/start.mdx +60 -13
  61. package/docs/api-reference/workflow-astro/index.mdx +18 -0
  62. package/docs/api-reference/workflow-astro/meta.json +4 -0
  63. package/docs/api-reference/workflow-astro/workflow.mdx +45 -0
  64. package/docs/api-reference/workflow-errors/entity-conflict-error.mdx +4 -4
  65. package/docs/api-reference/workflow-errors/hook-conflict-error.mdx +60 -0
  66. package/docs/api-reference/workflow-errors/hook-not-found-error.mdx +8 -8
  67. package/docs/api-reference/workflow-errors/index.mdx +88 -0
  68. package/docs/api-reference/workflow-errors/meta.json +6 -0
  69. package/docs/api-reference/workflow-errors/precondition-failed-error.mdx +68 -0
  70. package/docs/api-reference/workflow-errors/run-expired-error.mdx +2 -2
  71. package/docs/api-reference/workflow-errors/run-not-supported-error.mdx +58 -0
  72. package/docs/api-reference/workflow-errors/step-not-registered-error.mdx +5 -5
  73. package/docs/api-reference/workflow-errors/throttle-error.mdx +2 -2
  74. package/docs/api-reference/workflow-errors/too-early-error.mdx +2 -2
  75. package/docs/api-reference/workflow-errors/workflow-error.mdx +52 -0
  76. package/docs/api-reference/workflow-errors/workflow-not-registered-error.mdx +5 -6
  77. package/docs/api-reference/workflow-errors/workflow-run-cancelled-error.mdx +6 -6
  78. package/docs/api-reference/workflow-errors/workflow-run-failed-error.mdx +5 -5
  79. package/docs/api-reference/workflow-errors/workflow-run-not-completed-error.mdx +58 -0
  80. package/docs/api-reference/workflow-errors/workflow-run-not-found-error.mdx +4 -4
  81. package/docs/api-reference/workflow-errors/workflow-runtime-error.mdx +58 -0
  82. package/docs/api-reference/workflow-errors/workflow-world-error.mdx +8 -8
  83. package/docs/api-reference/workflow-globals.mdx +14 -10
  84. package/docs/api-reference/workflow-nest/configure-workflow-controller.mdx +33 -0
  85. package/docs/api-reference/workflow-nest/index.mdx +31 -0
  86. package/docs/api-reference/workflow-nest/meta.json +9 -0
  87. package/docs/api-reference/workflow-nest/nest-local-builder.mdx +64 -0
  88. package/docs/api-reference/workflow-nest/workflow-controller.mdx +40 -0
  89. package/docs/api-reference/workflow-nest/workflow-module.mdx +74 -0
  90. package/docs/api-reference/workflow-next/with-workflow.mdx +39 -17
  91. package/docs/api-reference/workflow-nitro/index.mdx +60 -0
  92. package/docs/api-reference/workflow-nuxt/index.mdx +48 -0
  93. package/docs/api-reference/workflow-observability/hydrate-data.mdx +35 -0
  94. package/docs/api-reference/workflow-observability/hydrate-resource-io.mdx +62 -0
  95. package/docs/api-reference/workflow-observability/index.mdx +62 -0
  96. package/docs/api-reference/workflow-observability/meta.json +11 -0
  97. package/docs/api-reference/workflow-observability/observability-revivers.mdx +50 -0
  98. package/docs/api-reference/workflow-observability/parse-class-name.mdx +41 -0
  99. package/docs/api-reference/workflow-observability/parse-step-name.mdx +40 -0
  100. package/docs/api-reference/workflow-observability/parse-workflow-name.mdx +55 -0
  101. package/docs/api-reference/workflow-runtime/create-world.mdx +39 -0
  102. package/docs/api-reference/workflow-runtime/get-world-handlers.mdx +44 -0
  103. package/docs/api-reference/{workflow-api → workflow-runtime}/get-world.mdx +11 -14
  104. package/docs/api-reference/workflow-runtime/health-check.mdx +50 -0
  105. package/docs/api-reference/workflow-runtime/index.mdx +41 -0
  106. package/docs/api-reference/workflow-runtime/meta.json +12 -0
  107. package/docs/api-reference/workflow-runtime/set-world.mdx +51 -0
  108. package/docs/api-reference/workflow-runtime/workflow-entrypoint.mdx +43 -0
  109. package/docs/api-reference/workflow-runtime/world/analytics.mdx +315 -0
  110. package/docs/api-reference/workflow-runtime/world/index.mdx +60 -0
  111. package/docs/api-reference/workflow-runtime/world/meta.json +4 -0
  112. package/docs/api-reference/workflow-runtime/world/queue.mdx +88 -0
  113. package/docs/api-reference/{workflow-api → workflow-runtime}/world/storage.mdx +98 -34
  114. package/docs/api-reference/{workflow-api → workflow-runtime}/world/streams.mdx +8 -8
  115. package/docs/api-reference/workflow-serde/index.mdx +1 -2
  116. package/docs/api-reference/workflow-serde/workflow-deserialize.mdx +3 -4
  117. package/docs/api-reference/workflow-serde/workflow-serialize.mdx +8 -8
  118. package/docs/api-reference/workflow-sveltekit/index.mdx +18 -0
  119. package/docs/api-reference/workflow-sveltekit/meta.json +4 -0
  120. package/docs/api-reference/workflow-sveltekit/workflow-plugin.mdx +42 -0
  121. package/docs/api-reference/workflow-vite/index.mdx +18 -0
  122. package/docs/api-reference/workflow-vite/meta.json +4 -0
  123. package/docs/api-reference/workflow-vite/workflow.mdx +48 -0
  124. package/docs/changelog/attributes-mvp.mdx +380 -0
  125. package/docs/changelog/batched-event-writes.mdx +79 -0
  126. package/docs/changelog/eager-processing.mdx +110 -436
  127. package/docs/changelog/index.mdx +4 -2
  128. package/docs/changelog/lazy-event-creation.md +127 -0
  129. package/docs/changelog/lazy-hook-resume.mdx +78 -0
  130. package/docs/changelog/meta.json +11 -1
  131. package/docs/changelog/resilient-resume.mdx +32 -0
  132. package/docs/changelog/resilient-start.mdx +33 -285
  133. package/docs/changelog/step-message-ownership.mdx +360 -0
  134. package/docs/changelog/turbo-mode.md +87 -0
  135. package/docs/comparisons/index.mdx +66 -0
  136. package/docs/comparisons/meta.json +11 -0
  137. package/docs/comparisons/workflow-sdk-vs-aws-agentcore.mdx +55 -0
  138. package/docs/comparisons/workflow-sdk-vs-aws-step-functions.mdx +111 -0
  139. package/docs/comparisons/workflow-sdk-vs-cloudflare-workflows.mdx +71 -0
  140. package/docs/comparisons/workflow-sdk-vs-inngest.mdx +102 -0
  141. package/docs/comparisons/workflow-sdk-vs-temporal.mdx +123 -0
  142. package/docs/comparisons/workflow-sdk-vs-trigger-dev.mdx +104 -0
  143. package/docs/configuration/build-and-diagnostics.mdx +70 -0
  144. package/docs/configuration/cli-and-web-ui.mdx +241 -0
  145. package/docs/configuration/framework-options.mdx +165 -0
  146. package/docs/configuration/index.mdx +32 -0
  147. package/docs/configuration/meta.json +12 -0
  148. package/docs/configuration/runtime-tuning.mdx +381 -0
  149. package/docs/configuration/worlds.mdx +313 -0
  150. package/docs/cookbook/advanced/child-workflows.mdx +211 -264
  151. package/docs/cookbook/advanced/meta.json +6 -1
  152. package/docs/cookbook/advanced/publishing-libraries.mdx +65 -56
  153. package/docs/cookbook/advanced/serializable-steps.mdx +48 -68
  154. package/docs/cookbook/advanced/upgrading-workflows.mdx +199 -0
  155. package/docs/cookbook/agent-patterns/agent-cancellation.mdx +78 -60
  156. package/docs/cookbook/agent-patterns/durable-agent.mdx +23 -131
  157. package/docs/cookbook/agent-patterns/human-in-the-loop.mdx +180 -195
  158. package/docs/cookbook/common-patterns/batching.mdx +18 -14
  159. package/docs/cookbook/common-patterns/idempotency.mdx +41 -53
  160. package/docs/cookbook/common-patterns/rate-limiting.mdx +8 -4
  161. package/docs/cookbook/common-patterns/saga.mdx +23 -19
  162. package/docs/cookbook/common-patterns/scheduling.mdx +34 -22
  163. package/docs/cookbook/common-patterns/sequential-and-parallel.mdx +29 -25
  164. package/docs/cookbook/common-patterns/timeouts.mdx +26 -21
  165. package/docs/cookbook/common-patterns/webhooks.mdx +10 -6
  166. package/docs/cookbook/common-patterns/workflow-composition.mdx +30 -27
  167. package/docs/cookbook/index.mdx +22 -21
  168. package/docs/cookbook/integrations/ai-sdk.mdx +86 -48
  169. package/docs/cookbook/integrations/chat-sdk.mdx +50 -33
  170. package/docs/cookbook/integrations/sandbox.mdx +62 -45
  171. package/docs/deploying.mdx +95 -0
  172. package/docs/errors/abort-signal-timeout-in-workflow.mdx +16 -12
  173. package/docs/errors/corrupted-event-log.mdx +39 -18
  174. package/docs/errors/deployment-mismatch.mdx +71 -0
  175. package/docs/errors/fetch-in-workflow.mdx +15 -14
  176. package/docs/errors/hook-conflict.mdx +69 -13
  177. package/docs/errors/index.mdx +2 -36
  178. package/docs/errors/node-js-module-in-workflow.mdx +9 -5
  179. package/docs/errors/replay-divergence.mdx +27 -0
  180. package/docs/errors/run-expired.mdx +85 -0
  181. package/docs/errors/runtime-decryption-failed.mdx +77 -0
  182. package/docs/errors/serialization-failed.mdx +44 -12
  183. package/docs/errors/start-invalid-workflow-function.mdx +9 -5
  184. package/docs/errors/step-executed-multiple-times.mdx +23 -0
  185. package/docs/errors/step-not-registered.mdx +6 -6
  186. package/docs/errors/timeout-in-workflow.mdx +12 -8
  187. package/docs/errors/webhook-invalid-respond-with-value.mdx +18 -18
  188. package/docs/errors/webhook-response-not-sent.mdx +20 -16
  189. package/docs/errors/workflow-not-registered.mdx +5 -5
  190. package/docs/foundations/cancellation.mdx +31 -32
  191. package/docs/foundations/errors-and-retries.mdx +42 -11
  192. package/docs/foundations/hooks.mdx +64 -35
  193. package/docs/foundations/idempotency.mdx +244 -12
  194. package/docs/foundations/index.mdx +1 -23
  195. package/docs/foundations/meta.json +2 -1
  196. package/docs/foundations/serialization.mdx +21 -22
  197. package/docs/foundations/starting-workflows.mdx +106 -30
  198. package/docs/foundations/streaming.mdx +108 -60
  199. package/docs/foundations/versioning.mdx +263 -0
  200. package/docs/foundations/workflows-and-steps.mdx +9 -9
  201. package/docs/getting-started/astro.mdx +22 -18
  202. package/docs/getting-started/express.mdx +15 -11
  203. package/docs/getting-started/fastify.mdx +15 -11
  204. package/docs/getting-started/hono.mdx +15 -11
  205. package/docs/getting-started/index.mdx +10 -3
  206. package/docs/getting-started/meta.json +3 -1
  207. package/docs/getting-started/nestjs.mdx +87 -20
  208. package/docs/getting-started/next.mdx +22 -16
  209. package/docs/getting-started/nitro.mdx +22 -18
  210. package/docs/getting-started/nuxt.mdx +15 -11
  211. package/docs/getting-started/python.mdx +190 -41
  212. package/docs/getting-started/react-router/index.mdx +33 -0
  213. package/docs/getting-started/react-router/meta.json +5 -0
  214. package/docs/getting-started/react-router/v7.mdx +237 -0
  215. package/docs/getting-started/react-router/v8.mdx +232 -0
  216. package/docs/getting-started/sveltekit.mdx +20 -16
  217. package/docs/getting-started/tanstack-start.mdx +17 -13
  218. package/docs/getting-started/vite.mdx +15 -11
  219. package/docs/how-it-works/cancellation.mdx +63 -63
  220. package/docs/how-it-works/code-transform.mdx +83 -67
  221. package/docs/how-it-works/encryption.mdx +30 -26
  222. package/docs/how-it-works/event-sourcing.mdx +125 -34
  223. package/docs/how-it-works/framework-integrations.mdx +96 -337
  224. package/docs/how-it-works/understanding-directives.mdx +22 -22
  225. package/docs/internal/index.mdx +6 -4
  226. package/docs/internal/meta.json +6 -1
  227. package/docs/internal/nitro-native-build.mdx +38 -0
  228. package/docs/internal/nitro-web-ui.mdx +24 -0
  229. package/docs/internal/serializable-abort-controller.mdx +7 -7
  230. package/docs/meta.json +3 -2
  231. package/docs/observability/attributes.mdx +134 -0
  232. package/docs/observability/index.mdx +32 -10
  233. package/docs/observability/meta.json +1 -1
  234. package/docs/observability/retention.mdx +95 -0
  235. package/docs/observability/tracing.mdx +124 -0
  236. package/docs/testing/index.mdx +36 -36
  237. package/docs/testing/server-based.mdx +10 -10
  238. package/docs/whats-new.mdx +186 -0
  239. package/package.json +17 -14
  240. package/docs/api-reference/workflow-api/world/index.mdx +0 -58
  241. package/docs/api-reference/workflow-api/world/meta.json +0 -4
  242. package/docs/api-reference/workflow-api/world/observability.mdx +0 -164
  243. package/docs/api-reference/workflow-api/world/queue.mdx +0 -86
  244. package/docs/deploying/building-a-world.mdx +0 -251
  245. package/docs/deploying/index.mdx +0 -95
  246. package/docs/deploying/meta.json +0 -4
  247. package/docs/deploying/world/local-world.mdx +0 -84
  248. package/docs/deploying/world/meta.json +0 -4
  249. package/docs/deploying/world/postgres-world.mdx +0 -224
  250. package/docs/deploying/world/vercel-world.mdx +0 -179
  251. package/docs/migration-guides/index.mdx +0 -34
  252. package/docs/migration-guides/meta.json +0 -9
  253. package/docs/migration-guides/migrating-from-aws-step-functions.mdx +0 -363
  254. package/docs/migration-guides/migrating-from-inngest.mdx +0 -314
  255. package/docs/migration-guides/migrating-from-temporal.mdx +0 -318
  256. package/docs/migration-guides/migrating-from-trigger-dev.mdx +0 -337
@@ -47,7 +47,7 @@ async function writeToStream(writable: WritableStream) {
47
47
  }
48
48
  ```
49
49
 
50
- ## API Signature
50
+ ## API signature
51
51
 
52
52
  ### Parameters
53
53
 
@@ -69,7 +69,7 @@ export default getWritable;`}
69
69
 
70
70
  Returns a `WritableStream<W>` where `W` is the type of data you plan to write to the stream.
71
71
 
72
- ## Good to Know
72
+ ## Good to know
73
73
 
74
74
  - **Workflow functions can only obtain the stream** - Call `getWritable()` in a workflow to get the stream reference, but you cannot call methods like `getWriter()`, `write()`, or `close()` directly in the workflow context.
75
75
  - **Step functions can interact with streams** - Steps can receive the stream as an argument or call `getWritable()` directly, and they can freely interact with it (write, close, etc.).
@@ -81,9 +81,9 @@ Returns a `WritableStream<W>` where `W` is the type of data you plan to write to
81
81
 
82
82
  ## Examples
83
83
 
84
- ### Basic Text Streaming
84
+ ### Basic text streaming
85
85
 
86
- Here's a simple example streaming text data:
86
+ This example streams text data:
87
87
 
88
88
  ```typescript lineNumbers
89
89
  import { sleep, getWritable } from "workflow";
@@ -118,7 +118,7 @@ async function stepCloseOutputStream(writable: WritableStream) {
118
118
  }
119
119
  ```
120
120
 
121
- ### Calling `getWritable()` Inside Steps
121
+ ### Calling `getWritable()` inside steps
122
122
 
123
123
  You can also call `getWritable()` directly inside step functions without passing it as a parameter:
124
124
 
@@ -157,7 +157,7 @@ async function stepCloseOutputStreamInside() {
157
157
  }
158
158
  ```
159
159
 
160
- ### Using Namespaced Streams in Steps
160
+ ### Using namespaced streams in steps
161
161
 
162
162
  You can also use namespaced streams when calling `getWritable()` from steps:
163
163
 
@@ -201,7 +201,7 @@ async function closeStreams() {
201
201
  }
202
202
  ```
203
203
 
204
- ### Advanced Chat Streaming
204
+ ### Advanced chat streaming
205
205
 
206
206
  Here's a more complex example showing how you might stream AI chat responses:
207
207
 
@@ -47,9 +47,12 @@ Workflow SDK contains the following functions you can use inside your workflow f
47
47
  <Card href="/docs/api-reference/workflow/get-writable" title="getWritable()">
48
48
  Access the current workflow run's default stream.
49
49
  </Card>
50
+ <Card href="/docs/api-reference/workflow/set-attributes" title="setAttributes()">
51
+ Attach string metadata to the current workflow run.
52
+ </Card>
50
53
  </Cards>
51
54
 
52
- ## Error Classes
55
+ ## Error classes
53
56
 
54
57
  Workflow SDK includes error classes that can be thrown in a workflow or step to change the error exit strategy of a workflow.
55
58
 
@@ -31,7 +31,7 @@ async function retryStep() {
31
31
  The difference between `Error` and `RetryableError` may not be entirely obvious, since when both are thrown, they both retry. The difference is that `RetryableError` has an additional configurable `retryAfter` parameter.
32
32
  </Callout>
33
33
 
34
- ## API Signature
34
+ ## API signature
35
35
 
36
36
  ### Parameters
37
37
 
@@ -0,0 +1,61 @@
1
+ ---
2
+ title: setAttributes
3
+ description: Attach string metadata to workflow run for observability.
4
+ type: reference
5
+ summary: Use setAttributes inside a workflow or step function to set run attributes.
6
+ prerequisites:
7
+ - /docs/foundations/workflows-and-steps
8
+ related:
9
+ - /docs/observability/attributes
10
+ - /docs/api-reference/workflow/fatal-error
11
+ ---
12
+
13
+ Attaches string metadata to the current workflow run.
14
+
15
+ ```typescript lineNumbers
16
+ import { setAttributes } from "workflow"
17
+
18
+ export async function orderWorkflow(orderId: string) {
19
+ "use workflow"
20
+
21
+ await setAttributes({
22
+ phase: "received",
23
+ orderId,
24
+ })
25
+ }
26
+ ```
27
+
28
+ ## API signature
29
+
30
+ ### Parameters
31
+
32
+ <TSDoc
33
+ definition={`
34
+ import { setAttributes } from "workflow";
35
+ export default setAttributes;`}
36
+ showSections={['parameters']}
37
+ />
38
+
39
+ ## Usage
40
+
41
+ Call `setAttributes` from a `"use workflow"` function or a `"use step"` function. Calling it from plain application code is not supported because there is no active workflow run.
42
+
43
+ Attribute values must be strings. Pass `undefined` to remove an attribute:
44
+
45
+ ```typescript lineNumbers
46
+ import { setAttributes } from "workflow"
47
+
48
+ export async function cleanupAttributes() {
49
+ "use workflow"
50
+
51
+ await setAttributes({ staleKey: undefined })
52
+ }
53
+ ```
54
+
55
+ Attribute keys must be 1-256 characters, values must be strings up to 256 bytes, and each run can have up to 64 attributes. Keys that start with `$` are reserved for framework and library code.
56
+
57
+ Validation errors throw [`FatalError`](/docs/api-reference/workflow/fatal-error) and fail the run before an attribute write is attempted.
58
+
59
+ Calls from both workflow and step bodies append a native `attr_set` event, which the World materializes onto `run.attributes`. Workflow-originated events record a workflow writer; step-originated events record the originating step ID and attempt.
60
+
61
+ Native attributes require spec version 4 or later. Step-body storage errors throw from `setAttributes`; catch them inside the step if the write should be best-effort. Workflow-body writes are committed when the workflow suspends: transient storage errors are retried with the suspension, while a write the World rejects as invalid (such as exceeding the per-run attribute cap across multiple calls) fails the run with the validation error.
@@ -14,7 +14,7 @@ Suspends a workflow for a specified duration or until an end date without consum
14
14
  This is useful when you want to resume a workflow after some duration or date.
15
15
 
16
16
  <Callout>
17
- `sleep` is a *special* type of step function and should be called directly inside workflow functions.
17
+ `sleep` is a built-in workflow runtime function (backed by a timer event in the event log, not a step) and should be called directly inside workflow functions.
18
18
  </Callout>
19
19
 
20
20
  ```typescript lineNumbers
@@ -26,7 +26,7 @@ async function testWorkflow() {
26
26
  }
27
27
  ```
28
28
 
29
- ## API Signature
29
+ ## API signature
30
30
 
31
31
  ### Parameters
32
32
 
@@ -39,7 +39,7 @@ showSections={['parameters']}
39
39
 
40
40
  ## Examples
41
41
 
42
- ### Sleeping With a Duration
42
+ ### Sleeping with a duration
43
43
 
44
44
  You can specify a duration for `sleep` to suspend the workflow for a fixed amount of time.
45
45
 
@@ -52,7 +52,7 @@ async function testWorkflow() {
52
52
  }
53
53
  ```
54
54
 
55
- ### Sleeping Until an End Date
55
+ ### Sleeping until an end date
56
56
 
57
57
  You can specify a future `Date` object for `sleep` to suspend the workflow until a specific date.
58
58
 
@@ -1,61 +1,23 @@
1
1
  ---
2
2
  title: DurableAgent
3
- description: Create AI agents that maintain state, call tools, and handle interruptions gracefully.
3
+ description: Deprecated DurableAgent API reference; use WorkflowAgent for new durable agents.
4
4
  type: reference
5
- summary: Use DurableAgent to build AI agents that maintain state across steps and survive interruptions.
5
+ summary: "Deprecated: use AI SDK's WorkflowAgent instead of DurableAgent."
6
6
  prerequisites:
7
7
  - /docs/ai
8
8
  related:
9
9
  - /docs/ai/defining-tools
10
10
  ---
11
11
 
12
- The `DurableAgent` class enables you to create AI-powered agents that can maintain state across workflow steps, call tools, and gracefully handle interruptions and resumptions.
13
-
14
- Tool calls can be implemented as workflow steps for automatic retries, or as regular workflow-level logic utilizing core library features such as [`sleep()`](/docs/api-reference/workflow/sleep) and [Hooks](/docs/foundations/hooks).
15
-
16
- ```typescript lineNumbers
17
- import { DurableAgent } from "@workflow/ai/agent";
18
- import { getWritable } from "workflow";
19
- import { z } from "zod";
20
- import type { UIMessageChunk } from "ai";
21
-
22
- async function getWeather({ city }: { city: string }) {
23
- "use step";
24
-
25
- return `Weather in ${city} is sunny`;
26
- }
27
-
28
- async function myAgent() {
29
- "use workflow";
30
-
31
- const agent = new DurableAgent({
32
- model: "anthropic/claude-haiku-4.5",
33
- instructions: "You are a helpful weather assistant.",
34
- temperature: 0.7,
35
- tools: {
36
- getWeather: {
37
- description: "Get weather for a city",
38
- inputSchema: z.object({ city: z.string() }),
39
- execute: getWeather,
40
- },
41
- },
42
- });
43
-
44
- // The agent will stream its output to the workflow
45
- // run's default output stream
46
- const writable = getWritable<UIMessageChunk>();
12
+ <Callout type="warn">
13
+ `DurableAgent` is deprecated. Use AI SDK's [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) for new durable agents. See the [migration guide](https://ai-sdk.dev/v7/docs/agents/workflow-agent#migrating-from-durableagent).
14
+ </Callout>
47
15
 
48
- const result = await agent.stream({
49
- messages: [{ role: "user", content: "How is the weather in San Francisco?" }],
50
- writable,
51
- });
16
+ This reference is kept for existing applications that still import `DurableAgent` from `@workflow/ai/agent`. Do not use `DurableAgent` for new code.
52
17
 
53
- // result contains messages, steps, and optional structured output
54
- console.log(result.messages);
55
- }
56
- ```
18
+ For current examples and implementation guidance, see AI SDK's [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) docs. For legacy code, the API surface below documents the existing `DurableAgent` exports.
57
19
 
58
- ## API Signature
20
+ ## API signature
59
21
 
60
22
  ### Class
61
23
 
@@ -163,7 +125,7 @@ import type { StreamTextOnAbortCallback } from "@workflow/ai/agent";
163
125
  export default StreamTextOnAbortCallback;`}
164
126
  />
165
127
 
166
- ### Advanced Types
128
+ ### Advanced types
167
129
 
168
130
  #### ToolCallRepairFunction
169
131
 
@@ -195,30 +157,30 @@ import type { OutputSpecification } from "@workflow/ai/agent";
195
157
  export default OutputSpecification;`}
196
158
  />
197
159
 
198
- ## Key Features
160
+ ## Key features
199
161
 
200
- - **Durable Execution**: Agents can be interrupted and resumed without losing state
201
- - **Flexible Tool Implementation**: Tools can be implemented as workflow steps for automatic retries, or as regular workflow-level logic
202
- - **Stream Processing**: Handles streaming responses and tool calls in a structured way
203
- - **Workflow Native**: Fully integrated with Workflow SDK for production-grade reliability
204
- - **AI SDK Parity**: Supports the same options as AI SDK's `streamText` including generation settings, callbacks, and structured output
162
+ - **Durable execution**: Agents can be interrupted and resumed without losing state.
163
+ - **Flexible tool implementation**: Tools can be implemented as workflow steps for automatic retries or as regular workflow-level logic.
164
+ - **Stream processing**: Handles streaming responses and tool calls in a structured way.
165
+ - **Workflow native**: Fully integrated with Workflow SDK for production reliability.
166
+ - **AI SDK parity**: Supports the same options as AI SDK's `streamText`, including generation settings, callbacks, and structured output.
205
167
 
206
- ## Good to Know
168
+ ## Good to know
207
169
 
208
- - Tools can be implemented as workflow steps (using `"use step"` for automatic retries), or as regular workflow-level logic
209
- - Tools can use core library features like `sleep()` and Hooks within their `execute` functions
210
- - The agent processes tool calls iteratively until completion or `maxSteps` is reached
211
- - **Default `maxSteps` is unlimited** - set a value to limit the number of LLM calls
212
- - The `stream()` method returns `{ messages, steps, toolCalls, toolResults, experimental_output, uiMessages }` containing the full conversation history, step details, tool call details, optional structured output, and optionally accumulated UI messages
213
- - Use `collectUIMessages: true` to accumulate `UIMessage[]` during streaming, useful for persisting conversation state without re-reading the stream
214
- - The `prepareStep` callback runs before each step and can modify model, messages, generation settings, tool choice, and context
215
- - Generation settings (temperature, maxOutputTokens, etc.) can be set on the constructor and overridden per-stream call
216
- - Use `activeTools` to limit which tools are available for a specific stream call
217
- - The `onFinish` callback is called when all steps complete; `onAbort` is called if aborted
170
+ - Tools can be implemented as workflow steps (using `"use step"` for automatic retries) or as regular workflow-level logic.
171
+ - Tools can use core library features like `sleep()` and hooks within their `execute` functions.
172
+ - The agent processes tool calls iteratively until completion or until `maxSteps` is reached.
173
+ - **Default `maxSteps` is unlimited**: Set a value to limit the number of large language model (LLM) calls.
174
+ - The `stream()` method returns `{ messages, steps, toolCalls, toolResults, experimental_output, uiMessages }` containing the full conversation history, step details, tool call details, optional structured output, and optionally accumulated user interface (UI) messages.
175
+ - Use `collectUIMessages: true` to accumulate `UIMessage[]` during streaming, which is useful for persisting conversation state without re-reading the stream.
176
+ - The `prepareStep` callback runs before each step and can modify the model, messages, generation settings, tool choice, and context.
177
+ - Generation settings (`temperature`, `maxOutputTokens`, and others) can be set on the constructor and overridden per-stream call.
178
+ - Use `activeTools` to limit which tools are available for a specific stream call.
179
+ - The `onFinish` callback is called when all steps complete; `onAbort` is called if aborted.
218
180
 
219
181
  ## Examples
220
182
 
221
- ### Basic Agent with Tools
183
+ ### Basic agent with tools
222
184
 
223
185
  ```typescript
224
186
  import { DurableAgent } from "@workflow/ai/agent";
@@ -237,7 +199,7 @@ async function weatherAgentWorkflow(userQuery: string) {
237
199
  "use workflow";
238
200
 
239
201
  const agent = new DurableAgent({
240
- model: "anthropic/claude-haiku-4.5",
202
+ model: "spacexai/grok-4.6",
241
203
  tools: {
242
204
  getWeather: {
243
205
  description: "Get current weather for a location",
@@ -260,7 +222,7 @@ async function weatherAgentWorkflow(userQuery: string) {
260
222
  }
261
223
  ```
262
224
 
263
- ### Multiple Tools
225
+ ### Multiple tools
264
226
 
265
227
  ```typescript
266
228
  import { DurableAgent } from "@workflow/ai/agent";
@@ -282,7 +244,7 @@ async function multiToolAgentWorkflow(userQuery: string) {
282
244
  "use workflow";
283
245
 
284
246
  const agent = new DurableAgent({
285
- model: "anthropic/claude-haiku-4.5",
247
+ model: "spacexai/grok-4.6",
286
248
  tools: {
287
249
  getWeather: {
288
250
  description: "Get weather for a location",
@@ -309,7 +271,7 @@ async function multiToolAgentWorkflow(userQuery: string) {
309
271
  }
310
272
  ```
311
273
 
312
- ### Multi-turn Conversation
274
+ ### Multi-turn conversation
313
275
 
314
276
  ```typescript
315
277
  import { DurableAgent } from "@workflow/ai/agent";
@@ -327,7 +289,7 @@ async function multiTurnAgentWorkflow() {
327
289
  "use workflow";
328
290
 
329
291
  const agent = new DurableAgent({
330
- model: "anthropic/claude-haiku-4.5",
292
+ model: "spacexai/grok-4.6",
331
293
  tools: {
332
294
  searchProducts: {
333
295
  description: "Search for products",
@@ -363,7 +325,7 @@ async function multiTurnAgentWorkflow() {
363
325
  }
364
326
  ```
365
327
 
366
- ### Tools with Workflow Library Features
328
+ ### Tools with Workflow library features
367
329
 
368
330
  ```typescript
369
331
  import { DurableAgent } from "@workflow/ai/agent";
@@ -385,7 +347,7 @@ async function requestApproval({ message }: { message: string }) {
385
347
  // Note: No "use step" for this tool call either,
386
348
  // since hooks are awaited at the workflow level
387
349
 
388
- // Utilize a Hook for Human-in-the-loop approval
350
+ // Use a Hook for Human-in-the-loop approval
389
351
  const hook = approvalHook.create({
390
352
  metadata: { message }
391
353
  });
@@ -406,7 +368,7 @@ async function agentWithLibraryFeaturesWorkflow(userRequest: string) {
406
368
  "use workflow";
407
369
 
408
370
  const agent = new DurableAgent({
409
- model: "anthropic/claude-haiku-4.5",
371
+ model: "spacexai/grok-4.6",
410
372
  tools: {
411
373
  scheduleTask: {
412
374
  description: "Pause the workflow for the specified number of seconds",
@@ -430,7 +392,7 @@ async function agentWithLibraryFeaturesWorkflow(userRequest: string) {
430
392
  }
431
393
  ```
432
394
 
433
- ### Dynamic Context with prepareStep
395
+ ### Dynamic context with prepareStep
434
396
 
435
397
  Use `prepareStep` to modify settings before each step in the agent loop:
436
398
 
@@ -443,7 +405,7 @@ async function agentWithPrepareStep(userMessage: string) {
443
405
  "use workflow";
444
406
 
445
407
  const agent = new DurableAgent({
446
- model: "openai/gpt-4.1-mini", // Default model
408
+ model: "spacexai/grok-4.6", // Default model
447
409
  instructions: "You are a helpful assistant.",
448
410
  });
449
411
 
@@ -474,7 +436,7 @@ async function agentWithPrepareStep(userMessage: string) {
474
436
  }
475
437
  ```
476
438
 
477
- ### Message Injection with prepareStep
439
+ ### Message injection with prepareStep
478
440
 
479
441
  Inject messages from external sources (like hooks) before each LLM call:
480
442
 
@@ -497,7 +459,7 @@ async function agentWithMessageQueue(initialMessage: string) {
497
459
  });
498
460
 
499
461
  const agent = new DurableAgent({
500
- model: "anthropic/claude-haiku-4.5",
462
+ model: "spacexai/grok-4.6",
501
463
  instructions: "You are a helpful assistant.",
502
464
  });
503
465
 
@@ -524,7 +486,7 @@ async function agentWithMessageQueue(initialMessage: string) {
524
486
  }
525
487
  ```
526
488
 
527
- ### Generation Settings
489
+ ### Generation settings
528
490
 
529
491
  Configure model generation parameters at the constructor or stream level:
530
492
 
@@ -538,7 +500,7 @@ async function agentWithGenerationSettings() {
538
500
 
539
501
  // Set default generation settings in constructor
540
502
  const agent = new DurableAgent({
541
- model: "anthropic/claude-haiku-4.5",
503
+ model: "spacexai/grok-4.6",
542
504
  temperature: 0.7,
543
505
  maxOutputTokens: 2000,
544
506
  topP: 0.9,
@@ -562,7 +524,7 @@ async function agentWithGenerationSettings() {
562
524
  }
563
525
  ```
564
526
 
565
- ### Limiting Steps with maxSteps
527
+ ### Limiting steps with maxSteps
566
528
 
567
529
  By default, the agent loops until completion. Use `maxSteps` to limit the number of LLM calls:
568
530
 
@@ -586,7 +548,7 @@ async function multiStepAgent() {
586
548
  "use workflow";
587
549
 
588
550
  const agent = new DurableAgent({
589
- model: "anthropic/claude-haiku-4.5",
551
+ model: "spacexai/grok-4.6",
590
552
  tools: {
591
553
  searchWeb: {
592
554
  description: "Search the web for information",
@@ -613,7 +575,7 @@ async function multiStepAgent() {
613
575
  }
614
576
  ```
615
577
 
616
- ### Callbacks for Monitoring
578
+ ### Callbacks for monitoring
617
579
 
618
580
  Use callbacks to monitor streaming progress, handle errors, and react to completion:
619
581
 
@@ -626,7 +588,7 @@ async function agentWithCallbacks() {
626
588
  "use workflow";
627
589
 
628
590
  const agent = new DurableAgent({
629
- model: "anthropic/claude-haiku-4.5",
591
+ model: "spacexai/grok-4.6",
630
592
  });
631
593
 
632
594
  await agent.stream({
@@ -654,7 +616,7 @@ async function agentWithCallbacks() {
654
616
  }
655
617
  ```
656
618
 
657
- ### Structured Output
619
+ ### Structured output
658
620
 
659
621
  Parse structured data from the LLM response using `Output.object`:
660
622
 
@@ -668,7 +630,7 @@ async function agentWithStructuredOutput() {
668
630
  "use workflow";
669
631
 
670
632
  const agent = new DurableAgent({
671
- model: "anthropic/claude-haiku-4.5",
633
+ model: "spacexai/grok-4.6",
672
634
  });
673
635
 
674
636
  const result = await agent.stream({
@@ -689,7 +651,7 @@ async function agentWithStructuredOutput() {
689
651
  }
690
652
  ```
691
653
 
692
- ### Tool Choice Control
654
+ ### Tool choice control
693
655
 
694
656
  Control when and which tools the model can use:
695
657
 
@@ -703,7 +665,7 @@ async function agentWithToolChoice() {
703
665
  "use workflow";
704
666
 
705
667
  const agent = new DurableAgent({
706
- model: "anthropic/claude-haiku-4.5",
668
+ model: "spacexai/grok-4.6",
707
669
  tools: {
708
670
  calculator: {
709
671
  description: "Perform calculations",
@@ -752,7 +714,7 @@ async function agentWithToolChoice() {
752
714
  }
753
715
  ```
754
716
 
755
- ### Passing Context to Tools
717
+ ### Passing context to tools
756
718
 
757
719
  Use `experimental_context` to pass shared context to tool executions:
758
720
 
@@ -771,7 +733,7 @@ async function agentWithContext(userId: string) {
771
733
  "use workflow";
772
734
 
773
735
  const agent = new DurableAgent({
774
- model: "anthropic/claude-haiku-4.5",
736
+ model: "spacexai/grok-4.6",
775
737
  tools: {
776
738
  getUserData: {
777
739
  description: "Get user data",
@@ -796,7 +758,7 @@ async function agentWithContext(userId: string) {
796
758
  }
797
759
  ```
798
760
 
799
- ### Collecting UI Messages
761
+ ### Collecting UI messages
800
762
 
801
763
  Use `collectUIMessages` to accumulate `UIMessage[]` during streaming. This is useful when you need to persist the conversation without re-reading the run's output stream:
802
764
 
@@ -809,7 +771,7 @@ async function agentWithUIMessages(userMessage: string) {
809
771
  "use workflow";
810
772
 
811
773
  const agent = new DurableAgent({
812
- model: "anthropic/claude-haiku-4.5",
774
+ model: "spacexai/grok-4.6",
813
775
  instructions: "You are a helpful assistant.",
814
776
  });
815
777
 
@@ -838,7 +800,7 @@ async function saveConversation(messages: UIMessage[]) {
838
800
  The `uiMessages` property is only available when `collectUIMessages` is set to `true`. When disabled, `uiMessages` is `undefined`.
839
801
  </Callout>
840
802
 
841
- ### Machine-Readable Tool Results
803
+ ### Machine-readable tool results
842
804
 
843
805
  `stream()` returns tool call information you can inspect programmatically. Compare `toolCalls` with `toolResults` to find unresolved tool calls that need client-side handling:
844
806
 
@@ -857,7 +819,7 @@ async function agentWithToolInspection(userMessage: string) {
857
819
  "use workflow";
858
820
 
859
821
  const agent = new DurableAgent({
860
- model: "anthropic/claude-haiku-4.5",
822
+ model: "spacexai/grok-4.6",
861
823
  tools: {
862
824
  checkOrderStatus: {
863
825
  description: "Check order status",
@@ -895,7 +857,7 @@ async function agentWithToolInspection(userMessage: string) {
895
857
  `toolCalls` and `toolResults` reflect the *last step* of the agent loop. Tools without an `execute` function will appear in `toolCalls` but not in `toolResults`, which is how you detect calls that need client-side handling.
896
858
  </Callout>
897
859
 
898
- ### Aborting Long-Running Streams
860
+ ### Aborting long-running streams
899
861
 
900
862
  Use `timeout` to abort a stream automatically after a fixed duration:
901
863
 
@@ -912,7 +874,7 @@ async function agentWithTimeout(userMessage: string) {
912
874
  "use workflow";
913
875
 
914
876
  const agent = new DurableAgent({
915
- model: "anthropic/claude-haiku-4.5",
877
+ model: "spacexai/grok-4.6",
916
878
  });
917
879
 
918
880
  await agent.stream({
@@ -923,10 +885,10 @@ async function agentWithTimeout(userMessage: string) {
923
885
  }
924
886
  ```
925
887
 
926
- ## See Also
888
+ ## See also
927
889
 
928
- - [Building Durable AI Agents](/docs/ai) - Complete guide to creating durable agents
929
- - [Queueing User Messages](/docs/ai/message-queueing) - Using prepareStep for message injection
930
- - [WorkflowChatTransport](/docs/api-reference/workflow-ai/workflow-chat-transport) - Transport layer for AI SDK streams
931
- - [Workflows and Steps](/docs/foundations/workflows-and-steps) - Understanding workflow fundamentals
932
- - [AI SDK Loop Control](https://ai-sdk.dev/docs/agents/loop-control) - AI SDK's agent loop control patterns
890
+ - [Building Durable AI Agents](/docs/ai): Complete guide to creating durable agents
891
+ - [Queueing User Messages](/docs/ai/message-queueing): Using `prepareStep` for message injection
892
+ - [WorkflowChatTransport](/docs/api-reference/workflow-ai/workflow-chat-transport): Transport layer for AI SDK streams
893
+ - [Workflows and Steps](/docs/foundations/workflows-and-steps): Understanding workflow fundamentals
894
+ - [AI SDK Loop Control](https://ai-sdk.dev/docs/agents/loop-control): AI SDK's agent loop control patterns
@@ -1,21 +1,21 @@
1
1
  ---
2
2
  title: "@workflow/ai"
3
- description: Helpers for building AI-powered workflows with the AI SDK.
3
+ description: Deprecated AI integration APIs kept for existing Workflow applications.
4
4
  type: overview
5
- summary: Explore helpers for integrating AI SDK to build durable AI-powered workflows.
5
+ summary: Migrate legacy @workflow/ai APIs to AI SDK's WorkflowAgent and WorkflowChatTransport.
6
6
  related:
7
7
  - /docs/ai
8
8
  ---
9
9
 
10
- Helpers for integrating AI SDK for building AI-powered workflows.
10
+ The `@workflow/ai` package is deprecated in Workflow 5 and remains documented for existing applications. Build new agents with [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) and [`WorkflowChatTransport`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#resumable-streaming-with-workflowchattransport) from `@ai-sdk/workflow`.
11
11
 
12
12
  ## Classes
13
13
 
14
14
  <Cards>
15
15
  <Card title="DurableAgent" href="/docs/api-reference/workflow-ai/durable-agent">
16
- A class for building durable AI agents that maintain state across workflow steps and handle tool execution with automatic retries.
16
+ Deprecated: use AI SDK's [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent). Reference kept for existing `@workflow/ai/agent` imports.
17
17
  </Card>
18
18
  <Card title="WorkflowChatTransport" href="/docs/api-reference/workflow-ai/workflow-chat-transport">
19
- A drop-in transport for the AI SDK for automatic reconnection in interrupted streams.
19
+ Deprecated: use AI SDK's [`WorkflowChatTransport`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#resumable-streaming-with-workflowchattransport) from `@ai-sdk/workflow`. Reference kept for existing `@workflow/ai` imports.
20
20
  </Card>
21
21
  </Cards>