Skip to main content

NodeContext

Struct NodeContext 

Source
pub struct NodeContext {
    pub step: u32,
    pub recursion_limit: u32,
    pub node_name: String,
    pub activation: ActivationReason,
    pub metadata: HashMap<String, Value>,
    pub phase_store: PhaseStateStore,
    pub stream_sender: Option<Arc<dyn Any + Send + Sync>>,
    pub tool_observer: Option<Arc<dyn ToolObserver>>,
    pub lobe_runtime_service_factory: Option<Arc<dyn LobeRuntimeServiceFactory>>,
}
Expand description

Execution context injected by the engine into every node call.

Read-only from the node’s perspective. The engine computes these values before each superstep. Nodes use this to make informed decisions about execution strategy (e.g., wrap up on last step).

§Extensibility

The metadata field is the extension point for the runtime layer:

  • pe-runtime (Plan 007): agent_id, thread_id, budget info
  • Custom layers: any String → serde_json::Value pair

§Layering

NodeContext is for engine + runtime metadata only. The optional matrix layer does NOT inject values here — it operates between nodes (guiding routing), not inside them. Nodes never see matrix state. This keeps nodes as pure computation units with or without the matrix.

Fields§

§step: u32

Current superstep number (1-indexed, increments each BSP cycle).

§recursion_limit: u32

Maximum supersteps before PeError::GraphRecursion.

§node_name: String

Name of the node being executed.

§activation: ActivationReason

Why this node was activated in this superstep.

§metadata: HashMap<String, Value>

Extensible metadata from higher layers (runtime, custom).

pe-runtime (Plan 007) populates this with:

  • "agent_id": which agent owns this execution
  • "thread_id": conversation thread identifier
  • "budget_remaining": token/cost budget info

Nodes read these opportunistically — if a key is missing, the runtime layer isn’t active. Graceful degradation.

§phase_store: PhaseStateStore

Phase state store for the interrupt/resume system.

Populated by the Pregel engine from checkpoint data on resume. Nodes using the node! DSL read their current phase from here. Empty on initial runs (no checkpoint). The engine preserves this across interrupt/resume boundaries via checkpoint serialization.

§stream_sender: Option<Arc<dyn Any + Send + Sync>>

Type-erased stream sender for the streaming layer (Plan 011).

When streaming is active, pe-runtime injects an Arc<mpsc::Sender<StreamEvent>> here. Nodes access it via pe-runtime’s StreamWriter helper — never directly.

None when streaming is not active (the common non-streaming path).

§tool_observer: Option<Arc<dyn ToolObserver>>

Optional tool observer for streaming tool call lifecycle events.

When streaming is active, pe-runtime injects a StreamingToolObserver that emits ToolCallStarted/ToolCallCompleted/ToolCallFailed. pe-tools extracts this and calls it around each tool execution.

None when streaming is not active.

§lobe_runtime_service_factory: Option<Arc<dyn LobeRuntimeServiceFactory>>

Optional factory for creating runtime-owned services for lobes.

When present, LobeNode can build source-attributed service handles for the concrete lobe being executed.

Implementations§

Source§

impl NodeContext

Source

pub fn remaining_steps(&self) -> u32

How many supersteps remain before the recursion limit.

Source

pub fn is_last_step(&self) -> bool

Whether this is the final superstep before recursion limit. Nodes should wrap up and produce a final answer.

Trait Implementations§

Source§

impl Clone for NodeContext

Source§

fn clone(&self) -> NodeContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.