NylorunDocsBeta
Get startedBuildRunDeployReferenceMore

Switch

Select one workflow branch from a deterministic routing key.

Switch computes a key from its input and runs exactly one matching case. Add default when inputs may produce keys outside the declared cases.

import { Chain, Switch } from "@nylorun/agents/define";

export const support = Chain({
  id: "support",
  steps: [
    triager,
    Switch({
      id: "route",
      on: (ticket) => ticket.kind,
      cases: {
        bug: bugAgent,
        billing: billingAgent,
      },
      default: generalAgent,
    }),
  ],
});

on is durable workflow logic: keep it deterministic and derive the key only from its input. Case names become manifest paths, so use stable names and do not use the reserved key default.

Each case may be an agent, tool, workflow, or slot. A slot can reshape the selected branch's input:

cases: {
  bug: {
    run: bugAgent,
    input: ({ value }) => `Investigate: ${value.summary}`,
  },
}

The switch output is the selected branch's output. Studio shows the chosen case and leaves unselected branches inactive.

See the shipped switch example, then learn how to run fixed branches in Parallel.