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_revisitis 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.
Example
Section titled “Example”const graph = new Graph({ nodes: [researcher, writer], edges: [['researcher', 'writer']],})
const result = await graph.invoke('Explain quantum computing')Implements
Section titled “Implements”MultiAgentBase
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Graph(options): Graph;Defined in: src/multiagent/graph.ts:99
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options | GraphOptions |
Returns
Section titled “Returns”Graph
Properties
Section titled “Properties”readonly id: string;Defined in: src/multiagent/graph.ts:90
Unique identifier for this orchestrator.
Implementation of
Section titled “Implementation of”MultiAgentBase.idreadonly nodes: ReadonlyMap<string, Node>;Defined in: src/multiagent/graph.ts:91
readonly edges: readonly Edge[];Defined in: src/multiagent/graph.ts:92
config
Section titled “config”readonly config: Required<GraphConfig>;Defined in: src/multiagent/graph.ts:93
Methods
Section titled “Methods”initialize()
Section titled “initialize()”initialize(): Promise<void>;Defined in: src/multiagent/graph.ts:124
Initialize the graph. Invokes the MultiAgentInitializedEvent callback. Called automatically on first invocation.
Returns
Section titled “Returns”Promise<void>
invoke()
Section titled “invoke()”invoke(input): Promise<MultiAgentResult>;Defined in: src/multiagent/graph.ts:137
Invoke graph and return final result (consumes stream).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input | InvokeArgs | The input to pass to entry point nodes |
Returns
Section titled “Returns”Promise<MultiAgentResult>
Promise resolving to the final MultiAgentResult
Implementation of
Section titled “Implementation of”MultiAgentBase.invokeaddHook()
Section titled “addHook()”addHook<T>(eventType, callback): HookCleanup;Defined in: src/multiagent/graph.ts:153
Register a hook callback for a specific graph event type.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends HookableEvent |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
eventType | HookableEventConstructor<T> | The event class constructor to register the callback for |
callback | HookCallback<T> | The callback function to invoke when the event occurs |
Returns
Section titled “Returns”HookCleanup
Cleanup function that removes the callback when invoked
Implementation of
Section titled “Implementation of”MultiAgentBase.addHookstream()
Section titled “stream()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input | InvokeArgs | The input to pass to entry nodes |
Returns
Section titled “Returns”AsyncGenerator<MultiAgentStreamEvent, MultiAgentResult, undefined>
Async generator yielding streaming events and returning a MultiAgentResult
Implementation of
Section titled “Implementation of”MultiAgentBase.stream