Skip to content

Branching Pattern

Route workflow execution to different paths based on user choice, collected data, or computed conditions.

[get-choice] → [route] → choice=A → [path-a] → [merge]
→ choice=B → [path-b] → [merge]
{
"type": "agent-directive",
"id": "get-action",
"directive": "Ask user: create new or edit existing?",
"inputSchema": {
"type": "object",
"properties": {
"action": { "type": "string", "enum": ["create", "edit"] }
},
"required": ["action"]
},
"connections": { "success": "route-action" }
}
{
"type": "condition",
"id": "route-action",
"condition": {
"operator": "eq",
"left": { "contextPath": "action" },
"right": "create"
},
"connections": {
"true": "create-workflow",
"false": "edit-workflow"
}
}

For more than 2 options, chain conditions:

{
"id": "check-create",
"type": "condition",
"condition": {
"operator": "eq",
"left": { "contextPath": "action" },
"right": "create"
},
"connections": {
"true": "create-branch",
"false": "check-edit"
}
}
{
"id": "check-edit",
"type": "condition",
"condition": {
"operator": "eq",
"left": { "contextPath": "action" },
"right": "edit"
},
"connections": {
"true": "edit-branch",
"false": "delete-branch"
}
}
{
"type": "condition",
"id": "check-has-tests",
"condition": {
"operator": "eq",
"left": { "contextPath": "has_tests" },
"right": "yes"
},
"connections": {
"true": "run-tests",
"false": "skip-tests"
}
}
{
"type": "condition",
"id": "check-error-count",
"condition": {
"operator": "gt",
"left": { "contextPath": "error_count" },
"right": 0
},
"connections": {
"true": "fix-errors",
"false": "proceed"
}
}

Combine multiple checks:

{
"condition": {
"operator": "and",
"conditions": [
{
"operator": "eq",
"left": { "contextPath": "status" },
"right": "ready"
},
{
"operator": "gt",
"left": { "contextPath": "items_count" },
"right": 0
}
]
}
}

Branches typically converge at a common node:

[create-branch] → [save-workflow]
[edit-branch] → [save-workflow]

Both paths connect to the same target node.