Skip to main content
Main graph builder class for creating complete graph configurations. Provides a fluent API for building graphs with nodes, edges, components, and subgraphs.

Example

const graph = new Graph('my_graph')
  .addComponent(llmComponent)
  .addComponent(embedderComponent)
  .addNode(intentNode)
  .addNode(llmNode)
  .addEdge(intentNode, llmNode)
  .setStartNode(intentNode)
  .setEndNode(llmNode)
  .build();

Hierarchy

Constructors

Methods

Constructors

constructor

new GraphBuilder(opts: string | GraphBuilderProps): GraphBuilder
Creates a new graph builder. Accepts either an options object or a graph ID string.

Parameters

opts
string | GraphBuilderProps
required
Graph ID string or GraphBuilderProps

Returns

GraphBuilder

Methods

addComponent

addComponent(component: Component | AbstractComponent): this
Adds a component to the graph configuration.

Parameters

component
Component | AbstractComponent
required
Component to add to the graph

Returns

this The graph instance for method chaining

addEdge

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

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

addIntentSubgraph

addIntentSubgraph(id: string, parameters: IntentSubgraphProps): GraphBuilder
Adds an intent subgraph to the graph.

Parameters

id
string
required
Unique identifier for the subgraph
parameters
IntentSubgraphProps
required
Intent subgraph parameters

Returns

GraphBuilder The graph instance for method chaining

addNode

addNode(node: Node | AbstractNode): this
Adds a node to the graph. If an AbstractNode is provided without corresponding component, internal components are automatically added.

Parameters

node
Node | AbstractNode
required
Node to add to the graph

Returns

this The graph instance for method chaining

addSubgraph

addSubgraph(subgraph: SubgraphBuilder): this
Adds a subgraph to the graph configuration.

Parameters

subgraph
SubgraphBuilder
required
Subgraph builder instance to be added

Returns

this The graph instance for method chaining

build

build(): Graph
Creates a graph executor instance for running the graph.

Returns

Graph GraphExecutor instance configured with this graph

setEndNode

setEndNode(node: string | Node | AbstractNode): this
Sets the end node of the graph.

Parameters

node
string | Node | AbstractNode
required
End node

Returns

this The graph instance for method chaining

setEndNodes

setEndNodes(nodes: (string | Node | AbstractNode)[]): this
Sets multiple end nodes for the graph.

Parameters

nodes
(string | Node | AbstractNode)[]
required
Array of end nodes

Returns

this The graph instance for method chaining

setStartNode

setStartNode(node: string | Node | AbstractNode): this
Sets the start node of the graph.

Parameters

node
string | Node | AbstractNode
required
Start node

Returns

this The graph instance for method chaining

setStartNodes

setStartNodes(nodes: (string | Node | AbstractNode)[]): this
Sets multiple start nodes for the graph.

Parameters

nodes
(string | Node | AbstractNode)[]
required
Array of start nodes

Returns

this The graph instance for method chaining