# Class GraphBuilder

Fluent builder for graph-based workflows.

Usage:

    const graph = new GraphBuilder()
      .addState('messages', { defaultValue: [], reducer: { type: 'append' } })
      .addNode('classify', classifyHandler)
      .addNode('respond', respondHandler)
      .addEdge(START, 'classify')
      .addConditionalEdge('classify', router, ['respond', 'escalate'])
      .addEdge('respond', END)
      .compile();

- Defined in packages/nexus-agents/src/orchestration/graph/graph-builder.ts:48

##### Index

### Constructors

constructor

### Methods

addState
addNode
addEdge
addConditionalEdge
compile

## Constructors

### constructor

- new GraphBuilder(): GraphBuilder

  #### Returns GraphBuilder

## Methods

### addState

- addState<T>(name: string, schema: StateFieldSchema<T>): this

  Registers a state field with its default value and reducer.

  #### Type Parameters

  - T

  #### Parameters

  - name: string
  - schema: StateFieldSchema<T>

  #### Returns this

  - Defined in packages/nexus-agents/src/orchestration/graph/graph-builder.ts:56

### addNode

- addNode(
  id: string,
  handler: NodeHandler,
  opts?: {
  timeout?: number;
  retries?: number;
  preconditions?: readonly PreconditionConfig[];
  verify?: NodeHook;
  },
  ): this

  Adds a node to the graph. Supports optional precondition hooks (Issue #997) and verify hook (Issue #994).

  #### Parameters

  - id: string
  - handler: NodeHandler
  - `Optional` opts: {
    timeout?: number;
    retries?: number;
    preconditions?: readonly PreconditionConfig[];
    verify?: NodeHook;
    }

  #### Returns this

  - Defined in packages/nexus-agents/src/orchestration/graph/graph-builder.ts:65

### addEdge

- addEdge(from: string, to: string, options?: { maxTraversals?: number }): this

  Adds a fixed edge between two nodes.

  #### Parameters

  - from: string
  - to: string
  - `Optional` options: { maxTraversals?: number }

  #### Returns this

  - Defined in packages/nexus-agents/src/orchestration/graph/graph-builder.ts:90

### addConditionalEdge

- addConditionalEdge(
  from: string,
  router: (state: Readonly<GraphState>) => string,
  targets: readonly string[],
  ): this

  Adds a conditional edge with a routing function. The router inspects state and returns the target node ID. All possible targets must be declared for compile-time validation.

  #### Parameters

  - from: string
  - router: (state: Readonly<GraphState>) => string
  - targets: readonly string[]

  #### Returns this

  - Defined in packages/nexus-agents/src/orchestration/graph/graph-builder.ts:105

### compile

- compile(): CompileResult

  Compiles the graph, validating all structural invariants. Returns a CompileResult — either a validated CompiledGraph or a compile error.

  #### Returns CompileResult

  - Defined in packages/nexus-agents/src/orchestration/graph/graph-builder.ts:122