Skip to main content

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:
When validation fails:
  1. The step is retried (up to max_retries)
  2. Validation feedback is passed to the step via ctx.variables["validation_feedback"]
  3. 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.
Example:

Step Types

Workflows accept three types of steps:
  1. Functions - Automatically wrapped as handlers
  2. Agents - Executed with the input
  3. Task - Full configuration

Task

A dataclass representing a single step in a workflow.

Constructor

Parameters

Handler Function

Custom handler functions receive WorkflowContext and return StepResult:

should_run Function

Conditional execution - return True to run the step, False to skip:

Agent Config Options

When using agent_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 as execute().

Example


list_workflows()

List all available workflows.

Returns

List of Workflow 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

Every action 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.
Example:

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.
Examples:
In your handler, access the current item:

repeat() - Evaluator-Optimizer Pattern

Repeat a step until a condition is met.
Example:

Pattern Combinations

Patterns can be combined for complex workflows:

See Also

Workflows Guide

Complete workflows documentation

Agent API

Agent class reference