Skip to main content

Executor

Struct Executor 

Source
pub struct Executor { /* private fields */ }
Expand description

The graph executor. Holds an optional checkpointer and an optional middleware chain; stateless with respect to individual runs, so one Executor can drive many concurrent runs (each with its own thread_id).

Implementations§

Source§

impl Executor

Source

pub fn new() -> Self

An executor without persistence (runs cannot be interrupted/resumed durably; interrupts will still surface but resume requires a checkpointer).

Source

pub fn with_checkpointer(checkpointer: Arc<dyn Checkpointer>) -> Self

An executor persisting checkpoints through checkpointer.

Source

pub fn layer<M: Middleware + 'static>(self, middleware: M) -> Self

Builder-style: attach a middleware layer (Middleware/Interceptor SDK). Layers compose in registration order — before-hooks run in .layer() order on the way into a node/model/tool call, after-hooks in reverse order on the way out. See crate::middleware.

Source

pub fn layer_shared(self, middleware: Arc<dyn Middleware>) -> Self

Builder-style: attach a pre-shared middleware layer.

Source

pub fn middleware(&self) -> &MiddlewareChain

The attached middleware chain (empty when no layers were added).

Source

pub fn with_effect_admission(self, compensations: CompensationRegistry) -> Self

Builder-style: make guarded tool effect admission available to nodes.

The supplied registry may be empty. Pure and read-only calls remain automatic; idempotent calls require a key, compensatable calls require a handler in this registry, and non-idempotent calls require a matching token in RunConfig::effect_approvals. The prebuilt ReAct tools node enforces this automatically. Custom nodes must pass NodeContext::effect_admission to the crate::tool::ToolExecutor they construct; direct crate::tool::Tool::call invocations are not intercepted by the executor.

Source

pub fn effect_admission_enabled(&self) -> bool

Whether this executor enforces the effect admission boundary.

Source

pub fn with_token_tx(self, token_tx: Sender<GraphEvent>) -> Self

Builder-style: hold a token broadcast sender that nodes can clone to publish GraphEvent::Token deltas (LangGraph’s messages stream mode).

The executor never emits Token events itself — tokens originate in nodes calling crate::llm::ChatModel::chat_stream. This is a convenience handle so node factories built around an Executor can fetch the sink via Executor::token_tx and capture a clone in each node closure. When the same channel should also receive the executor’s own events, attach it to the run via RunConfig::with_event_tx instead (or as well).

Source

pub fn token_tx(&self) -> Option<&Sender<GraphEvent>>

The token broadcast sender, if one was attached via Executor::with_token_tx. Clone it into node closures to stream GraphEvent::Tokens from within nodes.

Source

pub fn with_memory_source(self, source: MemorySource) -> Self

Builder-style: install the governed-memory source this executor’s runs answer memory reads from (R0.8 wave 1; see crate::memory::MemorySource).

The executor never reads or writes memory itself this wave — the full run-loop integration is a later wave. This is the seam’s installation point, mirroring Executor::with_token_tx: node factories built around an Executor fetch the journaled handle via Executor::memory once the run has started and capture a clone in each node closure. Nodes may equally bind a source to an attached journal directly (crate::journal::Journal::memory); both paths journal into the same run evidence.

Source

pub fn memory_source(&self) -> Option<&MemorySource>

The configured memory source, if one was installed via Executor::with_memory_source.

Source

pub fn memory(&self) -> Option<JournaledMemory>

The journaled memory handle for the most recent run: the run’s journal (set at run start) bound to the configured source. None before the first run or when no source is installed. The same most-recent-run caveat as Executor::journal applies: driving several runs concurrently through one Executor leaves this handle pointing at whichever run started last — bind per-run handles via crate::journal::Journal::memory when runs overlap.

Source

pub fn checkpointer(&self) -> Option<&Arc<dyn Checkpointer>>

The configured checkpointer, if any. Shared (not consumed) so one Executor can drive many concurrent runs over the same store.

Source

pub fn journal(&self) -> Option<Journal>

The Flight Recorder journal of the most recent run started through this executor — the one attached via RunConfig::with_journal, or the fresh journal the executor created for the run. None before the first run.

The journal is set at run start, so the evidence of a failed or suspended run is retrievable exactly like a completed run’s. Note the executor is deliberately stateless across runs: driving several runs concurrently through one Executor leaves this handle pointing at whichever run started last — attach per-run journals via the config when runs overlap.

Source

pub async fn run( &self, graph: &Graph, spec: &StateSpec, initial_state: State, config: RunConfig, ) -> Result<ExecutionOutcome>

Run a compiled graph to completion (or interruption).

  • graph: the compiled, frozen graph topology.
  • spec: the state schema (channels + reducers) used to merge node updates at each barrier.
  • initial_state: the starting state. When config.resume is set and a checkpoint exists for config.thread_id, the checkpointed state and next-node set take precedence over this argument. When config.checkpoint_id is set, that specific checkpoint (rather than the latest) is restored — replay/time travel; forking into a fresh thread first via crate::checkpoint::Checkpointer::fork_thread is the safe pattern, since replaying on the same thread appends new history.
  • config: run configuration (thread id, step limit, resume value, streaming sink).
§Super-step semantics

Each loop iteration runs one super-step as a transaction: the active nodes execute in parallel over an immutable start-of-step snapshot; the barrier discards the whole step’s writes on any node failure and suspends the run on an interrupt; only then are writes merged via the channel reducers, routing computed against the post-barrier state, and a boundary checkpoint persisted. The module-level docs enumerate the six phases; execute_super_step is the implementation.

The loop returns ExecutionOutcome::Done when routing yields an empty next set, ExecutionOutcome::Interrupted when a node interrupts, an RustyError::Graph error once config.max_steps super-steps have run without termination, and RustyError::Cancelled when RunConfig::cancellation is observed cancelled at a super-step boundary (the boundary checkpoint is intact; the run resumes from it).

Trait Implementations§

Source§

impl Default for Executor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more