pub struct Graph<State, Deps = (), End = ()>where
State: GraphState,{
pub nodes: HashMap<String, NodeDef<State, Deps, End>>,
/* private fields */
}Expand description
A graph for multi-agent workflows.
Fields§
§nodes: HashMap<String, NodeDef<State, Deps, End>>Nodes in the graph.
Implementations§
Source§impl<State, Deps, End> Graph<State, Deps, End>
impl<State, Deps, End> Graph<State, Deps, End>
Sourcepub fn with_max_steps(self, max: u32) -> Self
pub fn with_max_steps(self, max: u32) -> Self
Set maximum steps.
Sourcepub fn without_instrumentation(self) -> Self
pub fn without_instrumentation(self) -> Self
Disable auto instrumentation.
Sourcepub fn node<N>(self, name: impl Into<String>, node: N) -> Selfwhere
N: BaseNode<State, Deps, End> + 'static,
pub fn node<N>(self, name: impl Into<String>, node: N) -> Selfwhere
N: BaseNode<State, Deps, End> + 'static,
Add a node to the graph.
Sourcepub fn edge<F>(
self,
from: impl Into<String>,
to: impl Into<String>,
condition: F,
) -> Self
pub fn edge<F>( self, from: impl Into<String>, to: impl Into<String>, condition: F, ) -> Self
Add an edge with a condition.
Sourcepub fn edge_always(self, from: impl Into<String>, to: impl Into<String>) -> Self
pub fn edge_always(self, from: impl Into<String>, to: impl Into<String>) -> Self
Add an unconditional edge.
Sourcepub fn add_finish(self, name: impl Into<String>) -> Self
pub fn add_finish(self, name: impl Into<String>) -> Self
Add a finish node.
Sourcepub fn node_names(&self) -> impl Iterator<Item = &str>
pub fn node_names(&self) -> impl Iterator<Item = &str>
Get node names.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get node count.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Get edge count.
Sourcepub fn validate(&self) -> GraphResult<()>
pub fn validate(&self) -> GraphResult<()>
Validate the graph configuration.
Sourcepub fn build(self) -> GraphResult<Self>
pub fn build(self) -> GraphResult<Self>
Build and validate the graph.
Source§impl<State, Deps, End> Graph<State, Deps, End>
impl<State, Deps, End> Graph<State, Deps, End>
Sourcepub async fn run(
&self,
state: State,
deps: Deps,
) -> GraphResult<GraphRunResult<State, End>>
pub async fn run( &self, state: State, deps: Deps, ) -> GraphResult<GraphRunResult<State, End>>
Run the graph from the entry node.
Sourcepub async fn run_with_options(
&self,
state: State,
deps: Deps,
options: ExecutionOptions,
) -> GraphResult<GraphRunResult<State, End>>
pub async fn run_with_options( &self, state: State, deps: Deps, options: ExecutionOptions, ) -> GraphResult<GraphRunResult<State, End>>
Run the graph from the entry node with options.
Sourcepub async fn run_from<N>(
&self,
start: &N,
state: State,
deps: Deps,
) -> GraphResult<GraphRunResult<State, End>>
pub async fn run_from<N>( &self, start: &N, state: State, deps: Deps, ) -> GraphResult<GraphRunResult<State, End>>
Run the graph from a specific node.
Sourcepub async fn run_from_with_options<N>(
&self,
start: &N,
state: State,
deps: Deps,
options: ExecutionOptions,
) -> GraphResult<GraphRunResult<State, End>>
pub async fn run_from_with_options<N>( &self, start: &N, state: State, deps: Deps, options: ExecutionOptions, ) -> GraphResult<GraphRunResult<State, End>>
Run the graph from a specific node with options.
Trait Implementations§
Auto Trait Implementations§
impl<State, Deps, End> Freeze for Graph<State, Deps, End>
impl<State, Deps = (), End = ()> !RefUnwindSafe for Graph<State, Deps, End>
impl<State, Deps, End> Send for Graph<State, Deps, End>
impl<State, Deps, End> Sync for Graph<State, Deps, End>
impl<State, Deps, End> Unpin for Graph<State, Deps, End>
impl<State, Deps = (), End = ()> !UnwindSafe for Graph<State, Deps, End>
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