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
TheWorkflowContext 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:Observability
Event Types
Telemetry
Workflows automatically emit OpenTelemetry traces and metrics:Visualization
Visualize workflow graphs:Best Practices
Use factory functions for state isolation
Use factory functions for state isolation
Always wrap workflow creation in a function to ensure fresh state:
Handle errors gracefully
Handle errors gracefully
Implement error handling in executors:
Use checkpoints for long-running workflows
Use checkpoints for long-running workflows
Enable checkpointing for workflows that may need to resume:
Design for parallelism
Design for parallelism
Identify independent tasks that can run concurrently to improve performance.
Keep executors focused
Keep executors focused
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
Related
- Agents - Using agents in workflows
- Middleware - Workflow-level middleware
- Tools - Tools available to workflow agents