Skip to main content

GraphBuilder

Defined in: types.ts:303

Mutable graph builder returned by createGraphBuilder.

Example​

const builder = createGraphBuilder({ agentId: 'main' });
const rootId = builder.startNode({ type: 'agent', name: 'main' });
const toolId = builder.startNode({ type: 'tool', name: 'search', parentId: rootId });
builder.endNode(toolId);
builder.endNode(rootId);
const graph = builder.build();

Properties​

graphId​

readonly graphId: string

Defined in: types.ts:305

The graph's ID, available before build().


traceContext​

readonly traceContext: { spanId: string; traceId: string; }

Defined in: types.ts:308

Trace context for propagating distributed trace information.

spanId​

spanId: string

traceId​

traceId: string

Methods​

addEdge()​

addEdge(from, to, type): void

Defined in: types.ts:320

Add an explicit edge between two nodes.

Parameters​

ParameterType
fromstring
tostring
typeEdgeType

Returns​

void


build()​

build(): ExecutionGraph

Defined in: types.ts:362

Freeze and return the completed execution graph. Throws if no root node exists.

Returns​

ExecutionGraph


endNode()​

endNode(nodeId, status?): void

Defined in: types.ts:314

End a node. Status defaults to 'completed'.

Parameters​

ParameterType
nodeIdstring
status?NodeStatus

Returns​

void


failNode()​

failNode(nodeId, error): void

Defined in: types.ts:317

Mark a node as failed with an error.

Parameters​

ParameterType
nodeIdstring
errorstring | Error

Returns​

void


getOrganizationalBriefing()​

getOrganizationalBriefing(): unknown

Defined in: types.ts:349

Get organizational briefing if available (may return null if briefing hasn't been generated yet).

Returns​

unknown


getOrganizationalContext()​

getOrganizationalContext(): { briefingAvailable: boolean; briefingSummary?: string; insightCount: number; operatorContext?: OperatorContext; teamContext?: string; warningCount: number; }

Defined in: types.ts:352

Get organizational context summary for execution environment.

Returns​

{ briefingAvailable: boolean; briefingSummary?: string; insightCount: number; operatorContext?: OperatorContext; teamContext?: string; warningCount: number; }

briefingAvailable​

briefingAvailable: boolean

briefingSummary?​

optional briefingSummary?: string

insightCount​

insightCount: number

operatorContext?​

optional operatorContext?: OperatorContext

teamContext?​

optional teamContext?: string

warningCount​

warningCount: number


getSnapshot()​

getSnapshot(): ExecutionGraph

Defined in: types.ts:346

Return a frozen snapshot of the current graph state without finalising. The builder remains usable after calling this.

Returns​

ExecutionGraph


pushEvent()​

pushEvent(event): void

Defined in: types.ts:330

Record a trace event. Timestamp is added automatically.

Parameters​

ParameterType
eventOmit<TraceEvent, "timestamp">

Returns​

void

Example​

builder.pushEvent({ eventType: 'custom', nodeId: rootId, data: { key: 'value' } });

startNode()​

startNode(opts): string

Defined in: types.ts:311

Start a new execution node. Returns the generated node ID.

Parameters​

ParameterType
optsStartNodeOptions

Returns​

string


updateState()​

updateState(nodeId, state): void

Defined in: types.ts:333

Shallow-merge state into a node's state object.

Parameters​

ParameterType
nodeIdstring
stateRecord<string, unknown>

Returns​

void


withParent()​

withParent<T>(parentId, fn): T

Defined in: types.ts:340

Execute fn with an implicit parent context. Any startNode calls inside fn that omit parentId will automatically use parentId as their parent.

Type Parameters​

Type Parameter
T

Parameters​

ParameterType
parentIdstring
fn() => T

Returns​

T