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 File Format
Workflows are defined in markdown files with YAML frontmatter:Step 2: Analyze
Analyze the research findings.Step 3: Write Report
Write the final report.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:Error Handling
Configure how steps handle errors:Step 2: Critical Build
This step must succeed.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.
