Skip to content

How to do branching

Branch when the next step depends on something the run has just learned. Decide first what produces that value, because the answer changes the cost and the reliability of the branch.

Use a built-in probe when Orbital already observes the fact. The ticket workflow routes on pull request state without spending a turn asking an agent whether a merge happened. For another exact observation, use a script command with declared bool, number or text facts, and see how to add a local step. For judgement, declare an agent choice, which is what this example does.

An authenticated harness and a local Git project folder.

classify selects greet or explain; both reach done.

classify selects greet or explain; both reach done.

classify declares outputs="route:choice". Orbital infers the allowed values, greet and explain, from the conditions on the node’s outgoing edges, and rejects any other answer before it reaches context. The two edges carry distinct weights, so the higher one is tried first. Because the conditions cover every inferred value, this node needs no fallback.

Add a fallback when your conditions do not cover every case, and give each conditioned edge its own weight. Two edges cannot share one.

Download all files. Create a local Git practice repository. It needs no remote:

Terminal window
mkdir -p ~/orbital-conditional/.orbital
git init ~/orbital-conditional
cd ~/orbital-conditional

Extract the archive into ~/orbital-conditional/.orbital/. Keep every relative path. From ~/orbital-conditional run:

Terminal window
orbital validate .orbital/workflow.dot

Add the project folder in Orbital. On New run select the project and workflow graph, choose your authenticated harness and supply the goal. Use a separate practice project for each example so the workflow name is unambiguous.

Use a greeting goal to select greet, or another goal to select explain. Exactly one response node runs before done.

Every DOT file below is a complete runnable graph. The archive contains the same files. Prompt files are companions, not separate workflows.

workflow.dot
digraph conditional {
graph [version="1", entry="classify"]
classify [prompt="If the goal asks for a greeting, choose greet. Otherwise choose explain.", outputs="route:choice"]
greet [prompt="Write a friendly greeting. Do not use tools."]
explain [prompt="Explain the goal in one sentence. Do not use tools."]
done [shape="Msquare"]
classify -> greet [condition="route == 'greet'", weight="2"]
classify -> explain [condition="route == 'explain'", weight="1"]
greet -> done
explain -> done
}

Download workflow.dot

Check error handling before reading a value produced on only one branch. Continue with how to do looping.