# Loops and Goals

An agent working a ticket can split breadth-first work (many independent targets: every
route module, every open PR, a codebase-wide audit) into a **pipeline on that ticket**: a graph the human
can see, edit and approve before anything runs, instead of a plain prompt the agent
promises to follow. The pipeline is a DAG the board executes in exactly the order its
edges describe ([Loop steps](../reference/loop-nodes.md)), and it renders live on the
ticket as it runs.

## When to reach for one

Default to a single agent doing the work end to end: most tickets, and essentially every
tightly coupled change, are best done that way. Splitting a coupled change only adds
handoff and merge risk. A pipeline pays off only for genuinely independent strands whose
combined work exceeds one comfortable context: a codebase-wide audit, reviewing many open
PRs, or parallel investigations.

When the work is breadth over a list of targets, the coverage should be structural: list
the targets first, then give each child the targets it owns, so "covered everything" is a
property of the graph rather than a claim in a summary.

The children's work reaches the base branch only through the orchestrating ticket: it
merges each child into its own branch, tests the combined result, and hands over one
branch for review. See [Run a Loop](../how-to/run-loop.md).

## One plan, one ticket

For a plan that runs once, the ticket holds both the graph and its execution checkpoint.
Accepting a plan that carries a graph starts it without another planning turn. Execute by
loop uses this ticket's existing agent session to draw a missing graph, then waits for
the human to review it and press Start. No Orchestrate plan, Loop or run of a Loop is needed.

The executor handles joins and approval resumes. Conversations, a worker's question and
a failed review go to the owning agent. It hands control back with `resume_loop_run`.
After the landing step has actually landed the branches, the agent checks the combined
result in one closing turn. Stopping preserves progress rather than replaying paid work.

A big plan can nest. A step may itself be a **phase**: a subticket with its own graph,
branch and executor, no free form agent turn, that merges its workers and passes
verification before the plan moves on. Steps can name a known repository, so work lands in
its own repository and never in an unrelated branch. A step for you (kind `human_task`) hands a real world
step to a person and passes their answers downstream. A graph can be amended while it runs,
but only where nothing has started, so completed work is never replayed. How many steps run
at once is a per level setting, not a size limit: the rest wait for a slot.

A scheduled or event Loop still separates its reusable definition from each Run. Goals
still use that run history and ledger. Existing histories are not migrated.

## Goals: a Loop that runs until it is done

A Loop carrying a `goal` block is a **Goal** (on the **Create ticket** form, **Type** set
to **Goal**). Instead of firing on a clock, each run ends by reporting a verdict, and a
`continue` verdict with budget left fires the next run immediately. A Goal therefore stops
for exactly two reasons: the objective was reached, or a ceiling in
`params.resource_caps` was hit.

The block has two fields, both prose:

- `text`: the objective.
- `done_when`: the acceptance test in your own words, optional. It is deliberately a
  sentence rather than a predicate, because what judges it is a model reading the run
  ledger: "a spot-check of three entries matches the code" steers that better than
  anything the schema could check for you.

Each iteration appends one row to a **ledger**, and the next iteration is handed that
ledger up front, so it starts knowing where the last one got to instead of paying to
rediscover it. A run can report `done` or `blocked` as well as `continue`; both are
terminal, and they are kept separate on purpose, because "I got there" and "I cannot get
there" want different reactions from you.

> [!IMPORTANT]
> Set caps. A Goal that never reports `done` is bounded only by `resource_caps`.
