Appearance
Add a loop
An agent that repeats work can run all night. A loop repeats steps once for each plan item, checks a gate after every iteration and stops at a limit you set. Read this page when the same steps repeat for each item of an approved plan. It builds on Write a workflow.
The example is a software one: write a failing test, make it pass, validate. A loop for other work has the same keys and other steps. The file is illustrative.
agentPlana list of plan items
youYou approvethe exact plan
repeat for each plan item · up to the loop limit↺ proof still fails? another iteration · at the loop limit: the run fails or waits for you
agentWrite the proofa test for the next plan item
codeProof shown to failbefore the work
agentDo the workmake the proof 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 of proof, work and validation for each plan item, and an effect, the step that delivers the result (here, it opens a pull request).
Add the loop
Use a loop when the same steps repeat for each plan item. A plan item is one entry of the approved plan. The files call it a criterion.
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 engine: <engine> prompt: Write a plan with checkable criteria. outputs: [plan] scope: nothing - id: approve-plan kind: human waiting_for: approval - id: red-green loop: over: plan as: criterion until: verdict.all_covered max: 10 on_exhausted: ask steps: - id: proof kind: agent engine: <engine> prompt: Write a failing test for the criterion. outputs: [change] freeze: ["tests/**"] scope: ["tests/**"] - id: work kind: agent engine: <engine> prompt: Make the test pass. outputs: [change] scope: ["src/**", "tests/**"] - id: check kind: verify validators: [project, daggry/criterion-coverage] - id: ask kind: human waiting_for: input-needed - id: pr kind: effect do: open-prSet the loop keys. Every key is required.
Key Meaning overThe list to loop over. Use plan, the items of the approved plan.asThe name of the current item. untilThe gate: the rule that decides whether the loop can stop. Daggry reads it at the end of each iteration. maxThe loop limit: the most iterations the loop can run. It counts the whole loop, not each item. on_exhaustedWhat happens at the limit: fail, or theidof a top-levelhumanstep.stepsThe steps of one iteration. Set
maxgreater than the number of plan items you expect, or the loop cannot finish. Themaxof 10 here assumes a plan of fewer than 10 items.
The gate verdict.all_covered holds when every plan item has passed. The built-in validator daggry/criterion-coverage works that out, so the verify step names it. A loop cannot contain another loop.
How an iteration ends
You need this to read a run's status. An iteration either moves on or repeats, and the verify step decides which.
One iteration for each plan item, up to the loop limit
- agentWrite the proofa test for the next plan item
- codeShown to failbefore the work
- agentDo the workchange the paths in scope
- codeRun again on a clean copyevery validator
Plan items left, or this one failed: another iteration
Gatethe rule that lets the loop stop
- every plan item coveredNext step
- loop limit reachedFails, or a person decides
human step the workflow names. In software, the proof is a test. The diagram shows one iteration, the gate after it and the exit at the loop limit. When the limit is reached, the run fails or a person decides.
- The
verifystep passes. The loop moves to the next plan item. - The
verifystep fails. The same plan item repeats. The proof step does not run again. - Any other step fails. The run fails.
Each repeat spends one iteration of max.
Prove each item first
A test that already passes says nothing about the work. So the first step of the iteration writes a proof: a test that fails first, then passes. Software teams call this red, then green.
The freeze key marks the proof step. Each iteration then runs in this order.
- The proof step writes a test for the next plan item.
- Daggry runs the project's main validator on the version of the workspace the run started from, with the new test added. The proof counts only if the test fails there.
- Daggry seals the change and freezes the paths the proof step wrote, matched by the
freezeglobs. No later step can change a frozen path, whatever its scope. - The agent does the work that makes the test pass.
- The validators check the result on a clean copy of the workspace.
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 the limit is reached
Decide this before the run, because it is what stops an agent that is stuck. on_exhausted says what happens after max iterations.
- With
fail, the run fails. - With the
idof ahumanstep, the run stops there for your approval. Daggry skips that step unless the loop reaches its limit.
At that approval you have two choices.
- To give up the unfinished plan item and continue, run
daggry approve <run-id>. - To retry it with one frozen path open to change, run
daggry approve <run-id> --unfreeze <path>.
Related: