Appearance
Add a loop
Work is rarely right the first time, and an agent that keeps trying with no limit can run all night. A loop repeats its steps until the work is done, checks a gate after every iteration and stops at a limit you set. Read this page when one pass is not enough: the agent should keep working on what still fails. It builds on Write a workflow.
A loop seals nothing of its own. The steps of each iteration seal their change, measurements and verdicts, so the evidence trail shows every iteration, passed or failed. The example is software: write failing tests, make them pass, validate. The file is illustrative.
agent · plannerPlana list of criteria
youYou approvethe exact plan
repeat until every criterion is covered · up to the loop limit↺ a proof still fails? another iteration on what is left · at the loop limit: the run fails or waits for you
agent · test-writerWrite the proofsa test for every criterion, once
codeProofs shown to failbefore the work
agent · implementerDo the workmake the failing proofs pass
codeRun again on a clean copyevery validator
codeDeliver the resultan effect, for your review
The diagram shows the workflow this page builds: a plan, your approval, a loop that repeats until every proof passes, and an effect that delivers the result as a pull request.
Add the loop
A loop needs two things: what "done" means, and how often to try.
Add a loop entry after the approval. A loop entry has an
idand aloopkey, and nokind.yamlformat: daggry/workflow@1 steps: - id: plan kind: agent persona: planner outputs: [plan] scope: nothing - id: approve-plan kind: human of: plan - id: build loop: until: verdict.all_covered max: 5 steps: - id: proof kind: agent persona: test-writer outputs: [change] freeze: ["tests/**"] scope: ["tests/**"] - id: work kind: agent persona: implementer outputs: [change] scope: ["src/**", "tests/**"] - id: check kind: verify validators: [project] judges: [coverage] - id: pr kind: effect do: open-prSet the loop keys.
Key Meaning untilThe gate: what "done" means. It reads facts from sealed verdicts and runs nothing. Here the loop is done when every criterion of the plan is covered. maxThe loop limit: the most iterations the loop can run. stepsThe steps of one iteration. Set
maxto the number of tries you are willing to pay for. Most work that will pass does so in a few iterations.
The coverage judge works out verdict.all_covered when the verify step names it in judges. A loop cannot contain another loop.
How the loop runs
Each iteration works on everything that is still open, and each repeat has less to do.
the persona worksthe sealed verdict after verify
Iteration 1The persona works on the whole plan.
AC-1 passAC-2 passAC-3 failAC-4 failAC-5 passGate: all_covered is false. Two findings go back to the persona.
Iteration 2The persona works on the two that fail.
AC-1 passAC-2 passAC-3 passAC-4 failAC-5 passGate: all_covered is false. One finding goes back.
Iteration 3The persona works on the last one.
AC-1 passAC-2 passAC-3 passAC-4 passAC-5 passGate: all_covered is true. The loop ends, inside its limit of 5.
The diagram shows one loop over three iterations: the failing criteria shrink from two to one to none, and the gate reads the sealed verdict after each iteration.
- The gate holds. The loop ends, and the run goes on.
- The gate does not hold. The steps run again. The agent gets only the findings that still fail, with the tail of the validator's output. The proof step does not run again.
- An
agentorcommandstep fails. The run fails.
Each repeat spends one iteration of max, and its records stay in the trail beside the ones that passed.
Prove the work first
A test that already passes says nothing about the work. So the loop starts with a proof step: tests that fail first, then pass. Software teams call this red, then green.
The freeze key marks the proof step. It runs once, in the first iteration.
- The proof step writes a test for every criterion of the plan.
- Daggry runs the project's main validator on the version of the workspace the run started from, with the new tests added. The proof counts only if a test for every criterion fails there.
- Daggry seals the tests and freezes them. No later step can change a frozen path, whatever its scope.
- The agent does the work that makes the tests pass.
- The validators measure the result on a clean copy, and the judges decide. While a test still fails, the loop repeats from step 4.
A loop with no proof step, such as a document review, starts at step 4. For frozen paths, see What an agent cannot change.
When should a loop take one criterion at a time?
Add over: plan and as: criterion to the loop, and each iteration takes one criterion: its own proof, its own work and its own verify run.
the defaultThe whole plan in each iteration
- One persona start for each iteration
- One verify run for each iteration
- Proofs written and frozen once
- A repeat sees only what still fails
with over and asOne criterion in each iteration
- A persona start for each criterion, and for each repeat
- A verify run for each of them
- A proof written and frozen for each criterion
- Each criterion sealed and judged on its own
The diagram compares the two shapes. One criterion at a time costs more: an agent starts again for each criterion, re-reads the project, and every iteration runs the validators and seals its records. Use it when the criteria are large or independent, when the whole plan would not fit in one agent session, or when you want each criterion checked and sealed on its own. See One item at a time.
When the limit is reached
The limit is what stops an agent that is stuck. What happens next depends on the workflow.
- A checkpoint follows the loop. The run goes on to it, and Daggry asks you and says what is unfinished. Reply, and the loop goes round again with a fresh limit and what you said. Say yes, and the run goes on with the result as it is.
- No checkpoint follows. The run fails and says why.
If the agent believes a frozen test is wrong, it asks you on the issue, and your yes opens that one path once.
Related: