Skip to main content
The Workflow class manages nodes and connections in a workflow.

Class: Workflow

Constructor

string
Optional unique identifier. Auto-generated if not provided.
string
Optional workflow name. Defaults to 'Untitled Workflow'.
Example:

Properties

string
Unique workflow identifier.
string
Workflow name for display.
Map<NodeId, Node>
Map of node IDs to node instances.
Graph
Internal graph structure managing connections.

Methods

addNode()

Add a node to the workflow.
typeof Node
Node class constructor (must be registered).
AddNodeOptions
Optional configuration:
  • id?: string - Custom node ID
  • position?: { x: number; y: number } - Visual position
  • data?: Record<string, any> - Initial property values
Returns: Created node instance. Example:

removeNode()

Remove a node from the workflow.
string
ID of the node to remove.
Example:

getNode()

Get a node by ID.
string
ID of the node to retrieve.
Returns: Node instance or undefined if not found. Example:

connect()

Create a connection between two nodes.
string
Source node ID.
string
Output port name on source node.
string
Target node ID.
string
Input port name on target node.
Returns: Created Connection object. Example:

disconnect()

Remove a connection.
string
ID of the connection to remove.
Example:

validate()

Validate the workflow structure.
Returns: ValidationResult with validation status and errors. Checks:
  • No cycles in the graph
  • All connections are valid
  • All required inputs are connected or have default values
  • All nodes are valid
Example:

execute()

Execute the workflow.
ExecutionOptions
Optional execution configuration:
  • timeout?: number - Maximum execution time (ms)
  • variables?: Record<string, any> - Workflow variables
  • abortSignal?: AbortSignal - Cancellation signal
Returns: Promise resolving to ExecutionResult. Example:

toJSON()

Serialize workflow to JSON.
Returns: JSON representation of the workflow. Example:

fromJSON()

Deserialize workflow from JSON.
WorkflowJSON
JSON representation of the workflow.
Returns: New Workflow instance. Example:

Types

AddNodeOptions

ExecutionOptions

ExecutionResult

WorkflowJSON

Usage Examples

Basic Workflow

Save and Load

Validation Before Execute

Workflows Guide

Learn workflow concepts

Node API

Node class reference

Executor API

Executor class reference

JSON Schema

Workflow JSON format