Skip to content

Graph

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

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. MultiAgent-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')
  • MultiAgent
new Graph(options): Graph;

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

ParameterType
optionsGraphOptions

Graph

readonly id: string;

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

Unique identifier for this orchestrator.

MultiAgent.id

readonly nodes: ReadonlyMap<string, Node>;

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


readonly edges: readonly Edge[];

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


readonly config: Required<GraphConfig>;

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

initialize(): Promise<void>;

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

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

Promise<void>


invoke(input): Promise<MultiAgentResult>;

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

Invoke graph and return final result (consumes stream).

ParameterTypeDescription
inputMultiAgentInputThe input to pass to entry point nodes

Promise<MultiAgentResult>

Promise resolving to the final MultiAgentResult

MultiAgent.invoke

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

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

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

MultiAgent.addHook

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

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

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

ParameterTypeDescription
inputMultiAgentInputThe input to pass to entry nodes

AsyncGenerator<MultiAgentStreamEvent, MultiAgentResult, undefined>

Async generator yielding streaming events and returning a MultiAgentResult

MultiAgent.stream