Skip to main content
Builder class for creating subgraphs with a fluent API. Subgraphs are reusable graph components that can be referenced by other graphs.

Example

const subgraph = new SubgraphBuilder('my_subgraph')
  .addNode(intentNode)
  .addNode(llmNode)
  .addEdge(intentNode, llmNode)
  .setStartNode(intentNode)
  .setEndNode(llmNode)
  .build();

Constructors

Methods

Constructors

constructor

new SubgraphBuilder(id: string): SubgraphBuilder
Creates a new subgraph builder with the specified ID.

Parameters

id
string
required
Unique identifier for the subgraph

Returns

SubgraphBuilder

Methods

addEdge

addEdge(
    fromNode: string | Node | AbstractNode,
    toNode: string | Node | AbstractNode,
    options?: {
        conditionExpression?: string;
        conditionRef?: CustomEdgeConditionReference;
        loop?: boolean;
        optional?: boolean;
    },
): this
Adds an edge connecting two nodes in the subgraph.

Parameters

fromNode
string | Node | AbstractNode
required
Source node
toNode
string | Node | AbstractNode
required
Destination node
options
object
Optional edge configuration

Returns

this The builder instance for method chaining

addNode

addNode(node: Node | AbstractNode): this
Adds a node to the subgraph.

Parameters

node
Node | AbstractNode
required
Node to add to the subgraph

Returns

this The builder instance for method chaining

addParameter

addParameter(
    config: {
        name: string;
        type: "string" | "number" | "boolean" | "integer";
    },
): this
Adds a parameter to the subgraph that can be passed from the parent graph.

Parameters

config
object
required
Parameter configuration

Returns

this The builder instance for method chaining

addParameters

addParameters(
    parameters: {
        name: string;
        type: "string" | "number" | "boolean" | "integer";
    }[],
): this
Adds multiple parameters to the subgraph at once.

Parameters

parameters
Array<{ name: string; type: 'string' | 'number' | 'boolean' | 'integer' }>
required
Array of parameter configurations

Returns

this The builder instance for method chaining

build

build(): Subgraph
Builds and returns the final subgraph configuration.

Returns

Subgraph The completed subgraph configuration

Throws

If the subgraph has no nodes

setEndNode

setEndNode(node: string | Node | AbstractNode): this
Sets the end node of the subgraph (subgraphs can only have one end node).

Parameters

node
string | Node | AbstractNode
required
End node

Returns

this The builder instance for method chaining

setStartNode

setStartNode(node: string | Node | AbstractNode): this
Sets the start node of the subgraph (subgraphs can only have one start node).

Parameters

node
string | Node | AbstractNode
required
Start node

Returns

this The builder instance for method chaining