Skip to main content

Overview

DurableAgent is a class for building AI agents that maintain state across workflow executions. It wraps AI model providers with durable execution capabilities, ensuring that your AI agents can survive interruptions, handle long-running operations, and automatically recover from failures.

Constructor

DurableAgentOptions
required
Configuration for the durable agent

Methods

stream()

Streams AI responses with tool execution and state management.
DurableAgentStreamOptions
required
Returns: Promise<DurableAgentStreamResult>
ModelMessage[]
Final conversation messages including all tool calls and results
StepResult[]
Details for each LLM step executed during the stream
OUTPUT
Parsed structured output (only when experimental_output is specified)
UIMessage[]
Accumulated UI messages (only when collectUIMessages: true)

Examples

Basic Usage

With Tools

Structured Output

Dynamic Context Management

Type Definitions

ToolSet

ModelMessage

StepResult

Best Practices

  1. Use workflow steps for tools: Mark tool execute functions with 'use step' for automatic retries and durability
  2. Set maxSteps: Always set a reasonable maxSteps limit to prevent infinite loops
  3. Handle errors gracefully: Use onError callback to log and handle errors appropriately
  4. Manage context size: Use prepareStep to inject/remove messages dynamically and manage context window
  5. Stream to the client: Always use getWritable() to stream responses for better UX
  6. Choose the right model: Use prepareStep to switch models based on task complexity

See Also