Skip to main content
Workflows handle multi-step operations that run in the background. Unlike conversations, which respond to user messages, workflows run independently and can be scheduled, started programmatically, or triggered by the AI model. Use workflows for things like data processing pipelines, scheduled tasks, multi-step operations that need retries, or any work that shouldn’t block a conversation.

Creating a workflow

Create a file in src/workflows/:
The input and output schemas define what the workflow accepts and returns. Both use Zod. View running and completed workflows, their status, input, output, and run history from the dev console:
Workflows page in dev console

Persistent state

Add a state schema to carry data across the workflow’s steps and retries. State is persisted between executions:

Starting a workflow

Programmatically

On a schedule

Use a cron expression to run a workflow on a recurring schedule:
Common cron patterns:

As a tool

Convert a workflow to a tool so the AI model can start it during execute():

Deduplication

Use getOrCreate() to avoid starting duplicate workflows:
If a workflow with the same key and one of the specified statuses already exists, it returns the existing instance instead of creating a new one. statuses defaults to ["pending", "in_progress", "listening", "paused"] if you don’t pass it.

Loading a workflow by ID

Workflow instance

When you start a workflow, you get an instance with these methods:

Cancel

Set timeout

Extend or change the workflow timeout:

Complete early

End the workflow from inside the handler with a result:

Fail from inside the handler

Mark the workflow as failed with a reason. This throws immediately and interrupts the handler:

Run autonomous execute

Run the AI model inside the workflow, same as in conversations:

Timeout

Workflows time out after 5 minutes by default. Use the timeout prop to change this:
For workflows that need to run longer than 5 minutes, use steps. Steps break the work into persisted checkpoints so the workflow can resume from the last completed step.

Handler parameters

Last modified on April 27, 2026