What is a workflow?
A workflow is a Python function decorated with@workflow. It can contain steps, call other workflows, wait for events, and use normal programming constructs like loops and conditionals.
- Durable - Survive crashes and resume from the last completed step
- Stateful - Maintain context across execution
- Composable - Call other workflows and wait for results
- Observable - Track execution with real-time events
Why workflows?
Traditional functions fail completely when something goes wrong. Workflows persist progress at each step: Without workflows:Workflow context
Every workflow receives aWorkflowContext with execution metadata and methods:
Key concepts
Steps
Steps are the unit of durability. Each step’s output is persisted when the step completes.Workflow composition
Workflows can call other workflows or agents. They can wait for those to complete or simply trigger them as fire-and-forget.Control flow
Use normal Python control flow:Waits and events
Workflows can pause and resume:Starting workflows
Workflows can be started in three ways:1. Invoke using API or SDK
ctx.step.batch_invoke() or ctx.step.batch_agent_invoke() when calling from within workflows. See Steps for details.
2. Scheduled execution
3. Event-triggered
Key takeaways
- Workflows are durable functions - They survive failures and resume from the last completed step
- Steps are the unit of durability - Each step’s output is persisted
- WorkflowContext provides execution metadata - Access IDs, timestamps, and step methods
- Compose workflows - Call other workflows and wait for results
- Use normal Python control flow - Conditionals, loops, and parallel execution
- Start workflows - Via API, schedule, or events