Skip to content

switch

Multi-case branching. First rule whose when is true wins; emits verdict = case so downstream edges route by case:.

Sourceinternal/agents/workflow/nodes/switch.go
BranchingYes — emits verdict
When to useRouting with 2+ conditions where branch (single expr) is awkward. Each rule is independent; ordering matters (first match wins).

Schema

FieldTypeRequiredNotes
caseslist of {when, case}First rule whose when is true wins. UI uses a rows builder; JSON accepts the list directly.
default_casestringVerdict to emit when no rule matches. Leave blank to fail closed — the run errors.

Output

FieldTypeWhat
verdictstringWinning case label (or default_case fallback).

Example

json
{
  "id": "route",
  "type": "switch",
  "cases": [
    {"when": "{{index .Event.Payload \"status\"}} == \"approved\"", "case": "approve"},
    {"when": "{{index .Event.Payload \"status\"}} == \"rejected\"", "case": "reject"}
  ],
  "default_case": "review"
}

Matching semantics

Same as branch — binary ops or truthy string. Each rule is evaluated independently in order; the first true short-circuits.

Empty default_case with no match = error (fail closed) so the workflow halts instead of silently dropping the run.

Pair with

  • branch — single-expression sibling.
  • classify — produces an LLM verdict that switch can re-route.
Built with ❤️ by a developer, for developers.