Skip to main content
Workflows are long-running processes that handle complex, multi-step operations or scheduled tasks. Unlike conversations, workflows can run independently on a schedule or be triggered by events.
While workflows in the ADK are similar in concept to Workflows in Botpress Studio, they behave differently and shouldn’t be treated as equivalent.

Creating a workflow

Create a workflow in src/workflows/:

Scheduled workflows

Workflows can run on a schedule using cron syntax:

Steps

By default, workflows time out after 2 minutes—if you need to run a workflow for longer, you should use the step function. This lets you break the workflow up into a series of steps that each take only a few seconds to run individually:
Steps are persisted—if a workflow is interrupted, it can resume from the last completed step. This provides better handling when errors occur in complex, long-running workflows.
You can nest steps inside other steps—each step will complete when each of its sub-steps complete.

Reference

The step object also provides many additional methods for workflow control:

Step reference

Learn about all available step methods

Handling failing steps

If a step (or a step method) fails, it’ll throw a rejected promise. This will fail not only the current step, but the entire workflow. To avoid this, make sure you catch errors gracefully:
If the method you’re using has an options.maxAttempts field, it’ll throw an error after the maximum number of retries has been exceeded. You can track the retries using the attempt parameter and catch any errors:

Output

Workflows can return an output that matches the output schema:

Reference

Workflow props

Handler parameters

The handler function receives workflow context and provides step management:

Methods

Workflows can be started and managed programmatically:

workflow.start()

Start a new workflow instance:

workflow.getOrCreate()

Get an existing workflow or create a new one with deduplication:

workflow.asTool()

Convert a workflow into a tool for use with execute():

workflow.provide()

Provide data in response to a workflow data request (used with step.request()):

Helper functions

isWorkflowDataRequest()

Check if an event is a workflow data request:

isWorkflowCallback()

Check if an event is a workflow callback: