Workflow API
PraisonAI provides a simple, powerful workflow system for chaining agents and functions.Quick Start
Import
Pipeline and Workflow are interchangeable - they refer to the same class.
Use whichever term fits your mental model better.Callbacks
Workflow supports callbacks for monitoring and custom logic:Guardrails
Add validation to steps with automatic retry:- The step is retried (up to
max_retries) - Validation feedback is passed to the step via
ctx.variables["validation_feedback"] - For agent steps, feedback is appended to the prompt
Status Tracking
Track workflow and step execution status:WorkflowContext
Context passed to step handlers containing workflow state.Constructor
Attributes
StepResult
Result returned from step handlers.Constructor
Attributes
Example
Workflow
A complete workflow with multiple steps.Constructor
Parameters
Methods
start()
Run the workflow with the given input.
Returns:
Dict with output, steps, variables, and status
astart() / arun()
Async version of start() for async workflow execution.Step Types
Workflows accept three types of steps:- Functions - Automatically wrapped as handlers
- Agents - Executed with the input
- Task - Full configuration
Task
A dataclass representing a single step in a workflow.Constructor
Parameters
Handler Function
Custom handler functions receiveWorkflowContext and return StepResult:
should_run Function
Conditional execution - returnTrue to run the step, False to skip:
Agent Config Options
When usingagent_config, you can specify:
Example
Branching Example
Loop Example
Workflow
A dataclass representing a complete workflow with multiple steps.Constructor
Parameters
Example
WorkflowManager
The main class for managing and executing workflows.Constructor
Parameters
Methods
execute()
Execute a workflow synchronously.Parameters
Returns
Example
aexecute()
Execute a workflow asynchronously.Parameters
Same asexecute().
Example
list_workflows()
List all available workflows.Returns
List ofWorkflow objects.
Example
get_workflow()
Get a specific workflow by name.Parameters
Returns
Workflow object or None if not found.
create_workflow()
Create a new workflow file.Parameters
Example
get_stats()
Get workflow statistics.Returns
reload()
Reload workflows from disk.Variable Substitution
Everyaction string supports {{placeholder}} substitution, applied in this order:
For the full substitution pipeline and auto-append behaviour, see How Action Templating Works.
For date/time/UUID placeholders (
{{today}}, {{now}}, {{uuid}}), see Dynamic Variables — a separate mechanism.
Example
list_checkpoints()
List all saved workflow checkpoints.Returns
List of checkpoint info dicts with keys:name, workflow, completed_steps, saved_at.
Example
delete_checkpoint()
Delete a saved checkpoint.Parameters
Returns
True if deleted successfully, False if not found.
Example
Workflow Patterns
PraisonAI provides helper functions for common workflow patterns.Import
route() - Decision-Based Branching
Routes to different steps based on the previous output.parallel() - Concurrent Execution
Execute multiple steps concurrently and combine results.Parameters
Failure Strategies
Examples:
loop() - Iterate Over Data
Execute a step for each item in a list, CSV file, or text file.repeat() - Evaluator-Optimizer Pattern
Repeat a step until a condition is met.Pattern Combinations
Patterns can be combined for complex workflows:See Also
Workflows Guide
Complete workflows documentation
Agent API
Agent class reference

