> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/vercel/workflow/llms.txt
> Use this file to discover all available pages before exploring further.

# Workflow AI SDK

> Build durable AI agents with automatic retries and state management

The Workflow AI SDK provides building blocks for creating production-ready AI agents that integrate seamlessly with the Workflow DevKit. It extends the Vercel AI SDK with durable execution capabilities, allowing your AI agents to maintain state across interruptions, handle long-running tasks, and automatically recover from failures.

## Key Features

* **Durable Execution**: AI agents that survive interruptions and automatically resume
* **Multi-Provider Support**: Works with Anthropic, OpenAI, Google AI, and xAI
* **Automatic Retries**: Built-in retry logic for transient failures
* **Streaming Support**: Real-time streaming responses with state management
* **Tool Integration**: Use workflow steps as AI tools with automatic persistence
* **Type Safety**: Full TypeScript support with inference

## Installation

```bash theme={null}
npm install @workflow/ai ai
```

## Quick Start

```typescript theme={null}
import { DurableAgent } from '@workflow/ai';
import { anthropic } from '@workflow/ai/providers/anthropic';
import { getWritable } from 'workflow';
import { z } from 'zod';

export async function myWorkflow() {
  'use workflow';

  const agent = new DurableAgent({
    model: anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })('claude-3-5-sonnet-20241022'),
    system: 'You are a helpful assistant.',
    tools: {
      getWeather: {
        description: 'Get weather for a location',
        inputSchema: z.object({
          location: z.string().describe('City name'),
        }),
        execute: async ({ location }) => {
          'use step';
          // This runs as a durable workflow step
          const weather = await fetch(`https://api.weather.com/${location}`);
          return weather.json();
        },
      },
    },
  });

  await agent.stream({
    messages: [{ role: 'user', content: 'What\'s the weather in San Francisco?' }],
    writable: getWritable(),
  });
}
```

## Core Components

<CardGroup cols={2}>
  <Card title="DurableAgent" icon="robot" href="/api-reference/workflow-ai/durable-agent">
    Main class for building AI agents with durable execution
  </Card>

  <Card title="Providers" icon="plug" href="/api-reference/workflow-ai/providers">
    AI model provider integrations (Anthropic, OpenAI, Google, xAI)
  </Card>
</CardGroup>

## AI SDK Compatibility

The Workflow AI SDK is built on top of the [Vercel AI SDK](https://sdk.vercel.ai/docs) and maintains compatibility with its core concepts:

* **Messages**: Use the standard `ModelMessage` format
* **Tools**: Compatible with AI SDK tool definitions
* **Streaming**: Supports `UIMessageChunk` streaming protocol
* **Structured Output**: Works with the `Output` helper for typed responses

The key difference is that all operations are automatically made durable through workflow steps.

## When to Use

Use the Workflow AI SDK when you need:

* AI agents that run for extended periods (hours/days)
* Reliable execution of AI workflows with automatic retries
* Integration with external tools and APIs that need durability
* State management across multiple AI interactions
* Recovery from infrastructure failures or rate limits

For simple, short-lived AI interactions, the standard AI SDK may be sufficient.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.