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

Abstract base class for workflow patterns that coordinate agent execution. It provides shared state and graph-generation behavior. Choose one of the supported workflow classes below to coordinate agents sequentially, conditionally, in parallel, through repetition, or by routing.

The following workflow classes 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(parameter0?: WorkflowGenerateOptions<TState>): 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 (parameter0?: WorkflowGenerateOptions<TState>): WorkflowGenerateResult<TState>

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 (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

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

Parameters

ParameterTypeDescriptionRequired
agents
index
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

WorkflowGenerateOptions

Type definition
Type parameters
<TState extends AgentData = AgentData>

Options for generating a workflow's shared workspace and graph.

additionalSchemas

Property
Type
readonly (ZodObjectSchema<object> | undefined)[] | undefined

Additional schemas whose field names are initialized to undefined in the shared workflow workspace. Schema values are not parsed or validated.

agent

Property
Type
AgentMiddlewareAgent | undefined

Agent metadata included in lifecycle middleware requests. Required when middlewares is nonempty.

middlewares

Property
Type
AgentLifecycleMiddleware[] | undefined

Lifecycle middleware applied before and after workflow graph execution.

WorkflowGenerateResult

Type definition
Type parameters
<TState extends AgentData = AgentData>

Result returned by BaseWorkflow.generate(), containing the workflow's shared state annotation and a factory for creating its typed graph.

workspace

Property
Type
AgentStateAnnotation

Shared state annotation for the workflow graph. Fields declared by the agents' input and output schemas and any additional schemas are initialized to undefined; runtime-managed fields are also included.

createGraph

Property
Type
AgentCreateGraph

Factory that creates the typed state graph for this workflow. The returned graph is not compiled.