Core Concept
Workflows are:- Graph-based: Chain steps with
.then(),.branch(),.parallel() - Type-safe: Full TypeScript inference across step inputs/outputs
- Resumable: Suspend execution and resume from any step
- Composable: Nest workflows within workflows
- Observable: Track execution with observability spans
Basic Workflow
Create a simple sequential workflow:Workflow Configuration
Chaining Steps
Sequential Execution
Use.then() to chain steps sequentially:
Dynamic Mapping
Map specific fields from previous steps:Branching
Conditionally execute different steps:Multiple Branches
Parallel Execution
Run multiple steps concurrently:Agent Steps
Wrap agents as workflow steps:Tool Steps
Use tools as workflow steps:State Management
Maintain workflow state across steps:Suspend and Resume
Suspend execution for human approval or external input:Error Handling
Handle step failures with retries:Nested Workflows
Compose workflows within workflows:Streaming Output
Stream workflow progress in real-time:Workflow Runs
Manage workflow execution:Observability
Workflows automatically create spans for observability:- Workflow execution span
- Step execution spans
- Step input/output data
- Timing information
Best Practices
Use descriptive step IDs
Use descriptive step IDs
Use clear, descriptive IDs for better observability:
Handle errors at appropriate levels
Handle errors at appropriate levels
Use retries for transient failures, error handlers for expected errors:
Use parallel steps for independent operations
Use parallel steps for independent operations
Execute independent operations concurrently:
Use state for complex workflows
Use state for complex workflows
Store workflow state for multi-step coordination:
Related Resources
- Agents - Autonomous AI systems
- Tools - Tool composition patterns
- Memory - Conversation persistence
- Mastra Class - Central orchestrator