LoopFlow
Tutorial Workshop Keywords ๐ŸŽฎ LoopFlow Lab
Keywords / reflect

reflect

Turn a failure into the next plan. Core syntax

Syntax

when it fails: reflect, then plan again

What it does

The back-edge โ€” the loop's working memory. On a failed check, reflect reads the failure output and writes a short diagnosis, which becomes context for the next plan. The difference between retrying blindly and learning from each miss.

Without a back-edge, a loop that fails its done when check simply tries again from the same starting state and tends to make the same mistake โ€” burning tokens on a thrash. reflect breaks that cycle by inserting a diagnosis step between observe and the next plan: it names why the last cycle failed so the next plan starts from a hypothesis instead of a blank slate. You steer what it looks at with reflect on <focus> โ€” for example reflect on which layer broke tells the agent to localize the failure to a component before re-planning. This is within-run memory; its across-run counterpart is remember in, which persists lessons to a file. Two things make reflect actually work: the failure output has to reach the next plan (end your look at: with and the last failure), and every reflect back-edge needs a floor โ€” an after N tries: stop and warn guard โ€” so a loop that can't diagnose its way out eventually halts instead of looping forever.

Example

when it fails: reflect on which layer broke, then plan again
the reflect back-edge
loop "fix the checkout total":
  goal: cart total is correct with tax and discounts
  look at: src/cart/, src/tax/, and the last failure
  done when "pnpm test cart" passes
  each cycle: plan, then act, then observe
  when it fails: reflect on which layer broke, then plan again
  after 6 tries: stop and warn "thrashing on the total"
reflect wired into a full loop, floored by a thrash guard

How it runs

โœ“ pass planeach cycle actmake the change observerun done-when stopgoal met โœ“ when it fails โ†’ reflect, then plan again
Every cycle runs plan โ†’ act โ†’ observe; the done when check decides โ€” pass โ†’ stop, fail โ†’ reflect into the next plan.

Common mistakes

Related