---
title: "Control flow: conditions, loops, gates"
description: "The four connection flow types (Always, Conditional, Approval Gate, Loop) and when to use which."
slug: guides/building-workflows/control-flow-conditions-loops-gates
section: guides
subsection: building-workflows
canonical_url: https://cerevisor.com/docs/guides/building-workflows/control-flow-conditions-loops-gates
last_verified: 2026-05-18
last_verified_version: "1.2.0"
updated_at: 2026-05-18T15:08:18.053416+00:00
---

Every connection has a **flow type** that controls when it fires. Four types are supported. Open the Connection Config popup (double-click a connection) and pick from the Flow type dropdown, or use the right-click → Flow Type submenu for a quick switch.

## Always (default)

The downstream agent runs as soon as the upstream finishes. No conditions, no gates. This is what you want 95% of the time.

Edge appearance: solid line, role-accent gradient.

## Conditional

The downstream runs only if a natural-language condition evaluates true on the upstream's output.

Open Connection Config and fill in:

- **Condition**: natural-language. e.g. "the researcher's output mentions Horizon Europe funding."
- **Condition label**: short text shown on the edge (optional).
- **Is else branch?**: if true, the edge fires when the condition is *false*.

Conditional edges are evaluated by an LLM-as-judge pass over the upstream output. The judge runs on the same provider as the upstream agent (cheap call, usually Haiku-class).

### When to use

- Routing: send "high confidence" results to a fast writer, "low confidence" to a senior reviewer.
- Branching: if a researcher finds no sources, send to an escalation agent instead of the writer.
- Veto: if a reviewer says "this is wrong", route back to the original author instead of proceeding.

### Patterns

Two conditional edges from the same source: one for the true branch, one with **Is else branch** set, give you an if/else split. The orchestrator guarantees exactly one fires.

Cumulative conditions across multiple edges (three different criteria, three different downstream agents) all fire independently.

## Approval Gate

The workflow pauses. You see a modal showing the upstream's output and an approval prompt. You click **Approve** to continue or **Reject** to halt.

Configure:

- **Approval prompt**: the text shown to you when the gate opens. E.g. "Is this research solid enough to publish?"

### When to use

- High-stakes decisions: before a content agent publishes, before a code agent deploys.
- Cost gates: before a long-running expensive agent kicks off.
- Quality gates: review the upstream output before letting the workflow continue.

The agent on the upstream side of a gate completes normally; the gate sits between completion and downstream startup.

## Loop

The source agent re-runs until an exit condition is met or `maxIterations` is reached. The "target" of a loop is effectively the same agent; it loops back on itself.

Configure:

- **Loop condition**: natural-language exit criterion. E.g. "the draft is at least 600 words and includes all three required sections."
- **Max iterations**: default 3. Hard cap to prevent runaway.

### When to use

- Refine until done: draft → critique → revise until the critique passes.
- Iterative search: query → assess → refine query.
- Convergence: optimization passes that improve a metric.

Each loop iteration runs the agent fresh with the previous iteration's output as additional context. The exit condition is checked against each iteration's output.

If `maxIterations` is hit without the condition passing, the loop exits with the last iteration's output and the workflow continues. The agent card shows a warning badge so you know convergence wasn't achieved.

## Mixing flow types

You can have one source agent with multiple outgoing edges, each a different flow type:

- An **Always** edge to a writer (the normal path).
- An **Approval Gate** edge to a publisher (you sign off before publishing).
- A **Conditional** edge to an escalation agent (if researcher's confidence < 0.6).

The orchestrator evaluates each edge independently. The conditional fires (or doesn't) based on its condition; the gate pauses regardless.

## Visual cues on edges

| Flow type | Edge style | Badge |
|---|---|---|
| Always | Solid, role-accent gradient | (none) |
| Conditional | Solid with a question-mark badge | The condition label (short) |
| Approval Gate | Solid with a pause-icon badge | (none) |
| Loop | Curved, looping back | Iteration count when running |
