Skip to main content

Overview

Workflows provide a flexible and extensible component for managing and executing structured sequences of tasks. They are particularly useful for:
  • 🔄 Dynamic Execution: Steps can direct the flow based on state or results
  • Validation: Define schemas for data consistency and type safety
  • 🧩 Modularity: Steps can be standalone or invoke nested workflows
  • 👁️ Observability: Emit events during execution to track progress or handle errors
Supported in Python and TypeScript.

Core Concepts

State

State is the central data structure in a workflow. It’s a Pydantic model that:
  • Holds the data passed between steps
  • Provides type validation and safety
  • Persists throughout the workflow execution

Steps

Steps are the building blocks of a workflow. Each step is a function that:
  • Takes the current state as input
  • Can modify the state
  • Returns the name of the next step to execute or a special reserved value

Transitions

Transitions determine the flow of execution between steps. Each step returns either:
  • The name of the next step to execute
  • Workflow.NEXT - proceed to the next step in order
  • Workflow.SELF - repeat the current step
  • Workflow.END - end the workflow execution

Basic Usage

Simple Workflow

The example below demonstrates a minimal workflow that processes steps in sequence. This pattern is useful for straightforward, linear processes where each step builds on the previous one.

Advanced Features

Multi-Step and Nested Workflows

This advanced example showcases a workflow that implements multiplication through repeated addition—demonstrating control flow, state manipulation, nesting, and conditional logic. Workflow nesting allows complex behaviors to be encapsulated as reusable components, enabling hierarchical composition of workflows. This promotes modularity, reusability, and better organization of complex agent logic.
This workflow demonstrates several powerful concepts:
  • Implementing loops by returning Workflow.SELF
  • Conditional transitions between steps
  • Progressive state modification to accumulate results
  • Sign handling through state transformation
  • Type-safe step transitions using Literal types

Multi-Agent Workflows

The multi-agent workflow pattern enables the orchestration of specialized agents that collaborate to solve complex problems. Each agent focuses on a specific domain or capability, with results combined by a coordinator agent.
This pattern demonstrates:
  • Role specialization through focused agent configuration
  • Efficient tool distribution to relevant specialists
  • Parallel processing of different aspects of a query
  • Synthesis of multiple expert perspectives into a cohesive response
See the events documentation for more information on standard emitter events.

Memory in Workflows

Integrating memory into workflows allows agents to maintain context across interactions, enabling conversational interfaces and stateful processing. This example demonstrates a simple conversational echo workflow with persistent memory.
This pattern demonstrates:
  • Integration of memory as a first-class citizen in workflow state
  • Conversation loops that preserve context across interactions
  • Bidirectional memory updating (reading recent messages, storing responses)
  • Clean separation between the persistent memory and workflow-specific state

Examples

Python

Explore reference workflow implementations in Python

TypeScript

Explore reference workflow implementations in TypeScript