pub struct NodeContext { /* private fields */ }Expand description
The input to every node invocation.
The state snapshot is cloned per node invocation, so snapshot isolation is structural, not conventional: nodes running in the same super-step each hold their own owned snapshot and can never observe each other’s writes.
Implementations§
Source§impl NodeContext
impl NodeContext
Sourcepub fn new(state: State, config: NodeConfig) -> Self
pub fn new(state: State, config: NodeConfig) -> Self
Build a context from a state snapshot and config. Primarily used by
the executor; tests may construct it directly. Carries no middleware
chain — see NodeContext::with_middleware.
Sourcepub fn config(&self) -> &NodeConfig
pub fn config(&self) -> &NodeConfig
The run configuration for this invocation.
Sourcepub fn with_middleware(self, chain: MiddlewareChain) -> Self
pub fn with_middleware(self, chain: MiddlewareChain) -> Self
Builder-style: attach the run’s middleware chain. The executor sets this when layers are registered; empty otherwise.
Sourcepub fn middleware(&self) -> &MiddlewareChain
pub fn middleware(&self) -> &MiddlewareChain
The middleware chain attached to the run’s executor (Middleware /
Interceptor SDK). Node code uses it to propagate interception into
the boundaries it controls: hand it to
crate::tool::ToolExecutor::with_middleware or wrap models in
crate::middleware::MiddlewareChatModel. Empty when the executor
has no layers.
Sourcepub fn effect_admission(&self) -> Option<&EffectAdmissionContext>
pub fn effect_admission(&self) -> Option<&EffectAdmissionContext>
The run-scoped effect boundary attached by an executor that enabled
admission enforcement. Nodes dispatching tools should pass this to
crate::tool::ToolExecutor::with_effect_admission. The prebuilt
ReAct tools node does so automatically.
Sourcepub fn with_effect_admission(self, context: EffectAdmissionContext) -> Self
pub fn with_effect_admission(self, context: EffectAdmissionContext) -> Self
Builder-style: attach a run-scoped effect admission boundary.
Sourcepub fn resume_value(&self) -> Option<&Value>
pub fn resume_value(&self) -> Option<&Value>
The resume value, if this run is resuming from an interrupt.
Typical pattern inside a resumable node:
use rusty_agent_runtime::node::{NodeConfig, NodeContext};
use rusty_agent_runtime::state::State;
use serde_json::{json, Value};
let approved = match ctx.resume_value() {
Some(v) => v.clone(), // resumed: interrupt() "returns" v
None => return Err(ctx.interrupt(json!({"question": "approve?"}))),
};Sourcepub fn interrupt(&self, value: Value) -> RustyError
pub fn interrupt(&self, value: Value) -> RustyError
Build the interrupt error for a payload.
Returning Err(ctx.interrupt(payload)) from a node suspends the whole
run — not just this node. The super-step is transactional: no write of
the in-flight step survives, not even from sibling nodes that already
completed. The executor therefore persists a checkpoint that
re-schedules the entire active set of the suspended step — the
interrupting node plus all of its siblings — and surfaces payload in
crate::executor::ExecutionOutcome::Interrupted. On resume, every
node of that set re-executes from its start (node logic must be
idempotent), with NodeContext::resume_value set for the first
super-step.