Skip to main content

Workflow Routing

Route workflows to different paths based on the output of a decision step. This pattern is also known as Agentic Routing or Conditional Branching.
Steps inside this pattern inherit the same max_retries, guardrails, and output_file policies as top-level steps. See Nested workflows → Retry, guardrails, and output_file.
The user supplies inputs; routing chooses the next branch at runtime.

Quick Start

1

Define classifier and handlers

2

Route by classifier output

API Reference

route()

Parameters

How Matching Works

The router checks if any route key (case-insensitive) is contained in the previous step’s output:

Examples

Multi-Step Routes

Each route can contain multiple steps:

Chained Routing

Routes can be chained for complex decision trees:

With Agents

Routes can include Agent instances:

Use Cases

How It Works


Best Practices

Handle unexpected classifier output gracefully instead of failing the workflow.
Short, distinct keys reduce mis-routing when LLM output is noisy.
One clear purpose per branch simplifies testing and observability.
Record which route was taken to debug triage and moderation pipelines.

Workflow Patterns

Overview of routing, parallel, loop, and repeat

Workflow Parallel

Run independent steps concurrently

Workflow Loop

Iterate over lists and files

Workflow Repeat

Repeat until a condition is met