workflow 5.0.0-beta.11 → 5.0.0-beta.13

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.
package/docs/ai/index.mdx CHANGED
@@ -92,7 +92,7 @@ Then modify your API endpoint to use the OpenAI provider:
92
92
  {/* @skip-typecheck: incomplete code sample */}
93
93
  ```typescript title="app/api/chat/route.ts" lineNumbers
94
94
  // ...
95
- import { openai } from "@workflow/ai/openai"; // [!code highlight]
95
+ import { openai } from "@ai-sdk/openai"; // [!code highlight]
96
96
 
97
97
  export async function POST(req: Request) {
98
98
  // ...
@@ -232,7 +232,7 @@ Now that we have a basic agent using AI SDK, we can modify it to make it durable
232
232
  Add the Workflow SDK packages to your project:
233
233
 
234
234
  ```package-install
235
- npm i workflow @workflow/ai
235
+ npm i workflow @ai-sdk/workflow
236
236
  ```
237
237
 
238
238
  and extend the Next.js config to transform your workflow code (see [Getting Started](/docs/getting-started/next) for more details).
@@ -258,18 +258,18 @@ Move the agent logic into a separate function, which will serve as our workflow
258
258
 
259
259
  {/* @skip-typecheck: Shows two mutually exclusive model options */}
260
260
  ```typescript title="workflows/chat/workflow.ts" lineNumbers
261
- import { DurableAgent } from "@workflow/ai/agent"; // [!code highlight]
261
+ import { WorkflowAgent, type ModelCallStreamPart } from "@ai-sdk/workflow"; // [!code highlight]
262
262
  import { getWritable } from "workflow"; // [!code highlight]
263
263
  import { tools } from "@/ai/tools";
264
- import { openai } from "@workflow/ai/openai";
265
- import type { ModelMessage, UIMessageChunk } from "ai";
264
+ import { openai } from "@ai-sdk/openai";
265
+ import { convertToModelMessages, type UIMessage } from "ai";
266
266
 
267
- export async function chatWorkflow(messages: ModelMessage[]) {
267
+ export async function chatWorkflow(messages: UIMessage[]) {
268
268
  "use workflow"; // [!code highlight]
269
269
 
270
- const writable = getWritable<UIMessageChunk>(); // [!code highlight]
270
+ const writable = getWritable<ModelCallStreamPart>(); // [!code highlight]
271
271
 
272
- const agent = new DurableAgent({ // [!code highlight]
272
+ const agent = new WorkflowAgent({ // [!code highlight]
273
273
 
274
274
  // If using AI Gateway, just specify the model name as a string:
275
275
  model: "bedrock/claude-4-5-haiku-20251001-v1", // [!code highlight]
@@ -281,8 +281,10 @@ export async function chatWorkflow(messages: ModelMessage[]) {
281
281
  tools: flightBookingTools,
282
282
  });
283
283
 
284
+ const modelMessages = await convertToModelMessages(messages); // [!code highlight]
285
+
284
286
  await agent.stream({ // [!code highlight]
285
- messages,
287
+ messages: modelMessages,
286
288
  writable,
287
289
  });
288
290
  }
@@ -291,8 +293,9 @@ export async function chatWorkflow(messages: ModelMessage[]) {
291
293
  Key changes:
292
294
 
293
295
  - Add the `"use workflow"` directive to mark our Agent as a workflow function
294
- - Replaced `Agent` with [`DurableAgent`](/docs/api-reference/workflow-ai/durable-agent) from `@workflow/ai/agent`. This ensures that all calls to the LLM are executed as "steps", and results are aggregated within the workflow context (see [Workflows and Steps](/docs/foundations/workflows-and-steps) for more details on how workflows/steps are defined).
295
- - Use [`getWritable()`](/docs/api-reference/workflow/get-writable) to get a stream for agent output. This stream is persistent, and API endpoints can read from a run's stream at any time.
296
+ - Replace the in-memory agent with [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) from `@ai-sdk/workflow`. This runs the agent loop inside a workflow, persists state across step boundaries, and lets tool executions marked with `"use step"` retry automatically.
297
+ - Convert AI SDK `UIMessage` values to model messages inside the workflow before calling `agent.stream()`.
298
+ - Use [`getWritable()`](/docs/api-reference/workflow/get-writable) to get a stream for agent output. `WorkflowAgent` writes `ModelCallStreamPart` chunks to this persistent stream, and API endpoints can read from a run's stream at any time.
296
299
  </Step>
297
300
 
298
301
  <Step>
@@ -301,19 +304,18 @@ Key changes:
301
304
  Remove the agent call that we just extracted, and replace it with a call to `start()` to run the workflow:
302
305
 
303
306
  ```typescript title="app/api/chat/route.ts" lineNumbers
304
- import type { UIMessage } from "ai";
305
- import { convertToModelMessages, createUIMessageStreamResponse } from "ai";
307
+ import { createModelCallToUIChunkTransform } from "@ai-sdk/workflow";
308
+ import { createUIMessageStreamResponse, type UIMessage } from "ai";
306
309
  import { start } from "workflow/api";
307
310
  import { chatWorkflow } from "@/workflows/chat/workflow";
308
311
 
309
312
  export async function POST(req: Request) {
310
313
  const { messages }: { messages: UIMessage[] } = await req.json();
311
- const modelMessages = await convertToModelMessages(messages);
312
314
 
313
- const run = await start(chatWorkflow, [modelMessages]); // [!code highlight]
315
+ const run = await start(chatWorkflow, [messages]); // [!code highlight]
314
316
 
315
317
  return createUIMessageStreamResponse({
316
- stream: run.readable, // [!code highlight]
318
+ stream: run.readable.pipeThrough(createModelCallToUIChunkTransform()), // [!code highlight]
317
319
  });
318
320
  }
319
321
  ```
@@ -321,7 +323,8 @@ export async function POST(req: Request) {
321
323
  Key changes:
322
324
 
323
325
  - Call `start()` to run the workflow function. This returns a `Run` object, which contains the run ID and the readable stream (see [Starting Workflows](/docs/foundations/starting-workflows) for more details on the `Run` object).
324
- - Pass the `writable` to `agent.stream()` instead of returning a stream directly, ensuring all the Agent output is written to to the run's stream.
326
+ - Pass the `writable` to `agent.stream()` instead of returning a stream directly, ensuring all the Agent output is written to the run's stream.
327
+ - Pipe the readable stream through `createModelCallToUIChunkTransform()` so the raw model-call chunks become AI SDK UI message chunks before they are returned to the client.
325
328
 
326
329
  </Step>
327
330
 
@@ -423,7 +426,7 @@ A complete example that includes all of the above, plus all of the "next steps"
423
426
  ## Related Documentation
424
427
 
425
428
  - [Tools](/docs/ai/defining-tools) - Patterns for defining tools for your agent
426
- - [`DurableAgent` API Reference](/docs/api-reference/workflow-ai/durable-agent) - Full API documentation
429
+ - [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) - AI SDK API for durable, resumable agents
427
430
  - [Workflows and Steps](/docs/foundations/workflows-and-steps) - Core concepts
428
431
  - [Streaming](/docs/foundations/streaming) - In-depth streaming guide
429
432
  - [Errors and Retries](/docs/foundations/errors-and-retries) - Error handling patterns
@@ -1,59 +1,21 @@
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 and migration guidance.
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
20
  ## API Signature
59
21