Skip to main content

FlowNode

Trait FlowNode 

Source
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,不知道 AgentNodeToolNode 等具体类型。 AgentFlowNodelellm-agent crate 提供。

节点不修改 State。 节点读取 &State,输出 NodeOutput { deltas, next }。 Executor 收集 Delta 后统一 apply 到 State。

Required Methods§

Source

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§

Source

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 — 只读访问当前 State
  • sink — 事件输出 channel
  • span_id — 执行实例 ID(由 executor 生成)

默认实现直接调用 execute,返回 StreamNodeResult::Continue。 BarrierNode 覆写此方法以返回 StreamNodeResult::Pause

Source

fn metadata_hint(&self) -> NodeMetadata

节点元数据提示 — 静态声明节点的执行特征。

用于 Adaptive Checkpoint 的默认值。 NodeOutput.metadata 会覆盖此值。

四层优先级:

  1. NodeOutput.metadata — 运行时实际值(最高优先级)
  2. metadata_hint() — 节点静态声明
  3. NodeKind 推断 — Executor 根据类型推断
  4. NodeMetadata::default() — 兜底值

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§