Main execution engine for compiled AgentOS graphs.

Instantiate once and reuse across multiple runs — the runtime itself is stateless between calls. Each invoke() / stream() / resume() call creates isolated local state tracked via closures.

Example

const runtime = new GraphRuntime({ checkpointStore, nodeExecutor });
const result = await runtime.invoke(compiledGraph, { query: 'hello' });

Constructors

Methods

  • Execute the graph to completion and return the final artifacts payload.

    This is a convenience wrapper around stream() that discards intermediate events and awaits the terminal run_end event.

    Parameters

    • graph: CompiledExecutionGraph

      Compiled execution graph to run.

    • input: unknown

      Initial user-provided input; frozen into GraphState.input.

    Returns Promise<unknown>

    The GraphState.artifacts value after the last node completes.

  • Execute the graph while yielding GraphEvent values at each significant step.

    Events are emitted in strict causal order: run_start → (node_startnode_endedge_transition?)+ → run_end

    Checkpoints are saved according to both the graph-wide checkpointPolicy and per-node checkpoint settings. An interrupt event causes immediate suspension followed by a terminal run_end.

    Parameters

    • graph: CompiledExecutionGraph

      Compiled execution graph to run.

    • input: unknown

      Initial user-provided input; frozen into GraphState.input.

    Returns AsyncGenerator<GraphEvent, any, any>

    Yields

    Runtime events in causal order.

  • Resume a previously interrupted run from its latest persisted checkpoint.

    The runtime restores GraphState from the checkpoint and re-executes any nodes that had not yet completed when the run was suspended. Nodes recorded as write, external, or human effect-class are replayed from their stored outputs to avoid duplicate side-effects; all other nodes are re-executed.

    Parameters

    • graph: CompiledExecutionGraph

      The same compiled graph that was originally invoked.

    • runOrCheckpointId: string

      Either the original run id or an exact checkpoint id.

    Returns Promise<unknown>

    The final GraphState.artifacts value after resumption completes.

    Throws

    When no checkpoint exists for the given identifier.

  • Resume a previously interrupted run and stream runtime events from the restore point.

    Accepts either the original run id or an exact checkpoint id. The resolved checkpoint is used to reconstruct GraphState, then execution continues through the same event stream contract as ().

    Parameters

    • graph: CompiledExecutionGraph

      Compiled execution graph to resume.

    • runOrCheckpointId: string

      Either the original run id or an exact checkpoint id.

    Returns AsyncGenerator<GraphEvent, any, any>

    Yields

    Runtime events in causal order from the checkpoint onward.

    Throws

    When no checkpoint exists for the given identifier.