pub trait NodeFn<S: State>: Send + Sync {
// Required methods
fn call(&self, state: &S, ctx: &NodeContext) -> NodeFuture<S::Update>;
fn name(&self) -> &str;
}Expand description
The core node trait — any async function that takes state and returns a result.
Generated by the #[node] macro. Users never implement this manually.
Generic over S: State — works with any user-defined state struct.
§Context parameter
Every call receives a NodeContext with execution metadata.
Simple nodes ignore it. Smart nodes use it to adapt behavior:
ⓘ
fn call(&self, state: &MyState, ctx: &NodeContext) -> NodeFuture<MyUpdate> {
Box::pin(async move {
if ctx.is_last_step() {
// No time for tool calls — give best answer now
return NodeResult::Update(wrap_up(state));
}
// Normal execution...
})
}Required Methods§
Sourcefn call(&self, state: &S, ctx: &NodeContext) -> NodeFuture<S::Update>
fn call(&self, state: &S, ctx: &NodeContext) -> NodeFuture<S::Update>
Execute the node with a state snapshot and execution context.
ctx provides engine-computed metadata (step, remaining steps,
activation reason). Read-only — the engine owns this data.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".