Skip to main content

What are Workflows?

Workflows in LlamaIndex.TS provide an event-driven architecture for building complex agent systems. Instead of linear code execution, workflows:
  • React to events as they occur
  • Define handlers for different states
  • Enable stateful multi-step processes
  • Support parallel and conditional execution

When to Use Workflows

  • Building complex agents with multiple decision points
  • Creating multi-agent systems with coordination
  • Implementing custom RAG patterns
  • Orchestrating long-running processes
  • Debugging and monitoring agent behavior

Core Concepts

Events

Events carry data between workflow steps:

Handlers

Handlers process events and emit new ones:

State Management

Maintain state across workflow steps:

Complete Working Example: Joke Generator

This example shows a workflow that iteratively improves a joke:

Workflow Patterns

Linear Pipeline

Sequential processing steps:

Conditional Branching

Route events based on conditions:

Looping with State

Iterate until a condition is met:

Parallel Processing

Handle multiple events simultaneously:

Event Streaming

Stream workflow events in real-time:

Debugging Workflows

Event Logging

Log all events for debugging:

State Inspection

Access workflow state:

Building Custom Agent Workflows

Workflows are the foundation for the agent() helper. You can build custom agent patterns:

Next Steps