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

# Nested Workflow with Condition

> Demonstrates using a workflow (containing a Condition step) as a step in an outer workflow.

Demonstrates using a workflow (containing a Condition step) as a step in an outer workflow. The inner workflow decides whether content needs fact-checking before passing results to the outer workflow's writer.

```python nested_workflow_with_condition.py theme={null}
"""
Nested Workflow with Condition

Demonstrates using a workflow (containing a Condition step) as a step
in an outer workflow. The inner workflow decides whether content needs
fact-checking before passing results to the outer workflow's writer.
"""

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.workflow import Condition
from agno.workflow.step import Step
from agno.workflow.types import StepInput, StepOutput
from agno.workflow.workflow import Workflow


def needs_fact_check(step_input: StepInput) -> bool:
    """Check if the previous step's content mentions statistics or numbers."""
    prev = step_input.previous_step_content or ""
    return any(char.isdigit() for char in prev)


def format_for_writer(step_input: StepInput) -> StepOutput:
    """Pass content through for the outer workflow's writer step."""
    prev = step_input.previous_step_content or step_input.input
    return StepOutput(content=prev)


# --- Inner workflow: research with conditional fact-checking ---
researcher = Agent(
    name="Researcher",
    model=OpenAIResponses(id="gpt-5.4"),
    instructions="Research the topic. Include specific dates and numbers where relevant.",
)

fact_checker = Agent(
    name="Fact Checker",
    model=OpenAIResponses(id="gpt-5.4"),
    instructions="Verify the facts in the provided text. Correct any inaccuracies.",
)

inner_workflow = Workflow(
    name="Research with Fact Check",
    description="Researches a topic and conditionally fact-checks the results",
    steps=[
        Step(name="research", agent=researcher),
        Condition(
            name="fact_check_gate",
            description="Fact-check if content contains numbers",
            evaluator=needs_fact_check,
            steps=[Step(name="fact_check", agent=fact_checker)],
            else_steps=[Step(name="pass_through", executor=format_for_writer)],
        ),
    ],
)

# --- Outer workflow ---
writer = Agent(
    name="Writer",
    model=OpenAIResponses(id="gpt-5.4"),
    instructions="Write a polished paragraph from the research provided.",
)

outer_workflow = Workflow(
    name="Research, Check, and Write",
    description="Researches, conditionally fact-checks, then writes",
    steps=[
        Step(name="research_phase", workflow=inner_workflow),
        Step(name="writing_phase", agent=writer),
    ],
)


if __name__ == "__main__":
    outer_workflow.print_response(
        input="What are the key milestones in space exploration?",
        stream=True,
    )
```

## Run the Example

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno cel-python fastapi openai
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeGroup>
      ```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"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `nested_workflow_with_condition.py`, then run:

    ```bash theme={null}
    python nested_workflow_with_condition.py
    ```
  </Step>
</Steps>

Full source: [cookbook/04\_workflows/06\_advanced\_concepts/workflow\_as\_a\_step/nested\_workflow\_with\_condition.py](https://github.com/agno-agi/agno/blob/main/cookbook/04_workflows/06_advanced_concepts/workflow_as_a_step/nested_workflow_with_condition.py)
