# Review loops

> Building flows · https://spoletta.com/docs/loops

A review loop sends work back until it is good: a critic, an agent or a person, decides the work is weak, the writer revises it with the critic's instructions, and the critic looks again.

*Diagram: Write is the start; Post entering weak brings it back with the Critic's instructions.*

## A writer and a critic

1.  **The writer is the start**
    
    Add *Write* (agent) yielding *Post*, and point Start at it. Give Post the states `good` and `weak`.
    
2.  **The critic reviews**
    
    Add *Critic* (agent) taking Post, link it back to Post and pick both states with **Decide a state**. Its prompt says what good is: *accurate, concrete and under 900 words; otherwise weak. When weak, say exactly what to change.*
    
3.  **Close the loop**
    
    Drag from Post's `weak` pill onto Write: an event link. From `good`, link to whatever comes next, here a person who publishes.
    

A run goes: Write, Critic (weak), Write again, Critic, and so on. Every process runs at most once per pass, but a decision starts a fresh pass from the object, so the loop can repeat.

## Change requests

When a reviewer sends work back, the process taking it in that state gets a **change request**: the reviewed work and the reviewer's instructions, in place of the object as a plain input. The revising agent sees something like:

In the agent's prompt:

```text
The reviewer "Critic" marked the work below as "weak". Act on it following their instructions.
<reviewed name="Post" state="weak">…</reviewed>
<change_request>Cut the intro to two sentences.</change_request>
```

## When the writer isn't the start

A process with an event link runs only on its events (or from the start, or a next). So if each run needs a person to enter the topic first, Write is no longer the start, and a single Write with an event link would never write the first version. Split it in two:

-   **Draft** takes the person's input and writes the first version.
-   **Revise** takes the work in `changes requested` (an event) and writes it again.

Neither takes the work plainly: a process taking what it writes would wait for it before it could ever write it. The reviewer, though, takes it plainly, so it runs again each time a new version is handed in.

OPL:

```text
Draft takes Release.
Draft yields Notes.
Approve decides whether Notes is approved, changes requested or rejected.
Notes entering changes requested triggers Revise.
Revise yields Notes.
Notes entering approved triggers Post.
```

## Not looping forever

An agent reviewer's **Rounds** (default 3, up to 20) bounds the loop. Once it has run that many times, a decision that would send the work back to a process that already ran fails the critic instead, which ends that branch. A person can loop as long as they like.

> **Handle the last round:** To publish anyway rather than fail the run, drag an *on failure* connection from the Critic to a process such as *Publish anyway*. See [Handling failure](https://spoletta.com/docs/failures.md).
