Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
ad8b7f1
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Jan 27, 2026
e0cb61b
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Jan 28, 2026
051cadc
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Jan 29, 2026
af8ac1f
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Jan 29, 2026
e68e7d2
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Jan 30, 2026
8305e5b
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Jan 30, 2026
f3da688
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Jan 31, 2026
f8ee413
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 1, 2026
589cbd7
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 2, 2026
e979fdf
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 3, 2026
d4baed2
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 6, 2026
53503a4
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 10, 2026
d51e2e4
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 13, 2026
5123088
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 13, 2026
dd1a307
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 13, 2026
00bcfcd
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 14, 2026
f6a157b
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 15, 2026
816f35b
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 16, 2026
2b87dce
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 17, 2026
146de28
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 18, 2026
0ef6455
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 18, 2026
2d8c690
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 18, 2026
3513471
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 20, 2026
0f5d29e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 20, 2026
c76001e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 23, 2026
f97184f
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 24, 2026
f71c531
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 25, 2026
530e598
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 25, 2026
ea38511
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Feb 27, 2026
19b1a3f
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 2, 2026
757bfdb
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 2, 2026
5fb4cfb
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 3, 2026
cb5adc3
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 3, 2026
046fdbc
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 3, 2026
2a7884f
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 3, 2026
60ecae6
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 5, 2026
71a6e95
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 6, 2026
25fb139
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 9, 2026
8fe6a36
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 9, 2026
d7cb1a3
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 10, 2026
99b34fe
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 10, 2026
e63bfca
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 11, 2026
810af84
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 11, 2026
67142f9
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 11, 2026
58b47e7
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 12, 2026
4dfac66
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 12, 2026
a423b68
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 13, 2026
b8f1f2e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 13, 2026
30fe808
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 13, 2026
972c20b
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 13, 2026
0c882fb
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 13, 2026
e8d3775
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 16, 2026
29a316d
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 16, 2026
70b3e67
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 17, 2026
d97b801
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 17, 2026
e50f179
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 18, 2026
f6f1a4e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 18, 2026
6bc491f
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 18, 2026
bacb19e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 18, 2026
6a97701
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 20, 2026
d64bb0e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 20, 2026
04ef7fd
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 22, 2026
9748e93
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 24, 2026
27a5ca6
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 24, 2026
c0fcfbd
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 26, 2026
3c9b9f5
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 26, 2026
b317a73
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 28, 2026
119d147
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Mar 30, 2026
c77eede
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 1, 2026
8a8732e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 3, 2026
86b1861
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 5, 2026
47af9ca
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 7, 2026
b0f125e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 10, 2026
f1dbb56
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 11, 2026
deeab3e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 12, 2026
ea40643
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 13, 2026
e780833
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 13, 2026
a26e834
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 14, 2026
6ebb540
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 14, 2026
dc18bf6
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 14, 2026
70e6f37
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 14, 2026
edb2946
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 15, 2026
d5b3511
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 15, 2026
1497def
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 16, 2026
429d7fa
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 16, 2026
5ea7996
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 17, 2026
8d3b46f
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 22, 2026
b28953f
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 22, 2026
96d2a1e
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 22, 2026
59427f5
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 23, 2026
573f38b
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 28, 2026
d41a682
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 28, 2026
c6909cb
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 29, 2026
2556fb9
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 Apr 29, 2026
ab5cd69
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 May 1, 2026
2605428
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 May 5, 2026
a0c6481
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 May 6, 2026
4cd2ba0
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 May 7, 2026
5874a88
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 May 12, 2026
0345928
Merge remote-tracking branch 'origin/main' into main
karthikscale3 May 15, 2026
181dbf9
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 May 20, 2026
fa391d7
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 May 20, 2026
c2dbf33
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 May 20, 2026
7e39c27
Merge branch 'main' of github.com:vercel/workflow
karthikscale3 May 22, 2026
9a8a73f
docs: add DurableAgent deprecation notice, recommend WorkflowAgent
karthikscale3 May 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ related:

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.

<Callout type="warn">
**Deprecation notice:** `DurableAgent` will be deprecated soon. For new durable agent workflows, use [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) from `@ai-sdk/workflow` instead. See [Migrating from DurableAgent](https://ai-sdk.dev/v7/docs/agents/workflow-agent#migrating-from-durableagent) in the AI SDK docs.
</Callout>

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).

```typescript lineNumbers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ summary: Convert an AI SDK Agent into a DurableAgent backed by a workflow, with

Use this pattern to make any AI SDK agent durable. The agent becomes a workflow, tools become steps, and the framework handles retries, streaming, and state persistence automatically.

<Callout type="warn">
**Deprecation notice:** `DurableAgent` will be deprecated soon. For new durable agent workflows, use [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) from `@ai-sdk/workflow` instead. See [Migrating from DurableAgent](https://ai-sdk.dev/v7/docs/agents/workflow-agent#migrating-from-durableagent) in the AI SDK docs.
</Callout>

## When to use this

- Any AI agent with tool calls that should survive crashes and restarts
Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/v4/cookbook/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A curated collection of workflow patterns with clean, copy-paste code examples f

## Agent Patterns

- [**Durable Agent**](/cookbook/agent-patterns/durable-agent) — Replace a stateless AI agent with one that survives crashes and retries tool calls
- [**Durable Agent**](/cookbook/agent-patterns/durable-agent) — Legacy durable agent pattern (deprecated soon — prefer [WorkflowAgent](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent))
- [**Human-in-the-Loop**](/cookbook/agent-patterns/human-in-the-loop) — Pause an agent for human approval, then resume based on the decision
- [**Agent Cancellation**](/cookbook/agent-patterns/agent-cancellation) — Stop a running agent immediately via `run.cancel()` or gracefully via a hook + `Promise.race`

Expand Down
61 changes: 40 additions & 21 deletions docs/content/docs/v4/cookbook/integrations/ai-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: AI SDK
description: Use AI SDK's streamText directly inside durable workflows for lower-level control over model calls and tool execution.
type: guide
summary: Use streamText() inside a workflow for full control over model options, stop conditions, and output schemas — while tools remain durable steps.
summary: Use streamText() inside a workflow for full control over model options, stop conditions, and output schemas. The per-turn step is durable; individual tool calls inside it are not.
related:
- /docs/ai
- /docs/ai/chat-session-modeling
Expand All @@ -11,17 +11,17 @@ related:
- /docs/api-reference/workflow-ai/durable-agent
---

[AI SDK](https://ai-sdk.dev/) is Vercel's framework-agnostic TypeScript toolkit for building AI-powered apps and agents — unified provider access, streaming, tool calling, structured output, and UI hooks. Workflow SDK complements it by making those calls durable: the model request, the tool loop, and the multi-turn conversation all survive restarts and timeouts.
[AI SDK](https://ai-sdk.dev/) is Vercel's framework-agnostic TypeScript toolkit for building AI-powered apps and agents — unified provider access, streaming, tool calling, structured output, and UI hooks. Workflow SDK complements it by making the multi-turn loop durable: the conversation state, hooks, and per-turn responses survive restarts and timeouts. Note that in this pattern the durability boundary is the entire turn — individual tool calls inside a turn are **not** durable on their own (see [Pitfalls](#tools-are-not-individually-durable) below).

For the full AI SDK reference (providers, `streamText`, `generateObject`, `useChat`, tool calling, etc.) see the [AI SDK docs](https://ai-sdk.dev/docs). This page covers the Workflow-specific integration points.

<Callout type="info">
For most agent use cases, prefer [`DurableAgent`](/cookbook/agent-patterns/durable-agent) which wraps [`streamText`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) and manages the tool loop automatically. This page covers using `streamText()` directly when you need lower-level control.
For most agent use cases, prefer [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) from `@ai-sdk/workflow`, which manages the tool loop automatically and runs tools as durable workflow steps. This page covers using `streamText()` directly when you need AI SDK features that require lower-level control — accepting that tools inside a turn are no longer individually durable unless you wrap them yourself.
</Callout>

## When to use streamText directly

Use [`streamText()`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) instead of `DurableAgent` when you need:
Use [`streamText()`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) instead of [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) or the legacy `DurableAgent` when you need:

* **Custom stop conditions** — [`stopWhen`](https://ai-sdk.dev/docs/ai-sdk-core/agents#stop-conditions), [`prepareStep`](https://ai-sdk.dev/docs/ai-sdk-core/agents#prepare-step), or [`onStepFinish`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text#on-step-finish) callbacks
* **Structured output** — [`Output.object()`](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) or `Output.array()` alongside tool calling
Expand Down Expand Up @@ -52,14 +52,16 @@ export const turnHook = defineHook({ // [!code highlight]
schema: z.object({ message: z.string() }),
});

// Tools are plain async functions in this pattern. `streamText` calls them
// from inside `runTurn` (a step), and the `"use step"` directive is a no-op
// when called from another step — see the "Tools are not individually durable"
// pitfall below. Make side-effectful tools idempotent.
async function lookupOrder({ orderId }: { orderId: string }) {
"use step";
const res = await fetch(`https://api.store.com/orders/${orderId}`);
return res.json();
}

async function processRefund({ orderId, reason }: { orderId: string; reason: string }) {
"use step";
const res = await fetch("https://api.store.com/refunds", {
method: "POST",
body: JSON.stringify({ orderId, reason }),
Expand Down Expand Up @@ -294,16 +296,32 @@ export function SupportChat() {
## How it works

1. **One workflow = one conversation.** The workflow loops on a hook, keeping `allMessages`, tool history, and state alive across turns.
2. **Hook is created once.** `turnHook.create({ token: workflowRunId })` outside the loop — calling it twice with the same token throws `HookConflictError`.
3. **`preventClose: true`** on `pipeTo` keeps the durable writable open so the next turn can write to it.
4. **`sliceUntilFinish`** in the API reads chunks until `type === "finish"`, then closes the HTTP response. The source reader is released — not cancelled — so the workflow stream keeps flowing.
5. **`startIndex: tailIndex + 1`** gives each follow-up response only the new chunks, avoiding replay of previous turns.
6. **`/done`** resumes the hook so the workflow exits cleanly, then returns a synthetic `start` + `finish` so `useChat` transitions out of "streaming".
2. **`runTurn` is the durability boundary.** Each turn is one step. The model request and all tool calls inside it run as plain inline functions within that step. If anything throws mid-turn, the whole `runTurn` retries — individual tool calls are not separately durable. See [Pitfalls](#tools-are-not-individually-durable).
3. **Hook is created once.** `turnHook.create({ token: workflowRunId })` outside the loop — calling it twice with the same token throws `HookConflictError`.
4. **`preventClose: true`** on `pipeTo` keeps the durable writable open so the next turn can write to it.
5. **`sliceUntilFinish`** in the API reads chunks until `type === "finish"`, then closes the HTTP response. The source reader is released — not cancelled — so the workflow stream keeps flowing.
6. **`startIndex: tailIndex + 1`** gives each follow-up response only the new chunks, avoiding replay of previous turns.
7. **`/done`** resumes the hook so the workflow exits cleanly, then returns a synthetic `start` + `finish` so `useChat` transitions out of "streaming".

## Pitfalls

Non-obvious correctness details worth knowing before adapting this pattern.

### Tools are not individually durable

`streamText()` is invoked from inside `runTurn` (a `"use step"` function), and the AI SDK calls each tool by directly invoking its `execute` function in that same step. Even if a tool body has its own `"use step"` directive, that directive is a [no-op when called from another step](/docs/foundations/workflows-and-steps#step-functions) — the function just runs inline.

The consequences:

- The atomic retry unit is the entire `runTurn`, not the individual tool call.
- If `processRefund` succeeds and then the model call (or a later tool) throws, the whole turn retries, and `processRefund` will run again.
- Tool calls do not appear as separate entries in the event log or observability dashboard.

**Mitigations:**

- Make side-effectful tool implementations idempotent — dedupe server-side on a stable key (e.g. `orderId`, an `Idempotency-Key` header, etc.).
- Or use [`DurableAgent`](/docs/api-reference/workflow-ai/durable-agent), which runs tools at workflow scope — each tool can be marked `"use step"` to become its own durable, retryable step, or stay at workflow level to use primitives like `sleep()` and hooks.

### Snapshot `tailIndex` *before* resuming the hook

{/* @skip-typecheck - fragment referencing variables from the surrounding multi-turn pattern */}
Expand Down Expand Up @@ -332,32 +350,33 @@ In `sliceUntilFinish`, use `reader.releaseLock()` in the `finally` block rather

Clients can send a `runId` from a long-gone workflow (localStorage, back button, server restart). Wrap the follow-up path in a try/catch for `not found` / `expired` and fall through to the first-turn code path to start a fresh workflow.

## streamText vs DurableAgent
## streamText vs WorkflowAgent

| | `streamText()` | `DurableAgent` |
| | `streamText()` | [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) |
|---|---|---|
| **Tool loop** | AI SDK handles via `stopWhen` | DurableAgent handles internally |
| **Tool loop** | AI SDK handles via `stopWhen` | WorkflowAgent handles internally |
| **LLM call durability** | Re-executes on replay | Each LLM call is a durable step |
| **Stop conditions** | `stopWhen`, `prepareStep` | `prepareStep` only |
| **Structured output** | `Output.object()`, `Output.array()` | Not available |
| **Step callbacks** | `onStepFinish`, `onChunk` | Not available |
| **Setup** | Manual stream piping | Automatic |
| **Tool call durability** | Not individually durable — re-executes with the parent turn | Per tool — mark `"use step"` for a durable, retryable step |
| **Stop conditions** | `stopWhen`, `prepareStep` | `stopWhen`, `prepareStep` |
| **Structured output** | `Output.object()`, `Output.array()` | `Output.object()` via `stream()` |
| **Step callbacks** | `onStepFinish`, `onChunk` | Lifecycle callbacks on the agent |
| **Setup** | Manual stream piping | `getWritable()` + `createModelCallToUIChunkTransform()` |

Use `DurableAgent` for most agent use cases. Use `streamText` when you need the additional control.
Use [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) for most agent use cases. Use `streamText` when you need the additional control. The legacy [`DurableAgent`](/docs/api-reference/workflow-ai/durable-agent) docs remain available but will be deprecated soon.

## Key APIs

**AI SDK** ([docs](https://ai-sdk.dev/docs))

* [`streamText()`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) — core streaming function; `toUIMessageStream()` pipes into the durable writable
* [`tool()` / tool calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) — tools wrap `"use step"` functions so each tool call is replayed from the log, not re-executed
* [`tool()` / tool calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) — tools are plain async functions invoked by `streamText` inside the turn step; they are **not** individually durable in this pattern (see [Pitfalls](#tools-are-not-individually-durable))
* [`stepCountIs()` / `stopWhen`](https://ai-sdk.dev/docs/ai-sdk-core/agents#stop-conditions) — bound the agent loop inside each turn
* [`convertToModelMessages()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) / [`createUIMessageStreamResponse()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) — UI ↔ model message conversion at the API boundary
* [`useChat()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) — React hook that consumes the UI message stream on the client

**Workflow SDK**

* [`"use step"`](/docs/api-reference/workflow/use-step) — makes tool executions durable
* [`"use step"`](/docs/api-reference/workflow/use-step) — applied to `runTurn` to make each turn a durable, retryable unit
* [`defineHook()`](/docs/api-reference/workflow/define-hook) — suspension point for follow-up messages
* [`getWritable()`](/docs/api-reference/workflow/get-writable) — resumable stream output
* [`getRun()`](/docs/api-reference/workflow-api/get-run) — `run.getReadable({ startIndex })` for slicing per-turn streams
Expand Down
4 changes: 4 additions & 0 deletions docs/content/docs/v4/foundations/streaming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ export async function batchProcessingWorkflow(items: string[]) {

### Streaming AI Responses with `DurableAgent`

<Callout type="warn">
**Deprecation notice:** `DurableAgent` will be deprecated soon. For new durable agent workflows, use [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) from `@ai-sdk/workflow` instead.
</Callout>

Stream AI-generated content using [`DurableAgent`](/docs/api-reference/workflow-ai/durable-agent) from `@workflow/ai`. Tools can also emit progress updates to the same stream using [data chunks](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data#streaming-custom-data) with the [`UIMessageChunk`](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) type from the AI SDK:

```typescript title="workflows/ai-assistant.ts" lineNumbers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ related:

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.

<Callout type="warn">
**Deprecation notice:** `DurableAgent` will be deprecated soon. For new durable agent workflows, use [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) from `@ai-sdk/workflow` instead. See [Migrating from DurableAgent](https://ai-sdk.dev/v7/docs/agents/workflow-agent#migrating-from-durableagent) in the AI SDK docs.
</Callout>

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).

```typescript lineNumbers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ summary: Convert an AI SDK Agent into a DurableAgent backed by a workflow, with

Use this pattern to make any AI SDK agent durable. The agent becomes a workflow, tools become steps, and the framework handles retries, streaming, and state persistence automatically.

<Callout type="warn">
**Deprecation notice:** `DurableAgent` will be deprecated soon. For new durable agent workflows, use [`WorkflowAgent`](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent) from `@ai-sdk/workflow` instead. See [Migrating from DurableAgent](https://ai-sdk.dev/v7/docs/agents/workflow-agent#migrating-from-durableagent) in the AI SDK docs.
</Callout>

## When to use this

- Any AI agent with tool calls that should survive crashes and restarts
Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/v5/cookbook/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A curated collection of workflow patterns with clean, copy-paste code examples f

## Agent Patterns

- [**Durable Agent**](/cookbook/agent-patterns/durable-agent) — Replace a stateless AI agent with one that survives crashes and retries tool calls
- [**Durable Agent**](/cookbook/agent-patterns/durable-agent) — Legacy durable agent pattern (deprecated soon — prefer [WorkflowAgent](https://ai-sdk.dev/v7/docs/agents/workflow-agent#workflowagent))
- [**Human-in-the-Loop**](/cookbook/agent-patterns/human-in-the-loop) — Pause an agent for human approval, then resume based on the decision
- [**Agent Cancellation**](/cookbook/agent-patterns/agent-cancellation) — Stop a running agent immediately via `run.cancel()` or gracefully via a hook + `Promise.race`

Expand Down
Loading
Loading