Workflow class enables you to build structured, multi-step AI workflows with agents, teams, or custom functions. Workflows provide explicit control over execution flow with support for loops, conditionals, parallel execution, and human-in-the-loop interactions.
Constructor
Core Parameters
A descriptive name for the workflow.
Unique identifier for the workflow. Auto-generated if not provided.
A description of what the workflow does.
The steps to execute in the workflow. Can be a callable, Steps object, or list of Step objects.
Database
Database for storing workflow sessions and run history.
Session & State
Default session ID for the workflow.
Default user ID for the workflow.
Session state stored in database to persist across runs.
If True, overwrites stored session_state with provided session_state.
History
If True, adds workflow history to step executors.
Number of historical runs to include in messages.
Streaming
Stream the response from the workflow.
Stream intermediate step events.
Stream events from executors (agents/teams) within steps.
Storage
Persist events on the run response.
Store executor responses (agent/team responses) in flattened runs.
Events to skip when persisting.
Validation
Pydantic model to validate workflow input.
Metadata stored with the workflow.
Methods
run()
Execute the workflow.message(str): The input message (if workflow uses default parameters)- Or pass custom parameters matching your workflow definition
stream(bool): Whether to stream the responsesession_id(str): Optional session IDuser_id(str): Optional user ID
WorkflowRunOutput or Iterator of events if streaming
arun()
Async version ofrun().