pub struct StateGraph<S: State> { /* private fields */ }Expand description
Declarative graph definition with typed nodes and edges.
Build a graph using the fluent API, then call compile() to validate
and freeze it into a CompiledGraph for execution.
§Example
ⓘ
use pe_graph::{StateGraph, START, END};
let graph = StateGraph::new()
.add_node("prepare", prepare_node)
.add_node("chat", chat_node)
.add_edge(START, "prepare")
.add_edge("prepare", "chat")
.add_edge("chat", END)
.compile()?;Implementations§
Source§impl<S: State> StateGraph<S>
impl<S: State> StateGraph<S>
Sourcepub fn add_node(
self,
name: impl Into<String>,
node: impl NodeFn<S> + 'static,
) -> Self
pub fn add_node( self, name: impl Into<String>, node: impl NodeFn<S> + 'static, ) -> Self
Add a named node to the graph.
Reserved names (START, END) are rejected at compile() time,
not here — so the builder stays infallible and chainable.
Sourcepub fn add_edge(self, from: impl Into<String>, to: impl Into<String>) -> Self
pub fn add_edge(self, from: impl Into<String>, to: impl Into<String>) -> Self
Add a fixed edge: from always transitions to to after completing.
Use START for the first node, END for terminal nodes.
Sourcepub fn add_conditional_edge(
self,
from: impl Into<String>,
router: impl Fn(&S) -> Vec<String> + Send + Sync + 'static,
) -> Self
pub fn add_conditional_edge( self, from: impl Into<String>, router: impl Fn(&S) -> Vec<String> + Send + Sync + 'static, ) -> Self
Add a conditional edge: router reads state and returns next node names.
Return vec![END.to_string()] to terminate. Return multiple names
for parallel execution in the next superstep.
Sourcepub fn compile(self) -> Result<CompiledGraph<S>, PeError>
pub fn compile(self) -> Result<CompiledGraph<S>, PeError>
Validate the graph structure and freeze it into a CompiledGraph.
Validation checks:
- START has at least one outgoing edge
- All fixed edge targets/sources exist as node names (or START/END)
- No conditional edges from START
- All nodes are reachable from START
Trait Implementations§
Auto Trait Implementations§
impl<S> !RefUnwindSafe for StateGraph<S>
impl<S> !UnwindSafe for StateGraph<S>
impl<S> Freeze for StateGraph<S>
impl<S> Send for StateGraph<S>
impl<S> Sync for StateGraph<S>
impl<S> Unpin for StateGraph<S>
impl<S> UnsafeUnpin for StateGraph<S>
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