import { BaseWorkflow } from "@arcgis/ai-components/agent-utils/workflows/BaseWorkflow.js";- Inheritance
- BaseWorkflow→
Accessor.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
| Method | Signature | Class |
|---|---|---|
| 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
- 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
[]
isTerminalAgent
- Signature
-
isTerminalAgent (agents: BaseAgentLike<TState>[], index: number): boolean
Returns whether the agent at this position should expose terminal runtime fields.
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| agents | | | |
| index | | |
- 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