Creating a workflow
Create a file insrc/workflows/:
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:

Persistent state
Add astate 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:| Expression | Schedule |
|---|---|
"0 9 * * *" | Every day at 9:00 AM |
"0 */6 * * *" | Every 6 hours |
"*/30 * * * *" | Every 30 minutes |
"0 0 * * 1" | Every Monday at midnight |
As a tool
Convert a workflow to a tool so the AI model can start it duringexecute():
Deduplication
UsegetOrCreate() to avoid starting duplicate workflows:
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 thetimeout prop to change this:
Handler parameters
| Parameter | Type | Description |
|---|---|---|
input | object | Validated input matching the workflow’s input schema |
state | object | Mutable workflow state, persisted across executions |
step | function | Step function for persistence and control flow |
client | object | Botpress client for API calls |
execute | function | Run the AI model (same as in conversations) |
signal | AbortSignal | Indicates when the workflow should stop |
workflow | object | Current workflow instance (id, name, tags, cancel, complete, fail, setTimeout, execute) |
