ESM
import { SwitchWorkflow } from "@arcgis/ai-components/agent-utils/workflows/SwitchWorkflow.js";
Inheritance
SwitchWorkflow→BaseWorkflow<TState>
Since
ArcGIS Maps SDK for JavaScript 5.1

SwitchWorkflow routes execution to one of several branches based on a resolver function.

Use in the following scenarios:

  • Branch selection should be based on complex logic that doesn't fit a simple true/false condition.
  • You want explicit case handling with optional fallback.

How it works:

  • Run resolver(state, config) to get a case key,
  • Route to matching agentsMap entry,
  • If resolver returns undefined, execution ends without selecting a branch,
  • If unknown and defaultAgent exists, run default,
  • If unknown and no default, throw an error.

Constructors

Constructor

Constructor

Parameters

ParameterTypeDescriptionRequired
properties

Properties

agentsMap

Property
Type
Record<string, BaseAgentLike>

Mapping of keys to destination agents.

defaultAgent

Property
Type
BaseAgentLike | undefined

Optional fallback agent used when the resolver returns an unknown case.

resolver

Property
Type
SwitchDecider

Resolver used to select the case key for routing.

Methods

MethodSignatureClass
protected
buildEdges(agents: BaseAgentLike<TState>[]): GraphEdge<AgentGraphState<TState>>[]
protected
buildNodes(agents: BaseAgentLike<TState>[]): GraphNodes<AgentGraphState<TState>>
inherited
generate(parameter0?: WorkflowGenerateOptions<TState>): WorkflowGenerateResult<TState>
getAgents(): BaseAgentLike<TState>[]
protected
getEntryNode(): string
protected
isTerminalAgent(): boolean
protected
validateAgents(agents: BaseAgentLike<TState>[]): void

buildEdges

protected Method
Signature
buildEdges (agents: BaseAgentLike<TState>[]): GraphEdge<AgentGraphState<TState>>[]

Builds the workflow-specific edges.

Parameters

ParameterTypeDescriptionRequired
agents
Returns
GraphEdge<AgentGraphState>[]

buildNodes

protected Method
Signature
buildNodes (agents: BaseAgentLike<TState>[]): GraphNodes<AgentGraphState<TState>>

Builds the workflow's graph nodes.

Node ids use the agent id plus its position (agent.id_index) instead of only the raw agent id. That prevents collisions when the same agent instance is used multiple times.

Parameters

ParameterTypeDescriptionRequired
agents
Returns
GraphNodes<AgentGraphState>

generate

inherited Method
Signature
generate (parameter0?: WorkflowGenerateOptions<TState>): WorkflowGenerateResult<TState>
Inherited from: BaseWorkflow

Generates the workflow's graph and shared workspace based on its agents and optional boundary schemas.

Parameters

ParameterTypeDescriptionRequired
parameter0
Returns
WorkflowGenerateResult

getAgents

Method
Signature
getAgents (): BaseAgentLike<TState>[]

Returns the agents coordinated by this workflow.

Returns
BaseAgentLike[]

getEntryNode

protected Method
Signature
getEntryNode (): string

Returns the id of the first node in the workflow graph.

Returns
string

isTerminalAgent

protected Method
Signature
isTerminalAgent (): boolean

Indicates whether the agent at index is terminal and should expose terminal runtime fields in workflow state.

Returns
boolean

validateAgents

protected Method
Signature
validateAgents (agents: BaseAgentLike<TState>[]): void

Throws if the workflow contains no agents. Concrete workflow classes may add validation for their requirements.

Parameters

ParameterTypeDescriptionRequired
agents
Returns
void

Type definitions

SwitchDecider

Type definition
Type parameters
<TState extends AgentData = AgentData>

Resolver function that chooses a switch case key from current graph state.

Parameters

ParameterTypeDescriptionRequired
state

Current workflow graph state.

config

Optional execution configuration.

Returns
Promise<string | undefined> | string | undefined

SwitchWorkflowConstructProperties

Type definition
Type parameters
<TState extends AgentData>
Supertypes
Partial<Pick<SwitchWorkflow, "defaultAgent">> ‚  Pick<SwitchWorkflow‚ "agentsMap" | "resolver">