> ## 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.

# Loop with CEL end condition: compound exit condition

> Combines all_success and current_iteration to stop when both conditions are met: all steps succeeded AND enough iterations ran.

```python cel_compound_exit.py theme={null}
"""Loop with CEL end condition: compound exit condition.
=====================================================

Combines all_success and current_iteration to stop when both
conditions are met: all steps succeeded AND enough iterations ran.

Requirements:
    pip install cel-python
"""

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.workflow import CEL_AVAILABLE, Loop, Step, Workflow

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
if not CEL_AVAILABLE:
    print("CEL is not available. Install with: pip install cel-python")
    exit(1)

# ---------------------------------------------------------------------------
# Create Agents
# ---------------------------------------------------------------------------
researcher = Agent(
    name="Researcher",
    model=OpenAIChat(id="gpt-5.6-luna"),
    instructions="Research the given topic and provide detailed findings.",
    markdown=True,
)

reviewer = Agent(
    name="Reviewer",
    model=OpenAIChat(id="gpt-5.6-luna"),
    instructions="Review the research for completeness and accuracy.",
    markdown=True,
)

# ---------------------------------------------------------------------------
# Create Workflow
# ---------------------------------------------------------------------------
workflow = Workflow(
    name="CEL Compound Exit Loop",
    steps=[
        Loop(
            name="Research Loop",
            max_iterations=5,
            end_condition="all_success && current_iteration >= 2",
            steps=[
                Step(name="Research", agent=researcher),
                Step(name="Review", agent=reviewer),
            ],
        ),
    ],
)

# ---------------------------------------------------------------------------
# Run Workflow
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    print("Loop with CEL end condition: all_success && current_iteration >= 2")
    print("=" * 60)
    workflow.print_response(
        input="Research the impact of AI on healthcare",
        stream=True,
    )
```

## Run the Example

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

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno cel-python 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 `cel_compound_exit.py`, then run:

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

Full source: [cookbook/04\_workflows/07\_cel\_expressions/loop/cel\_compound\_exit.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/04_workflows/07_cel_expressions/loop/cel_compound_exit.py)


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