> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Nested Choices

> Route to a single step or a nested sequence of steps based on selector logic.

Demonstrates nested lists in router choices, which are converted into sequential `Steps` containers.

```python nested_choices.py theme={null}
"""
Nested Choices
==============

Demonstrates nested lists in router choices, which are converted into sequential `Steps` containers.
"""

from typing import List, Union

from agno.agent.agent import Agent
from agno.models.openai import OpenAIChat
from agno.workflow.router import Router
from agno.workflow.step import Step
from agno.workflow.types import StepInput
from agno.workflow.workflow import Workflow

# ---------------------------------------------------------------------------
# Create Agents
# ---------------------------------------------------------------------------
step_a = Agent(
    name="step_a", model=OpenAIChat(id="gpt-5.6-luna"), instructions="Step A"
)
step_b = Agent(
    name="step_b", model=OpenAIChat(id="gpt-5.6-luna"), instructions="Step B"
)
step_c = Agent(
    name="step_c", model=OpenAIChat(id="gpt-5.6-luna"), instructions="Step C"
)


# ---------------------------------------------------------------------------
# Define Router Selector
# ---------------------------------------------------------------------------
def nested_selector(
    step_input: StepInput,
    step_choices: list,
) -> Union[str, Step, List[Step]]:
    user_input = step_input.input.lower()

    if "single" in user_input:
        return step_choices[0]
    return step_choices[1]


# ---------------------------------------------------------------------------
# Create Workflow
# ---------------------------------------------------------------------------
workflow = Workflow(
    name="Nested Choices Routing",
    steps=[
        Router(
            name="Nested Router",
            selector=nested_selector,
            choices=[step_a, [step_b, step_c]],
        ),
    ],
)

# ---------------------------------------------------------------------------
# Run Workflow
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    workflow.print_response("Run the sequence", stream=True)
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno fastapi openai
```

**2. Export your OpenAI API key**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Run the example**

Save the code above as `nested_choices.py`, then run:

```bash theme={null}
python nested_choices.py
```

Full source: [cookbook/04\_workflows/05\_conditional\_branching/nested\_choices.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/04_workflows/05_conditional_branching/nested_choices.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.