pub trait Node: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 NodeContext,
) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn description(&self) -> &str { ... }
fn capabilities(&self) -> AgentCapabilities { ... }
fn kind(&self) -> NodeKind { ... }
fn call_args(&self, _ctx: &NodeContext) -> Option<Value> { ... }
fn will_act(&self, _ctx: &NodeContext) -> Result<bool> { ... }
fn subgraph(&self) -> Option<&CompiledGraph> { ... }
fn run_call<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 NodeContext,
_args: Value,
) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn validate_against(&self, _parent: &StateSchema) -> Result<()> { ... }
fn validate(&self) -> Result<()> { ... }
fn execute_stream<'a>(
&'a self,
ctx: &'a NodeContext,
) -> Pin<Box<dyn Stream<Item = Result<StreamEvent>> + Send + 'a>> { ... }
}Expand description
A node in the graph
Required Methods§
Sourcefn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 NodeContext,
) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 NodeContext,
) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute the node and return state updates
Provided Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Human-readable purpose shown by generic workflow inspectors.
Sourcefn capabilities(&self) -> AgentCapabilities
fn capabilities(&self) -> AgentCapabilities
Runtime capabilities inherited by portable graph topology metadata.
Sourcefn kind(&self) -> NodeKind
fn kind(&self) -> NodeKind
What kind of step this node is, as a workflow observer labels it in
CompiledGraph::shape (spec 3.3 §12).
Defaults to NodeKind::Other.
§Example
use adk_graph::node::{FunctionNode, Node, NodeOutput};
use adk_graph::shape::NodeKind;
let node = FunctionNode::new("receipt", |_ctx| async { Ok(NodeOutput::new()) });
assert_eq!(node.kind(), NodeKind::Function);Sourcefn call_args(&self, _ctx: &NodeContext) -> Option<Value>
fn call_args(&self, _ctx: &NodeContext) -> Option<Value>
The call this node makes, as an approver sees it and as its record binds it, when the node is governed (spec 3.3 §12, §7.1).
The value is shown in full on the decision and its
json_digest is part of the call’s action-ledger key, so a
fork whose call is unchanged is answered from the record. None, the default,
binds the call to the whole state the node reads.
§Example
use adk_graph::node::{Node, NodeContext, NodeOutput};
use serde_json::{Value, json};
struct Charge;
#[async_trait::async_trait]
impl Node for Charge {
fn name(&self) -> &str {
"pay"
}
fn call_args(&self, ctx: &NodeContext) -> Option<Value> {
Some(json!({ "amountCents": ctx.get("amountCents").cloned()? }))
}
async fn execute(&self, _ctx: &NodeContext) -> adk_graph::Result<NodeOutput> {
Ok(NodeOutput::new())
}
}Sourcefn will_act(&self, _ctx: &NodeContext) -> Result<bool>
fn will_act(&self, _ctx: &NodeContext) -> Result<bool>
Whether this node acts in ctx, asked before a governed node’s call is authorized
(spec 3.3 §12, §7.4).
Ok(false) means the node does nothing here, such as an action node whose condition
is false: a governed node then completes with no writes, and no decision is created
for a call that would not run. An error means the node cannot act, such as an HTTP
node whose request cannot be built: a governed node then fails with that error
without asking anyone. The default is Ok(true).
§Errors
Returns why the node cannot act in ctx.
§Example
use adk_graph::node::{Node, NodeContext, NodeOutput};
struct Refund;
#[async_trait::async_trait]
impl Node for Refund {
fn name(&self) -> &str {
"refund"
}
fn will_act(&self, ctx: &NodeContext) -> adk_graph::Result<bool> {
Ok(ctx.get("refund_due").and_then(|due| due.as_bool()).unwrap_or(false))
}
async fn execute(&self, _ctx: &NodeContext) -> adk_graph::Result<NodeOutput> {
Ok(NodeOutput::new())
}
}Sourcefn subgraph(&self) -> Option<&CompiledGraph>
fn subgraph(&self) -> Option<&CompiledGraph>
The graph this node runs, when it is a subgraph, so a workflow observer finds the
governed nodes inside it (spec 3.3 §12). The default is None.
§Example
use adk_graph::node::{FunctionNode, Node, NodeOutput};
let node = FunctionNode::new("receipt", |_ctx| async { Ok(NodeOutput::new()) });
assert!(node.subgraph().is_none());Sourcefn run_call<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 NodeContext,
_args: Value,
) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn run_call<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 NodeContext,
_args: Value,
) -> Pin<Box<dyn Future<Output = Result<NodeOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Runs exactly args: an approver’s edit of Node::call_args (spec 3.3 §7.1, §7.5).
Called instead of Node::execute when an approver edited a governed node’s call.
It must send the call it is given and nothing else.
§Errors
The default returns GovernedError::EditUnsupported:
the node cannot run an edited call, so the edited call is refused and nothing runs.
§Example
use adk_graph::node::{Node, NodeContext, NodeOutput};
use serde_json::Value;
struct Charge;
#[async_trait::async_trait]
impl Node for Charge {
fn name(&self) -> &str {
"pay"
}
async fn execute(&self, _ctx: &NodeContext) -> adk_graph::Result<NodeOutput> {
Ok(NodeOutput::new())
}
async fn run_call(&self, _ctx: &NodeContext, args: Value) -> adk_graph::Result<NodeOutput> {
Ok(NodeOutput::new().with_update("charged", args["amountCents"].clone()))
}
}Sourcefn validate_against(&self, _parent: &StateSchema) -> Result<()>
fn validate_against(&self, _parent: &StateSchema) -> Result<()>
Rejects a node that cannot execute, before the graph runs.
Called for every node by StateGraph::compile, so a configuration whose
backend is unavailable fails while the graph is being built rather than
part-way through a run, when earlier nodes may already have had side effects.
§Errors
Returns an error describing what is unavailable. The default accepts the node. Checks this node against the schema of the graph that holds it.
Called by StateGraph::compile for
every node, so a node that has requirements on its parent states them
before anything runs. Defaults to accepting any parent.
SubgraphNode uses this to reject a
channel mapping that names a channel neither side declares.
fn validate(&self) -> Result<()>
Sourcefn execute_stream<'a>(
&'a self,
ctx: &'a NodeContext,
) -> Pin<Box<dyn Stream<Item = Result<StreamEvent>> + Send + 'a>>
fn execute_stream<'a>( &'a self, ctx: &'a NodeContext, ) -> Pin<Box<dyn Stream<Item = Result<StreamEvent>> + Send + 'a>>
Streams execution events for this node.
An implementation must report the node’s state updates by yielding a
StreamEvent::Updates event, because a streaming executor takes the
updates from this stream rather than executing the node a second time.
The default implementation wraps Node::execute and does so.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".