pub struct GraphBuilder<S: WorkflowState = State, M: MergeStrategy<S> = StateMerge> { /* private fields */ }Expand description
Graph 构建器。
Implementations§
Source§impl<S: WorkflowState, M: MergeStrategy<S>> GraphBuilder<S, M>
impl<S: WorkflowState, M: MergeStrategy<S>> GraphBuilder<S, M>
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
创建 GraphBuilder。
类型参数由调用方推断或显式指定。
- 默认:
GraphBuilder::new("name")→GraphBuilder<State, StateMerge> - 自定义:
GraphBuilder::<AgentState, _>::new("name")
Sourcepub fn canonical_hash(&mut self, hash: u64) -> &mut Self
pub fn canonical_hash(&mut self, hash: u64) -> &mut Self
P0-2: 设置 canonical hash — 由 DSL 层(如 AgentBuilder)调用。
如果不设置,build() 会自动计算一个基于图结构的 hash。
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<S, M>, ) -> &mut Self
Sourcepub fn subgraph<Inner, IM, L>(
&mut self,
name: impl Into<String>,
spec: SubgraphSpec<S, Inner, IM, L>,
) -> &mut Selfwhere
S: 'static,
Inner: 'static + WorkflowState,
IM: 'static + MergeStrategy<Inner>,
L: 'static + StateLens<S, Inner>,
pub fn subgraph<Inner, IM, L>(
&mut self,
name: impl Into<String>,
spec: SubgraphSpec<S, Inner, IM, L>,
) -> &mut Selfwhere
S: 'static,
Inner: 'static + WorkflowState,
IM: 'static + MergeStrategy<Inner>,
L: 'static + StateLens<S, Inner>,
便捷方法 — 添加 Subgraph 节点。
自动将 SubgraphSpec 编译为 CompiledSubgraph
并注册为节点。
§示例
ⓘ
use lellm_graph::{GraphBuilder, SubgraphSpec, StateLens};
let agent_graph = AgentBuilder::new(model).tools([...]).build();
let spec = SubgraphSpec::new(agent_graph, AgentLens);
let mut builder = GraphBuilder::<WorkflowState, _>::new("workflow");
builder.subgraph("agent", spec); // 语法糖
// 等价于:
// builder.node("agent", NodeKind::Subgraph(spec.compile()));pub fn edge( &mut self, from: impl Into<String>, to: impl Into<String>, ) -> PendingEdge<'_, S, M>
pub fn edge_if( &mut self, from: impl Into<String>, to: impl Into<String>, condition: impl Fn(&S) -> bool + Send + Sync + 'static, ) -> PendingEdge<'_, S, M>
pub fn edge_fallback( &mut self, from: impl Into<String>, to: impl Into<String>, ) -> PendingEdge<'_, S, M>
pub fn build(self) -> Result<Graph<S, M>, BuildErrors>
pub fn name(&self) -> &str
Auto Trait Implementations§
impl<S = State, M = StateMerge> !RefUnwindSafe for GraphBuilder<S, M>
impl<S = State, M = StateMerge> !UnwindSafe for GraphBuilder<S, M>
impl<S, M> Freeze for GraphBuilder<S, M>
impl<S, M> Send for GraphBuilder<S, M>
impl<S, M> Sync for GraphBuilder<S, M>
impl<S, M> Unpin for GraphBuilder<S, M>
impl<S, M> UnsafeUnpin for GraphBuilder<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