Workflow vs Agent
They share the same interface: call a Runnable to get an event stream, or chain
.collect() for the final OutputEvent. A common pattern is a workflow that routes to agents (classify → specialist agent). See Agents & LLMs.
Reading guide
- Control flow — parallel execution,
step_span(),depends_on, wiring data between steps - Branching — conditional steps with
when - Errors & failure — what happens when a step fails or is skipped
- Agents & LLMs — agents as steps, LLM routing patterns
- Human in the loop — approval gates on workflow steps
- Examples below — copy-paste pipelines for common shapes
Quickstart
Functions used as steps must accept and return Pydantic-serializable types (
str, int, float, bool, dict, list, BaseModel). Custom classes that aren’t Pydantic models cannot be passed between steps.Adding steps
Use.step() to add a Runnable (function, Tool, Agent, or nested Workflow):
Workflow inputs
Keyword arguments passed to the workflow are forwarded to steps. Parameters without a default on a step become workflow-level inputs (merged into the workflow’s params schema):.step(name, key=value) are defaults for that step only and are not exposed as workflow inputs.
Output
The workflow returns the last executed step’s output. If you need multiple step results, add a final merge step:Running
Composition
Nest workflows as steps. The inner workflow’s final output becomes that step’s output:Examples
Sequential steps
Chain steps with data passing between them
Parallel fan-out
Fetch from multiple sources concurrently, then merge
Conditional routing
Route to different handlers based on validation
Workflow composition
Nest an inner workflow as a step