Skip to main content
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

npm install @workflow/ai ai

Quick Start

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

DurableAgent

Main class for building AI agents with durable execution

Providers

AI model provider integrations (Anthropic, OpenAI, Google, xAI)

AI SDK Compatibility

The Workflow AI SDK is built on top of the Vercel AI SDK 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.

Build docs developers (and LLMs) love