Skip to main content

Graph

Struct Graph 

Source
pub struct Graph<State, Deps = (), End = ()>
where State: GraphState,
{ pub nodes: HashMap<String, NodeDef<State, Deps, End>>, /* private fields */ }
Available on crate feature graph only.
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>
where State: GraphState, Deps: Send + Sync + 'static, End: Send + Sync + 'static,

Source

pub fn new() -> Graph<State, Deps, End>

Create a new empty graph.

Source

pub fn with_name(self, name: impl Into<String>) -> Graph<State, Deps, End>

Set the graph name.

Source

pub fn with_max_steps(self, max: u32) -> Graph<State, Deps, End>

Set maximum steps.

Source

pub fn without_instrumentation(self) -> Graph<State, Deps, End>

Disable auto instrumentation.

Source

pub fn node<N>( self, name: impl Into<String>, node: N, ) -> Graph<State, Deps, End>
where N: BaseNode<State, Deps, End> + 'static,

Add a node to the graph.

Source

pub fn edge<F>( self, from: impl Into<String>, to: impl Into<String>, condition: F, ) -> Graph<State, Deps, End>
where F: Fn(&State) -> bool + Send + Sync + 'static,

Add an edge with a condition.

Source

pub fn edge_always( self, from: impl Into<String>, to: impl Into<String>, ) -> Graph<State, Deps, End>

Add an unconditional edge.

Source

pub fn entry(self, name: impl Into<String>) -> Graph<State, Deps, End>

Set the entry node.

Source

pub fn finish(self, names: &[&str]) -> Graph<State, Deps, End>

Set finish nodes.

Source

pub fn add_finish(self, name: impl Into<String>) -> Graph<State, Deps, End>

Add a finish node.

Source

pub fn name(&self) -> Option<&str>

Get the graph name.

Source

pub fn node_names(&self) -> impl Iterator<Item = &str>

Get node names.

Source

pub fn node_count(&self) -> usize

Get node count.

Source

pub fn edge_count(&self) -> usize

Get edge count.

Source

pub fn edges(&self) -> &[Edge<State>]

Get edges.

Source

pub fn validate(&self) -> Result<(), GraphError>

Validate the graph configuration.

Source

pub fn build(self) -> Result<Graph<State, Deps, End>, GraphError>

Build and validate the graph.

Source§

impl<State, Deps, End> Graph<State, Deps, End>
where State: GraphState, Deps: Clone + Send + Sync + 'static, End: Clone + Send + Sync + 'static,

Source

pub async fn run( &self, state: State, deps: Deps, ) -> Result<GraphRunResult<State, End>, GraphError>

Run the graph from the entry node.

Source

pub async fn run_with_options( &self, state: State, deps: Deps, options: ExecutionOptions, ) -> Result<GraphRunResult<State, End>, GraphError>

Run the graph from the entry node with options.

Source

pub async fn run_from<N>( &self, start: &N, state: State, deps: Deps, ) -> Result<GraphRunResult<State, End>, GraphError>
where N: BaseNode<State, Deps, End> + ?Sized,

Run the graph from a specific node.

Source

pub async fn run_from_with_options<N>( &self, start: &N, state: State, deps: Deps, options: ExecutionOptions, ) -> Result<GraphRunResult<State, End>, GraphError>
where N: BaseNode<State, Deps, End> + ?Sized,

Run the graph from a specific node with options.

Trait Implementations§

Source§

impl<State, Deps, End> Default for Graph<State, Deps, End>
where State: GraphState, Deps: Send + Sync + 'static, End: Send + Sync + 'static,

Source§

fn default() -> Graph<State, Deps, End>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more