Skip to main content
Workflows enable you to orchestrate multiple agents and executors in a graph-based structure. They provide control flow, state management, and coordination for complex multi-step processes.

Core Concepts

Executors

Executors are the nodes in a workflow graph. They process inputs and produce outputs:
  • Function Executors: Standalone functions decorated with @executor
  • Agent Executors: Agents that can be used as workflow nodes
  • Custom Executors: Classes that inherit from Executor

Edges

Edges connect executors and define the flow of data:
  • Single Edge: One-to-one connection
  • Fan-Out: One executor sends to multiple downstream executors
  • Fan-In: Multiple executors send to one downstream executor
  • Conditional: Branching based on runtime conditions

Workflow Context

The WorkflowContext object provides methods to:
  • Send messages to downstream nodes
  • Yield workflow outputs
  • Access workflow state
  • Manage execution flow

Creating Executors

Function Executor with @executor

Class-Based Executor

Agent Executor

Use agents directly as workflow nodes:

Building Workflows

Simple Linear Workflow

Workflow with Agents

Explicit Type Parameters

Specify input/output types explicitly on @handler:

Running Workflows

Non-Streaming Execution

Streaming Execution

Advanced Control Flow

Conditional Branching

Fan-Out (Parallel Processing)

State Management

Workflow State

Workflows maintain state across executions:

State Isolation

Create fresh workflows for each run:

Checkpointing

Save and resume workflow state:

Orchestration Patterns

Sequential Orchestration

Concurrent Orchestration

Human-in-the-Loop

Sub-Workflows

Embed workflows within other workflows:

Declarative Workflows

Define workflows using YAML:
Load and run:

Observability

Event Types

Telemetry

Workflows automatically emit OpenTelemetry traces and metrics:

Visualization

Visualize workflow graphs:

Best Practices

Always wrap workflow creation in a function to ensure fresh state:
Implement error handling in executors:
Enable checkpointing for workflows that may need to resume:
Identify independent tasks that can run concurrently to improve performance.
Each executor should have a single, well-defined responsibility. This makes workflows easier to understand and maintain.

API Reference

WorkflowBuilder

WorkflowContext

Workflow

Examples

Content Creation Pipeline

  • Agents - Using agents in workflows
  • Middleware - Workflow-level middleware
  • Tools - Tools available to workflow agents