Skip to main content
Workflows orchestrate steps in a DAG: you define what runs, Timbal infers dependencies and runs independent steps in parallel. Use them when the path is predictable (ETL, gated deploys, fan-out/fan-in, LLM routing) rather than leaving every decision to the model.

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

  1. Control flow — parallel execution, step_span(), depends_on, wiring data between steps
  2. Branching — conditional steps with when
  3. Errors & failure — what happens when a step fails or is skipped
  4. Agents & LLMs — agents as steps, LLM routing patterns
  5. Human in the loop — approval gates on workflow steps
  6. 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):
Each step name must be unique within the workflow. Timbal detects cycles when you link steps and raises if the graph would loop.

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):
Fixed values passed in .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:
See Workflow Composition for a full example.

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