import { SwitchWorkflow } from "@arcgis/ai-components/agent-utils/workflows/SwitchWorkflow.js";- Inheritance
- SwitchWorkflow→
BaseWorkflow<TState>→ Accessor.js
- 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
agentsMapentry, - If unknown and
defaultAgentexists, run default, - If unknown and no default, throw an error.
Constructors
Properties
| Property | Type | Class |
|---|---|---|
| | ||
| | ||
| |
defaultAgent
- Type
- BaseAgentLike
| undefined
Optional fallback agent used when the resolver returns an unknown case.
Methods
| Method | Signature | Class |
|---|---|---|
| protected | buildEdges(agents: BaseAgentLike<TState>[]): GraphEdge<AgentGraphState<TState>>[] | |
| protected | buildNodes(agents: BaseAgentLike<TState>[]): GraphNodes<AgentGraphState<TState>> | |
| inherited | generate(): WorkflowGenerateResult<TState> | |
| getAgents(): BaseAgentLike<TState>[] | | |
| protected | getEntryNode(): string | |
| protected | isTerminalAgent(): boolean | |
| protected | validateAgents(agents: BaseAgentLike<TState>[]): void | |
buildEdges
- Signature
-
buildEdges (agents: BaseAgentLike<TState>[]): GraphEdge<AgentGraphState<TState>>[]
Builds the workflow-specific edges.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| agents | | |
- Returns
- GraphEdge<AgentGraphState
>[]
buildNodes
- 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
| Parameter | Type | Description | Required |
|---|---|---|---|
| agents | | |
- Returns
- GraphNodes<AgentGraphState
>
generate
- Signature
-
generate (): WorkflowGenerateResult<TState>
Generates the workflow's graph and shared workspace based on the defined agents and their schemas. This method is called by the WorkflowAgent when it generates its graph, and it orchestrates the creation of the workflow's structure, including validating the agents, deriving shared state from their schemas, and building the nodes and edges of the graph.
- Returns
- WorkflowGenerateResult
getAgents
- Signature
-
getAgents (): BaseAgentLike<TState>[]
A list of agents that are part of this workflow.
- Returns
- BaseAgentLike
[]
getEntryNode
- Signature
-
getEntryNode (): string
Returns the id of the first node in the workflow graph.
- Returns
- string
isTerminalAgent
- Signature
-
isTerminalAgent (): boolean
Returns whether the agent at this position should expose terminal runtime fields.
- Returns
- boolean
validateAgents
- Signature
-
validateAgents (agents: BaseAgentLike<TState>[]): void
Validates the workflow configuration and throws if invalid.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| agents | | |
- Returns
- void
Type definitions
SwitchDecider
Resolver function that chooses a switch case key from current graph state.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| state | Current workflow graph state. | | |
| config | Optional execution configuration. | |
SwitchWorkflowConstructProperties
- Type parameters
- <TState extends AgentData>
- Supertypes
- Partial<Pick<SwitchWorkflow
, "defaultAgent">> ‚ Pick<SwitchWorkflow ‚ "agentsMap" | "resolver">