pub struct Graph<S: WorkflowState = State, M: MergeStrategy<S> = StateMerge> { /* private fields */ }Expand description
图(Graph)— 允许有环,循环保护由 GraphExecutor::max_steps 运行时熔断提供。
Implementations§
Source§impl<S: WorkflowState, M: MergeStrategy<S>> Graph<S, M>
impl<S: WorkflowState, M: MergeStrategy<S>> Graph<S, M>
pub fn name(&self) -> &str
pub fn node_names(&self) -> Vec<&str>
pub fn start_node(&self) -> &str
pub fn end_node(&self) -> &str
Sourcepub fn canonical_hash(&self) -> u64
pub fn canonical_hash(&self) -> u64
获取 canonical AST hash — 从 DSL 层计算,不依赖 HashMap 顺序。
用于 Checkpoint 的 graph compatibility 校验。 相同输入永远产生相同 hash,Checkpoint 不会因此失效。
Sourcepub fn hash_u64(&self) -> u64
pub fn hash_u64(&self) -> u64
计算图结构指纹 hash(u64 原始值)— 基于 compiled graph 结构。
注意:此 hash 依赖 HashMap 迭代顺序,可能不稳定。
优先使用 canonical_hash() 进行 Checkpoint 校验。
pub fn edges_from(&self, from: &str) -> Vec<&Edge<S>>
pub fn find_edge(&self, from: &str, to: &str) -> Option<&Edge<S>>
pub fn find_fallback_edge(&self, from: &str) -> Option<String>
Sourcepub fn validate(&self) -> Result<(), TerminalError>
pub fn validate(&self) -> Result<(), TerminalError>
验证图结构。
Sourcepub fn analyze(&self) -> GraphDiagnostics
pub fn analyze(&self) -> GraphDiagnostics
完整图诊断分析。
Sourcepub fn analyze_cycles(&self) -> CycleAnalysis
pub fn analyze_cycles(&self) -> CycleAnalysis
@deprecated 使用 analyze() 替代。
Sourcepub async fn run_inline<'cb>(
&self,
exec_ctx: &mut ExecutionEngine<'_, S>,
max_steps: usize,
step_cb: &mut dyn StepCallback<'cb>,
) -> Result<(), GraphError>
pub async fn run_inline<'cb>( &self, exec_ctx: &mut ExecutionEngine<'_, S>, max_steps: usize, step_cb: &mut dyn StepCallback<'cb>, ) -> Result<(), GraphError>
内联执行 — 唯一的执行路径。
接收 ExecutionEngine(借用 State),内部循环构建 [NodeContext](能力视图)
供节点使用。
数据流:
ExecutionEngine
→ build_node_context() → NodeContext<'_, S>
→ node.execute(ctx) → 节点 record() Mutations
→ drop(ctx) → 释放借用
→ commit() → apply Mutations 到 State
→ emit_checkpoint() → 通知 CheckpointSink
→ step_cb.on_step() → 通知 wrapper(追踪/事件)
→ take_control() → 获取路由信号§StepCallback
每步回调在 commit + checkpoint 之后、take_control 之前调用。
用于 wrapper(如 run_execution_loop)追踪 execution_log 或发射 per-node 事件。
Trait Implementations§
Auto Trait Implementations§
impl<S = State, M = StateMerge> !RefUnwindSafe for Graph<S, M>
impl<S = State, M = StateMerge> !UnwindSafe for Graph<S, M>
impl<S, M> Freeze for Graph<S, M>
impl<S, M> Send for Graph<S, M>
impl<S, M> Sync for Graph<S, M>
impl<S, M> Unpin for Graph<S, M>
impl<S, M> UnsafeUnpin for Graph<S, M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more