▾
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
| Method | Signature | Class |
|---|---|---|
| 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
- 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 (parameter0?: WorkflowGenerateOptions<TState>): WorkflowGenerateResult<TState>
Generates the workflow's graph and shared workspace based on its agents and optional boundary schemas.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| parameter0 | | |
- Returns
- WorkflowGenerateResult
getAgents
- Signature
-
getAgents (): BaseAgentLike<TState>[]
Returns the agents coordinated by this workflow.
- Returns
- BaseAgentLike
[]
isTerminalAgent
- 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
| Parameter | Type | Description | Required |
|---|---|---|---|
| agents | | | |
| index | | |
- Returns
- boolean
validateAgents
- Signature
-
validateAgents (agents: BaseAgentLike<TState>[]): void
Throws if the workflow contains no agents. Concrete workflow classes may add validation for their requirements.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| agents | | |
- Returns
- void
Type definitions
WorkflowGenerateOptions
Options for generating a workflow's shared workspace and graph.
additionalSchemas
- 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
- Type
- AgentMiddlewareAgent | undefined
Agent metadata included in lifecycle middleware requests. Required when middlewares is nonempty.
middlewares
- Type
- AgentLifecycleMiddleware
[] | undefined
Lifecycle middleware applied before and after workflow graph execution.
WorkflowGenerateResult
Result returned by BaseWorkflow.generate(), containing the workflow's shared state annotation and a factory for
creating its typed graph.
workspace
- 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
- Type
- AgentCreateGraph
Factory that creates the typed state graph for this workflow. The returned graph is not compiled.