pub struct GraphBuilder { /* private fields */ }Expand description
Graph 构建器。
Implementations§
Source§impl GraphBuilder
impl GraphBuilder
pub fn new(name: impl Into<String>) -> Self
pub fn start(&mut self, node: impl Into<String>) -> &mut Self
pub fn end(&mut self, node: impl Into<String>) -> &mut Self
pub fn node(&mut self, name: impl Into<String>, kind: NodeKind) -> &mut Self
Sourcepub fn edge(
&mut self,
from: impl Into<String>,
to: impl Into<String>,
) -> PendingEdge<'_>
pub fn edge( &mut self, from: impl Into<String>, to: impl Into<String>, ) -> PendingEdge<'_>
添加边(无条件普通边)。
返回 PendingEdge,可通过 .max_visits(n) 附加循环分析约束。
ⓘ
g.edge("a", "b"); // 普通边
g.edge("b", "a").max_visits(5); // 普通边 + 循环分析Sourcepub fn edge_if(
&mut self,
from: impl Into<String>,
to: impl Into<String>,
condition: impl Fn(&State) -> bool + Send + Sync + 'static,
) -> PendingEdge<'_>
pub fn edge_if( &mut self, from: impl Into<String>, to: impl Into<String>, condition: impl Fn(&State) -> bool + Send + Sync + 'static, ) -> PendingEdge<'_>
添加条件边(if/else-if 规则链)。
返回 PendingEdge,可通过 .max_visits(n) 附加循环分析约束。
ⓘ
g.edge_if("agent", "retry", |s| s.has_tool_calls()).max_visits(10);
g.edge_if("agent", "end", |_| true);Sourcepub fn edge_fallback(
&mut self,
from: impl Into<String>,
to: impl Into<String>,
) -> PendingEdge<'_>
pub fn edge_fallback( &mut self, from: impl Into<String>, to: impl Into<String>, ) -> PendingEdge<'_>
添加 fallback 边(无条件兜底)。
返回 PendingEdge,可通过 .max_visits(n) 附加循环分析约束。
Sourcepub fn build(self) -> Result<Graph, BuildErrors>
pub fn build(self) -> Result<Graph, BuildErrors>
构建 Graph。
收集所有错误后统一报告。Warning 变体不阻止 build 成功。
ⓘ
match builder.build() {
Ok(graph) => { /* 使用 graph */ }
Err(errors) => {
for e in &errors.0 {
eprintln!("{}", e);
}
}
}pub fn name(&self) -> &str
Auto Trait Implementations§
impl !RefUnwindSafe for GraphBuilder
impl !UnwindSafe for GraphBuilder
impl Freeze for GraphBuilder
impl Send for GraphBuilder
impl Sync for GraphBuilder
impl Unpin for GraphBuilder
impl UnsafeUnpin for GraphBuilder
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