Graph is a finite state machine pipeline. You define nodes (processing steps) and transitions between them; the graph executes them in sequence, carrying a typed state object from node to node until a node produces a final output.
Use graphs for multi-step sequential workflows, resumable pipelines, and pipelines that benefit from step-by-step inspection or replay.
If you are looking at older Vibes docs that show
new Graph({ nodes: [...] }) or this.next() inside a node - those are incorrect. The correct API is shown on this page.Graph state machine
Defining nodes
Each node extendsBaseNode<State, Output>. The run() method returns either next(nodeId, newState) to transition to another node, or output(value) to end the graph. Import next and output as free functions from @vibesjs/sdk - they are NOT methods on BaseNode.
BaseNode fields
Building and running a graph
Pass nodes as a positional array to theGraph constructor. An optional second argument accepts { maxIterations? }.
Step-by-step iteration with runIter()
graph.runIter() returns a GraphRun object. Call run.next() repeatedly to advance one step at a time. Each step is either a "node" step (with nodeId and state) or an "output" step (with output).
GraphStep kinds
Visualizing with toMermaid()
graph.toMermaid() returns a flowchart TD Mermaid string. The edges are derived from the nextNodes declarations on each BaseNode.
mermaid code block.
Persistence
Pass aFileStatePersistence instance to graph.run() to checkpoint state after each node. If the run is interrupted, restarting with the same graphId resumes from the last saved state.
MemoryStatePersistence:
API reference
Agents
Use agents as nodes in your graph workflow
Graph Workflow Example
End-to-end graph pipeline example