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

RouterWorkflow runs a router agent, then dispatches to exactly one downstream agent.

Use in the following scenarios:

  • A model (or routing step) should choose the destination,
  • Only one branch should run per request

How it works:

  • routerAgent always runs first,
  • routerAgent reads the selected route key from routerOutputKey,
  • The agent corresponding to the selected route key is dispatched from agentsMap.

Constructors

Constructor

Constructor

Parameters

ParameterTypeDescriptionRequired
properties

Properties

agentsMap

Property
Type
Record<string, BaseAgentLike>

Mapping of route keys to destination agents.

routerAgent

Property
Type
BaseAgentLike

The agent that decides which route key to select.

routerOutputKey

Property
Type
keyof AgentGraphState

State key containing the selected route returned by the router agent.

Methods

MethodSignatureClass
protected
buildEdges(agents: BaseAgentLike<TState>[]): GraphEdge<AgentGraphState<TState>>[]
inherited protected
buildNodes(agents: BaseAgentLike<TState>[]): GraphNodes<AgentGraphState<TState>>
inherited
generate(): WorkflowGenerateResult<TState>
getAgents(): BaseAgentLike<TState>[]
protected
getEntryNode(): string
protected
isTerminalAgent(_agents: BaseAgentLike<TState>[], index: number): 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

inheritedprotected Method
Signature
buildNodes (agents: BaseAgentLike<TState>[]): GraphNodes<AgentGraphState<TState>>
Inherited from: BaseWorkflow

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 (): WorkflowGenerateResult<TState>
Inherited from: BaseWorkflow

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.

getAgents

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

A list of agents that are part of 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 (_agents: BaseAgentLike<TState>[], index: number): boolean

Returns whether the agent at this position should expose terminal runtime fields.

Parameters

ParameterTypeDescriptionRequired
_agents
index
Returns
boolean

validateAgents

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

Validates the workflow configuration and throws if invalid.

Parameters

ParameterTypeDescriptionRequired
agents
Returns
void

Type definitions

RouterWorkflowConstructProperties

Type definition
Type parameters
<TState extends AgentData>
Supertypes
Pick<RouterWorkflow‚ "agentsMap" | "routerAgent" | "routerOutputKey">