> ## 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.

# SubgraphBuilder

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

## Examples

```typescript theme={"system"}
const subgraph = new SubgraphBuilder('my_subgraph')
.addParameter({ name: 'user_input', type: 'string' })
.addNode(intentNode)
.addNode(llmNode)
.addEdge(intentNode, llmNode)
.setStartNode(intentNode)
.setEndNode(llmNode)
.build();
```

## Constructors

* [constructor](#constructor)

## Methods

* [addParameter](#addparameter)
* [addParameters](#addparameters)
* [addNode](#addnode)
* [addEdge](#addedge)
* [setStartNode](#setstartnode)
* [setEndNode](#setendnode)
* [build](#build)

***

## Constructors

### constructor

```typescript theme={"system"}
new SubgraphBuilder(id: string): SubgraphBuilder
```

Creates a new subgraph builder with the specified ID.

#### Parameters

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

#### Returns

`SubgraphBuilder`

## Methods

### addParameter

```typescript theme={"system"}
addParameter(config: object): this
```

Adds a parameter to the subgraph that can be passed from the parent graph.

#### Parameters

<ParamField body="config" type="object" required>
  Parameter configuration
</ParamField>

#### Returns

`this`

### addParameters

```typescript theme={"system"}
addParameters(parameters: object): this
```

Adds multiple parameters to the subgraph at once.

#### Parameters

<ParamField body="parameters" type="object" required>
  Array of parameter configurations
</ParamField>

#### Returns

`this`

### addNode

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

Adds a node to the subgraph.

#### Parameters

<ParamField body="node" type="Node | AbstractNode" required>
  Node to add to the subgraph
</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 subgraph.

#### Parameters

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

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

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

#### Returns

`this`

### setStartNode

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

Sets the start node of the subgraph (subgraphs can only have one start node).

#### Parameters

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

#### Returns

`this`

### setEndNode

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

Sets the end node of the subgraph (subgraphs can only have one end node).

#### Parameters

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

#### Returns

`this`

### build

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

Builds and returns the final subgraph configuration.

#### Returns

`Subgraph`
