Skip to content

Graph

Defined in: src/multiagent/graph.ts:89

Directed graph orchestration pattern.

Agents execute as nodes in a dependency graph, with edges defining execution order and optional conditions controlling routing. Source nodes (those with no incoming edges) run first, and downstream nodes execute once all their dependencies complete. Parallel execution is supported up to a configurable concurrency limit.

Key design choices vs the Python SDK:

  • Construction uses a declarative options object rather than a mutable GraphBuilder. Nodes and edges are passed directly to the constructor.
  • Dependency resolution uses AND semantics: a node runs only when all incoming edges are satisfied. Python uses OR semantics, firing a node when any single incoming edge from the completed batch is satisfied.
  • Nodes are launched individually as they become ready (up to maxConcurrency). Python executes in discrete batches, waiting for the entire batch to complete before scheduling the next set of nodes.
  • Agent nodes are stateless by default (snapshot/restore on each execution). Python accumulates agent state across executions unless reset_on_revisit is enabled.
  • Node failures produce a FAILED result, allowing parallel paths to continue. Orchestrator-level limits (maxSteps) throw exceptions. Python does the inverse: node failures throw exceptions (fail-fast), while limit violations return a FAILED result.
const graph = new Graph({
nodes: [researcher, writer],
edges: [['researcher', 'writer']],
})
const result = await graph.invoke('Explain quantum computing')
  • MultiAgentBase
new Graph(options): Graph;

Defined in: src/multiagent/graph.ts:99

ParameterType
optionsGraphOptions

Graph

readonly id: string;

Defined in: src/multiagent/graph.ts:90

Unique identifier for this orchestrator.

MultiAgentBase.id

readonly nodes: ReadonlyMap<string, Node>;

Defined in: src/multiagent/graph.ts:91


readonly edges: readonly Edge[];

Defined in: src/multiagent/graph.ts:92


readonly config: Required<GraphConfig>;

Defined in: src/multiagent/graph.ts:93

initialize(): Promise<void>;

Defined in: src/multiagent/graph.ts:124

Initialize the graph. Invokes the MultiAgentInitializedEvent callback. Called automatically on first invocation.

Promise<void>


invoke(input): Promise<MultiAgentResult>;

Defined in: src/multiagent/graph.ts:137

Invoke graph and return final result (consumes stream).

ParameterTypeDescription
inputInvokeArgsThe input to pass to entry point nodes

Promise<MultiAgentResult>

Promise resolving to the final MultiAgentResult

MultiAgentBase.invoke

addHook<T>(eventType, callback): HookCleanup;

Defined in: src/multiagent/graph.ts:153

Register a hook callback for a specific graph event type.

Type Parameter
T extends HookableEvent
ParameterTypeDescription
eventTypeHookableEventConstructor<T>The event class constructor to register the callback for
callbackHookCallback<T>The callback function to invoke when the event occurs

HookCleanup

Cleanup function that removes the callback when invoked

MultiAgentBase.addHook

stream(input): AsyncGenerator<MultiAgentStreamEvent, MultiAgentResult, undefined>;

Defined in: src/multiagent/graph.ts:164

Stream graph execution, yielding events as nodes execute. Invokes hook callbacks for each event before yielding.

ParameterTypeDescription
inputInvokeArgsThe input to pass to entry nodes

AsyncGenerator<MultiAgentStreamEvent, MultiAgentResult, undefined>

Async generator yielding streaming events and returning a MultiAgentResult

MultiAgentBase.stream