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::Valuepair
§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: u32Current superstep number (1-indexed, increments each BSP cycle).
recursion_limit: u32Maximum supersteps before PeError::GraphRecursion.
node_name: StringName of the node being executed.
activation: ActivationReasonWhy 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: PhaseStateStorePhase 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
impl NodeContext
Sourcepub fn remaining_steps(&self) -> u32
pub fn remaining_steps(&self) -> u32
How many supersteps remain before the recursion limit.
Sourcepub fn is_last_step(&self) -> bool
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
impl Clone for NodeContext
Source§fn clone(&self) -> NodeContext
fn clone(&self) -> NodeContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more