> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inworld.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# GraphBuilder

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

## Examples

```typescript theme={"system"}
const graph = new Graph('my_graph')
.addComponent(llmComponent)
.addComponent(embedderComponent)
.addNode(intentNode)
.addNode(llmNode)
.addEdge(intentNode, llmNode)
.setStartNode(intentNode)
.setEndNode(llmNode)
.build();
```

## Constructors

* [constructor](#constructor)

## Methods

* [addSubgraph](#addsubgraph)
* [addIntentSubgraph](#addintentsubgraph)
* [addNode](#addnode)
* [addEdge](#addedge)
* [addComponent](#addcomponent)
* [setStartNode](#setstartnode)
* [setEndNode](#setendnode)
* [setStartNodes](#setstartnodes)
* [setEndNodes](#setendnodes)
* [addMCPSubgraph](#addmcpsubgraph)
* [build](#build)

***

## Constructors

### constructor

```typescript theme={"system"}
new GraphBuilder(opts: string | GraphBuilderProps): GraphBuilder
```

Creates a new graph builder. Accepts either an options object or a graph ID string.

#### Parameters

<ParamField body="opts" type="string | GraphBuilderProps" required>
  Graph builder options or graph ID string
</ParamField>

#### Returns

`GraphBuilder`

## Methods

### addSubgraph

```typescript theme={"system"}
addSubgraph(subgraph: SubgraphBuilder): this
```

Adds a subgraph to the graph configuration.

#### Parameters

<ParamField body="subgraph" type="SubgraphBuilder" required>
  Subgraph builder instance to be added
</ParamField>

#### Returns

`this`

### addIntentSubgraph

```typescript theme={"system"}
addIntentSubgraph(id: string, parameters: Config): this
```

Adds an intent subgraph to the graph.

#### Parameters

<ParamField body="id" type="string" required>
  Unique identifier for the subgraph
</ParamField>

<ParamField body="parameters" type="Config" required>
  Intent subgraph parameters
</ParamField>

#### Returns

`this`

### addNode

```typescript theme={"system"}
addNode(node: Node | AbstractNode): this
```

Adds a node to the graph. If an is provided without corresponding component, internal components are automatically added.

#### Parameters

<ParamField body="node" type="Node | AbstractNode" required>
  Node to add to the graph
</ParamField>

#### Returns

`this`

### addEdge

```typescript theme={"system"}
addEdge(fromNode: string | Node | AbstractNode, toNode: string | Node | AbstractNode, options?: object): this
```

Adds an edge connecting two nodes in the graph.

#### Parameters

<ParamField body="fromNode" type="string | Node | AbstractNode" required>
  Source node
</ParamField>

<ParamField body="toNode" type="string | Node | AbstractNode" required>
  Destination node
</ParamField>

<ParamField body="options" type="object">
  Optional edge configuration
</ParamField>

#### Returns

`this`

### addComponent

```typescript theme={"system"}
addComponent(component: Component | AbstractComponent): this
```

Adds a component to the graph configuration.

#### Parameters

<ParamField body="component" type="Component | AbstractComponent" required>
  Component to add to the graph
</ParamField>

#### Returns

`this`

### setStartNode

```typescript theme={"system"}
setStartNode(node: string | Node | AbstractNode): this
```

Sets the start node of the graph.

#### Parameters

<ParamField body="node" type="string | Node | AbstractNode" required>
  Start node
</ParamField>

#### Returns

`this`

### setEndNode

```typescript theme={"system"}
setEndNode(node: string | Node | AbstractNode): this
```

Sets the end node of the graph.

#### Parameters

<ParamField body="node" type="string | Node | AbstractNode" required>
  End node
</ParamField>

#### Returns

`this`

### setStartNodes

```typescript theme={"system"}
setStartNodes(nodes: (string | Node | AbstractNode)[]): this
```

Sets multiple start nodes for the graph.

#### Parameters

<ParamField body="nodes" type="(string | Node | AbstractNode)[]" required>
  Array of start nodes
</ParamField>

#### Returns

`this`

### setEndNodes

```typescript theme={"system"}
setEndNodes(nodes: (string | Node | AbstractNode)[]): this
```

Sets multiple end nodes for the graph.

#### Parameters

<ParamField body="nodes" type="(string | Node | AbstractNode)[]" required>
  Array of end nodes
</ParamField>

#### Returns

`this`

### addMCPSubgraph

```typescript theme={"system"}
addMCPSubgraph(id: string, parameters: Config): this
```

Adds an MCP subgraph to the graph.

#### Parameters

<ParamField body="id" type="string" required>
  Unique identifier for the subgraph
</ParamField>

<ParamField body="parameters" type="Config" required>
  MCP subgraph parameters
</ParamField>

#### Returns

`this`

### build

```typescript theme={"system"}
build(): Graph
```

Creates a graph executor instance for running the graph.

#### Returns

`Graph`
