LoopFlow
Tutorial Workshop Keywords 🎮 LoopFlow Lab
Keywords / when … (transitions)

when … (transitions)

Rules evaluated after each observe. Core syntax

Syntax

when it passes and the goal is met: stop
when it fails: reflect, then plan again
when blocked: ask a human

What it does

when … rules are the loop's transitions — they run after each observe and decide what happens next. Conditions: it passes · it passes and the goal is met · it fails · blocked. Actions: stop · stop and warn · reflect · plan · act · observe · ask a human.

These lines are what make a loop self-correcting rather than a one-shot prompt. when it fails: reflect, then plan again is the back-edge: it turns a failed check into a diagnosis that feeds the next plan, so the loop learns within a run instead of repeating the same mistake. For that diagnosis to reach the next plan, end look at: with and the last failure. when blocked: ask a human is the escape hatch for when the agent genuinely can't proceed. Together they cover the three outcomes of every cycle: done, retry, or stuck.

Precedence is fixed by the engine, not by the order you write the lines: blocked > attempts > pass > fail. That ordering is deliberate — after N tries (attempts) is checked before it fails, so once you hit the try ceiling the thrash guard always wins and a failing loop can't reflect-and-retry forever. Never write a reflect back-edge without also giving the loop a hard stop; the last line of a loop is its ceiling.

Example

when it passes and the goal is met: stop
when it fails: reflect on which layer broke, then plan again
when blocked: ask a human
transition rules

How it runs

AFTER EACH OBSERVE — FIRST MATCH WINS 1blocked? ask a human 2after N tries? stop & warn ⚠ 3passes & goal met? stop ✓ done 4it fails? reflect, then plan again
The order is the engine's, not yours: attempts is checked before fail, so the thrash guard always wins once you hit the limit.

Common mistakes

Related