pub trait FlowNode: Send + Sync {
// Required method
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
state: &'life1 State,
) -> Pin<Box<dyn Future<Output = Result<NodeOutput, GraphError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn execute_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
state: &'life1 State,
_sink: &'life2 Sender<GraphEvent>,
span_id: SpanId,
) -> Pin<Box<dyn Future<Output = Result<StreamNodeResult, GraphError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn metadata_hint(&self) -> NodeMetadata { ... }
}Expand description
节点执行 trait — trait-based 设计。
Graph 只知道 dyn FlowNode,不知道 AgentNode、ToolNode 等具体类型。
AgentFlowNode 由 lellm-agent crate 提供。
节点不修改 State。 节点读取 &State,输出 NodeOutput { deltas, next }。
Executor 收集 Delta 后统一 apply 到 State。
Required Methods§
Sourcefn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
state: &'life1 State,
) -> Pin<Box<dyn Future<Output = Result<NodeOutput, GraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
state: &'life1 State,
) -> Pin<Box<dyn Future<Output = Result<NodeOutput, GraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
执行节点逻辑(阻塞模式)。
state— 只读访问当前 State- 返回
NodeOutput { deltas, next }— 修改意图 + 下一步路由
Provided Methods§
Sourcefn execute_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
state: &'life1 State,
_sink: &'life2 Sender<GraphEvent>,
span_id: SpanId,
) -> Pin<Box<dyn Future<Output = Result<StreamNodeResult, GraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn execute_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
state: &'life1 State,
_sink: &'life2 Sender<GraphEvent>,
span_id: SpanId,
) -> Pin<Box<dyn Future<Output = Result<StreamNodeResult, GraphError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
执行节点逻辑(流式模式),将内部事件转发到 channel。
state— 只读访问当前 Statesink— 事件输出 channelspan_id— 执行实例 ID(由 executor 生成)
默认实现直接调用 execute,返回 StreamNodeResult::Continue。
BarrierNode 覆写此方法以返回 StreamNodeResult::Pause。
Sourcefn metadata_hint(&self) -> NodeMetadata
fn metadata_hint(&self) -> NodeMetadata
节点元数据提示 — 静态声明节点的执行特征。
用于 Adaptive Checkpoint 的默认值。 NodeOutput.metadata 会覆盖此值。
四层优先级:
NodeOutput.metadata— 运行时实际值(最高优先级)metadata_hint()— 节点静态声明NodeKind推断 — Executor 根据类型推断NodeMetadata::default()— 兜底值
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".