# Outcomes

When an agent finishes, it reports a named outcome. ub-agents checks the result on GitHub, removes the agent's trigger labels and applies the labels you declared.

```yaml
outcomes:
  approved: {add: [ready-to-merge]}
  changes-requested: {add: [needs-changes], max-rounds: 3}
```

## Limit rounds

`max-rounds` caps how often an agent can report an outcome on the same item. With the example above, the first three `changes-requested` reports add `needs-changes`. The fourth adds `needs-human` instead, with an **Action needed** comment. Approval still adds `ready-to-merge` at any round.

```flow
flow v0
# max-rounds: three rounds back to the implementer, then a person decides.

columns rework main stop

pill needs-review col=main tone=agent
box reviewer "reviews the exact head commit"
pill ready-to-merge tone=done
end merge "The integrator picks it up"

box implementer col=rework row=needs-review "revises the same PR"
pill needs-changes col=rework row=reviewer tone=rework

panel human col=stop row=reviewer tone=stop
  pill needs-human
  strong "A person decides"
  muted "ub-agents retry resets the count"

needs-review --> reviewer
reviewer --> ready-to-merge : approved, any round
ready-to-merge --> merge
reviewer --> needs-changes tone=rework : rounds 1 to 3
needs-changes --> implementer tone=rework from=top to=bottom
implementer --> needs-review tone=rework
reviewer --> human tone=stop : round 4

legend
  pill tone=done "GitHub label, like ready"
  panel tone=stop "human involved"
```

To allow one more round, swap `needs-human` for `needs-review` by hand. To start the count over, run `ub-agents retry N --agent reviewer --reason TEXT`. The count lives on GitHub, so restarts and other launchers don't reset it; each new pull request starts at zero.

## Add labels

Labels to add. When the agent hands off a pull request, they go on that pull request.

```yaml
handed-off: {add: [needs-review]}
```

## Remove labels

Extra labels to take off. The agent's own trigger labels are always removed.

```yaml
handed-off: {add: [needs-review], remove: [in-progress]}
```

## End of the workflow

An empty mapping changes nothing else.

```yaml
merged: {}
```

## Ask the launcher to merge

A `pr` agent can report its merge decision and exit. The launcher waits for checks and performs the merge:

```yaml
integrator:
  kind: pr
  # Other required agent settings omitted.
  on-conflict: changes-requested
  outcomes:
    merged: {merge: squash}
    changes-requested: {add: [needs-changes]}
```

`merge` accepts `squash`, `merge` or `rebase`. The outcome cannot add a stop label, declare `sub-issues`, or be the agent's `on-conflict` outcome. The agent keeps policy, review, changelog and base-merge decisions, then reports instead of running `gh pr merge`.

The reported `candidate_sha` is the merge target; no new report option is needed. The launcher checks that head against the assigned candidate or its base merge, rereads stop labels, and waits for every check run and commit status on that exact head. Skipped and neutral checks pass. Pending or absent checks wait without a model until the run's `agent-timeout-minutes` deadline, with the lease renewing. After checking mergeability, it merges with a head match and accepts only a confirmed merge on the base branch, recording `candidate_sha` and `merge_commit_sha`. Failed checks and conflicts use `on-conflict`; other refusals block. Closing issues happens afterward; a failed close does not undo acceptance.

Recovery only confirms an existing merge; it never merges. Outcomes without `merge` keep their current behavior. See the [merge gates and recovery](https://github.com/uberblick-ai/ub-agents/blob/main/docs/coordination.md#launcher-merges).

**Upgrading:** every launcher of a project must run a release supporting `merge` before its `ub-agents.yaml` uses the key.

## Start sub-issues

An agent that takes issues can start the native sub-issues its run creates:

```yaml
split: {sub-issues: {add: [needs-preparation]}}
```

Agents file sub-issues without trigger labels, then report `split`. The launcher adds the declared labels, which must be issue-agent triggers, and removes the parent's triggers. With [approvals on](https://agents.uberblick.ai/docs/configuration/approvals.md), sub-issues inherit the parent's start. See the [outcome contract](https://github.com/uberblick-ai/ub-agents/blob/main/docs/coordination.md#explicit-outcomes).

## Ask a person

Add a stop label to park the item for a human decision.

```yaml
maintainer-merge: {add: [needs-human]}
```

## Reporting

The agent reports with one command. Your instructions say which outcome to use when.

```sh
ub-agents report --outcome approved --summary "Checks pass"
ub-agents report --outcome handed-off --summary "Ready for review" --handoff 219
```

After a Claude or Codex run ends, the launcher can record its main-session context
window, first, tenth (or last) and peak prompt token counts, and compaction count
on the outcome and its handoff copies. Missing or invalid context is omitted.
These display-only values do not change results, labels or usage-limit decisions;
see the [coordination record reference](https://github.com/uberblick-ai/ub-agents/blob/main/docs/coordination.md).

## Stop reports

A report that parks the item needs at least one ask: `--action` for each thing a person must do, or `--option` per alternative for a choice, recommendation first. Each ask is one sentence that names who acts. A `max-rounds` stop gets a review request from the launcher if no ask is given.

```sh
ub-agents report --outcome needs-human --summary "Storage policy unclear" \
  --option "Owner: keep storage local." --option "Owner: move storage to the cloud."
```

## Retry and blocked

`--status retry` and `--status blocked` change no labels. Retry runs again after a backoff. Blocked parks the item and also needs `--action` or `--option`.

```sh
ub-agents report --status retry --summary "GitHub returned 502"
```

## Key reference

`outcomes` is a required, nonempty mapping from names to transitions.

| Key | Type and default | Rules |
|---|---|---|
| `add` | List, `[]` | Must not include the agent's own triggers. May add a stop label. |
| `remove` | List, `[]` | Must not include a stop label, and no trigger of the agent may be one. |
| `max-rounds` | Positive integer | Needs a configured stop label, and the outcome must not add one. |
| `sub-issues` | Mapping with only `add` | Nonempty list of `issue` or `either` agent triggers, no stop labels. Agents that take issues only. |
| `merge` | String: `squash`, `merge` or `rebase`; omitted by default | `pr` agents only; no added stop labels or `sub-issues`, and cannot be the agent's `on-conflict` outcome. |

See [explicit outcomes](https://github.com/uberblick-ai/ub-agents/blob/main/docs/coordination.md#explicit-outcomes) for validation,
transition order, stop checks and recovery, and [assignments and attempts](https://github.com/uberblick-ai/ub-agents/blob/main/docs/coordination.md#assignments-and-attempts)
for round counting.
See [launcher merges](https://github.com/uberblick-ai/ub-agents/blob/main/docs/coordination.md#launcher-merges)
for the merge gates and recovery rules.
