Skip to content

graph()

import { graph, END } from '@polymatx/weave';
graph<State extends object>(): GraphBuilder<State>
MethodDescription
.node(name, fn)Register a node. First call becomes the entry by default.
.edge(from, to)Register an edge. to may be a string, END, or a fn.
.entry(name)Override the entry node.
.maxSteps(n)Override the per-run step cap (default 50).
.checkpoint(store)Attach a checkpoint store for durable runs.
.compile()Returns a CompiledGraph<State>.
compiled.run({
initialState,
signal?: AbortSignal,
runId?: string,
budgetUsd?: number,
onEvent?: (event: TraceEvent) => void,
resumeFromCheckpoint?: boolean,
});

Returns { runId, state, steps, durationMs, events }.

  • NodeNotFoundError — an edge points to a node that wasn’t registered.
  • GraphCompileError — invalid configuration at compile() time.
  • BudgetExceededError — cumulative cost exceeded budgetUsd.
  • WeaveErrormaxSteps exhausted, run aborted, or otherwise.