ESM
import { BaseWorkflow } from "@arcgis/ai-components/agent-utils/workflows/BaseWorkflow.js";
Inheritance
BaseWorkflowAccessor.js
Subclasses
ConditionalWorkflow, LoopWorkflow, ParallelWorkflow, RouterWorkflow, SequentialWorkflow, SwitchWorkflow
Since
ArcGIS Maps SDK for JavaScript 5.1

BaseWorkflow is the foundational class for defining workflows. A workflow defines a sequence of agents that work together to accomplish a task. This class provides the structure and common building blocks for constructing a workflow, including generating the shared workspace and creating the graph that defines how agents are connected and executed.

Specific workflows extend this base class and implement the abstract methods to define their unique behavior and structure.

The following workflow types are supported:

  • SequentialWorkflow - executes agents in a sequence, where the output of one agent can be passed as input to the next.
  • ConditionalWorkflow - allows for branching logic based on conditions evaluated at runtime, enabling different paths of execution depending on user input or LLM output.
  • LoopWorkflow - supports repeating a set of agents until a certain condition is met, useful for iterative processes.
  • ParallelWorkflow - enables concurrent execution of multiple agents, allowing for tasks that can be performed simultaneously.
  • RouterWorkflow - dynamically routes execution to different agents based on the input or state, providing flexibility in handling various scenarios.
  • SwitchWorkflow - similar to RouterWorkflow but designed for cases where there are multiple distinct paths based on discrete values in the input or state.

Methods

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

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

Method
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.

getAgents

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

A list of agents that are part of this workflow.

Returns
BaseAgentLike[]

getEntryNode

protected Method
Signature
getEntryNode (agents: BaseAgentLike<TState>[]): string | undefined

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

Parameters

ParameterTypeDescriptionRequired
agents
Returns
string | undefined

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

WorkflowGenerateResult

Type definition
Type parameters
<TState extends AgentData = AgentData>

Return payload from BaseWorkflow.generate().

workspace

Property
Type
AgentStateAnnotation

Shared workflow state annotation.

createGraph

Property
Type
AgentCreateGraph

Factory that creates the workflow graph.