choice picks exactly one case from a boolean or a closed string enum that an earlier step
produced. It doesn’t evaluate conditions or make judgments: produce the decision first, with a
task, an agent or a
function through call, then route on it.
Syntax
choice id=route-filing
choice id=route-portfolio
Fields
The fence takes no attributes after
id, and its body takes no other fields.
What you can route on
on must point to a required member whose schema is boolean or a string enum, read from an
input or an earlier step’s output. Open strings, numbers, null, arrays, objects, optional members
and unions can’t be routed. Expressions such as $approval.score > 80 aren’t allowed; compute a
boolean or enum in an earlier step.
Cases
Case keys are strings. Quote them so YAML keeps them as strings.- For a boolean, the keys are exactly
'true'and'false'. - For an enum, the keys are exactly the enum’s values.
- Every value appears exactly once. There is no
defaultcase.
Inline cases hold only data: literals, built objects and references. Anything that does work, such
as a task, call, wait or agent, goes in a heading body.
Several case keys can share one heading body. For example,
'approved' and
'approved-with-modifications' can both point to '#promote-package'.
Heading bodies
A heading body is a child heading of the section that holds the choice. The rules:- The choice is the last fence in its section.
- Each
'#block'target is a direct child heading of that section. Use a custom ID, such as### Use the snapshot {#use-snapshot}, so renaming the heading doesn’t change the target. - The headings the choice uses come first among the section’s child headings, one after another.
- After a body finishes, the run continues at the first child heading the choice doesn’t use. If there is none, it continues at the next heading after the section.
- A body can contain any steps, including a nested
choice,repeatorfor-each, and can end the run withcomplete.
Region outputs
outputs declares the values the choice hands to later steps. Every case that continues must bind
each declared output exactly once:
- an inline outputs case binds all of them by itself;
- a heading body binds each one with an ordinary step whose
outputhas that name, on every path that reaches the end of the body.
$portfolio_source, not through the
choice’s ID. Values a body binds that aren’t declared outputs stay inside the body and can’t be
read after the choice.
If cases produce different shapes, declare an output schema with nullable members, and collapse
them with ?? in a later value node.
Example
A minimal approval route, with a body for one value and an inline end for the other:balance, which later steps read. A second choice uses continue for the past-due case.
The policy values and hosts are illustrative.
balance-check.procedure.md
On retry and resume
- Routing follows the data. The choice reads the recorded value of
onand selects the matching case. It never calls anything, so a resumed run selects the same case again. - No override. A run can’t take the
'true'case whileonisfalse. To route differently, the value itself has to change. - Outputs appear together. A body’s declared outputs become visible to later steps in one step when the body ends, never one at a time. When a nested choice or loop ends at the same time as its enclosing body, every level closes together.
- Ending inside a body. When a body reaches
complete, the run ends, and the choice and every enclosing construct are recorded as finished. If a step in a body fails, the run fails, and enclosing steps aren’t marked finished.
Common errors
See also
- repeat node and for-each node: other constructs with heading bodies
- parallel node
- complete node
- value node
- task node: the usual source of an approval decision