Workflows
Create and execute reusable multi-step workflows with advanced features like context passing between steps, per-step agent configuration, and async execution. Define complex task sequences in markdown files and execute them programmatically.Key Features
| Feature | Description |
|---|---|
| Context Passing | Automatically pass outputs from previous steps to subsequent steps |
| Per-Step Agents | Configure different agents with unique roles for each step |
| Per-Step Tools | Assign specific tools to each step |
| Async Execution | Execute workflows asynchronously with aexecute() |
| Variable Substitution | Use {{previous_output}} and {{step_name_output}} |
| Planning Mode | Enable planning mode at workflow level |
Quick Start
Workflow Class API
TheWorkflow class provides a powerful programmatic API for creating workflows with functions, agents, and pattern helpers.
Basic Usage
Workflow with Agents
Use Agent objects directly as workflow steps:Planning & Reasoning
Tools per Step
Guardrails & Validation
Output Modes
Control how workflow execution is displayed. Workflows use the same output presets as Agent for consistency.| Preset | Description |
|---|---|
silent | No output (default, fastest) |
status | Tool calls + final output inline |
trace | Timestamped execution trace |
verbose | Full Rich panels |
debug | Trace + metrics |
json | JSONL output for piping |
Output to File
Memory Integration
Async Execution
Status Tracking
Pattern Helpers Reference
| Pattern | Description | Example |
|---|---|---|
route() | Decision-based branching | route({"yes": [step_a], "no": [step_b]}) |
parallel() | Concurrent execution | parallel([step1, step2, step3]) |
loop() | Iterate over list/CSV | loop(handler, over="items") |
repeat() | Evaluator-optimizer | repeat(gen, until=condition, max_iterations=5) |
when() | Conditional branching | when(condition="{{score}} > 80", then_steps=[...]) |
include() | Workflow composition | include(workflow=sub_workflow) |
Robustness Features
Enable execution tracing and graceful degradation for production workflows:[!NOTE]if_()is deprecated in favor ofwhen()for cleaner syntax.
Complete Python Example with All Patterns
Workflow File Format
Workflows are defined in markdown files with YAML frontmatter:Frontmatter Options
| Option | Type | Description |
|---|---|---|
name | string | Workflow name |
description | string | Workflow description |
default_llm | string | Default LLM for all steps |
planning | boolean | Enable planning mode |
planning_llm | string | LLM for planning |
variables | object | Default variables |
Step Options
| Option | Type | Description |
|---|---|---|
context_from | list | Specific steps to include context from |
retain_full_context | boolean | Include all previous outputs (default: true) |
output_variable | string | Store output in custom variable name |
output_file | string | Save step output to file |
loop_over | string | Variable name to iterate over |
loop_var | string | Variable name for current item in loop |
Pattern Blocks
Use code blocks to define workflow patterns:| Block | Description |
|---|---|
```route | Define routing conditions |
```parallel | Define parallel execution steps |
```images | Define images for vision tasks |
```repeat | Define repeat/iteration settings |
Route Pattern Example
Parallel Pattern Example
Loop Pattern Example
Images Pattern Example
Output File Example
Storage Structure
Variable Substitution
Use{{variable}} syntax for dynamic values:
Context Passing
Workflow steps automatically pass context to subsequent steps. Use special variables to access previous outputs:| Variable | Description |
|---|---|
{{previous_output}} | Output from the immediately previous step |
{{step_name_output}} | Output from a specific step (e.g., {{research_output}}) |
Context Control Options
| Option | Default | Description |
|---|---|---|
context_from | All previous | List of step names to include context from |
retain_full_context | True | Include all previous outputs vs only specified |
output_variable | {step_name}_output | Custom variable name for step output |
Conditional Steps
Add conditions to skip steps based on context:Callbacks
Monitor workflow execution with callbacks:Error Handling
Configure how steps handle errors:| Error Mode | Behavior |
|---|---|
stop | Stop workflow on failure (default) |
continue | Continue to next step on failure |
retry | Retry the step up to max_retries times |
Async Execution
Useaexecute() for async workflow execution:
Execute Parameters
| Parameter | Type | Description |
|---|---|---|
workflow_name | str | Name of workflow to execute |
executor | callable | Optional function to execute steps |
default_agent | Agent | Default agent for steps without config |
default_llm | str | Default LLM model |
memory | Memory | Shared memory instance |
planning | bool | Enable planning mode |
stream | bool | Enable streaming output |
verbose | int | Verbosity level (0-3) |
variables | dict | Variables to substitute |
on_step | callable | Callback before each step |
on_result | callable | Callback after each step |
Programmatic API
Best Practices
Use per-step agents for specialized tasks
Use per-step agents for specialized tasks
Configure different agents with specific roles for each step. A Researcher agent for gathering data, an Analyst for processing, and a Writer for output.
Control context passing
Control context passing
Use
context_from to limit which previous outputs are included. This reduces token usage and keeps agents focused on relevant information.Use output_variable for clarity
Use output_variable for clarity
Name your outputs with
output_variable for clearer variable substitution in subsequent steps.Keep steps focused
Keep steps focused
Each step should do one thing well. Break complex tasks into multiple steps for better error handling and visibility.
Use async for parallel workflows
Use async for parallel workflows
Use
aexecute() with asyncio.gather() to run multiple independent workflows concurrently.Set appropriate error handling
Set appropriate error handling
Use
on_error: continue for optional steps and on_error: stop for critical steps that must succeed.CLI Usage
Execute workflows directly from the command line:CLI Options
| Flag | Description |
|---|---|
--workflow-var key=value | Set workflow variable |
--llm <model> | LLM model |
--tools <tools> | Tools (comma-separated) |
--planning | Enable planning mode |
--memory | Enable memory |
--save | Save output to file |
--verbose | Verbose output |
Architecture Patterns
Understanding how Workflow relates to other PraisonAI patterns:Class Hierarchy
| Class | Contains | Purpose |
|---|---|---|
Agent | Self (LLM wrapper) | Core execution unit |
Task | Reference to agent | Work item for agent |
Agents | List of Agent | Multi-agent orchestrator |
Workflow | List of steps | Declarative step orchestrator |
Task | Reference to agent field | Work item with agent reference |
Pattern Comparison
| Concept | Agents Pattern | Workflow Pattern |
|---|---|---|
| Orchestrator | Agents | Workflow |
| Work Item | Task (contains agent ref) | Task (contains agent ref) |
| Executor | Agent | Agent (same!) |
Key Insight: Task is to Workflow what Task is to Agents — it’s a work item that references an agent, not an agent itself.

