What are Workflows?
Workflows are programmable execution pipelines that orchestrate step-by-step processing with explicit control flow.Building Blocks of a Workflow: Steps
Steps are the core units of work, which can process data, perform actions and pass results onward.Adding Steps to the Workflow
Use.step() to add steps to workflows. Any Runnable is valid to create a step.
Functions used as workflow steps must accept and return Pydantic-serializable types (e.g.,
str, int, float, bool, dict, list, BaseModel). Custom classes that aren’t Pydantic models cannot be passed between steps.Step Names and Reusing Functions
Each step in a workflow must have a unique name. Like all Runnables, steps are identified by their names, which must be distinct within the workflow. To use the same function multiple times in a workflow, wrap it in a new Tool with a distinct name for each usage:Step Context
The input and output from each step is stored in its Run Context, accessible viaget_run_context().current_span(). You can also store custom variables and access data from sibling steps.
See Control Flow for details and Context & State Management for the full reference.
Running the Workflow
The workflow’s final output is determined by the last executed step in the dependency graph. To run the workflow and receive directly the final output, use thecollect() method:
Workflow Output
When you run a workflow, only the last executed step’s output is returned. If you need outputs from multiple steps, create a final step that receives all of them and combines them:Composition
Workflows can contain other workflows as steps:Integrating LLMs
Using Agents
Best for autonomous AI that needs to reason, use tools, and maintain conversation context:Key Features
- Composition: Workflows can contain other workflows
- Parallel Execution: Independent steps run concurrently
- Automatic Dependencies: Lambda parameters create implicit execution order
- Type Safety: Automatic parameter validation via Pydantic
- Error Isolation: Failed steps skip dependents, others continue