step_choices parameter provides ultimate flexibility for dynamic routing, allowing Router selectors to return strings, Step objects, or lists of Steps for chained execution. It enables complex logic where available paths are inspected at runtime rather than hard-coded.
Key Benefits
When your routing logic needs flexible return types or dynamic access to available choices,step_choices is the right tool.
- Flexible Returns: Return string names, Step objects, or lists as needed
- Dynamic Selection: Use
step_choicesto inspect available options at runtime - Step Chaining: Return
List[Step]to execute multiple steps in sequence - Nested Containers: Use nested lists in choices for grouped sequential execution
- Reusable Logic: Build routing functions that adapt to any set of choices
Selector Return Types Summary
| Return Type | Description | Example |
|---|---|---|
str | Step name - Router resolves from choices | return "Tech Research" |
Step | Step object directly | return step_map["writer"] |
List[Step] | Chain multiple steps | return [researcher, writer, reviewer] |
Examples
String Selector
Return step names as strings for simple resolution.
Dynamic Selector
Inspect
step_choices to dynamically select steps.Nested Selector
Select nested lists of steps as a single unit.