Skip to main content

StateGraph

Struct StateGraph 

Source
pub struct StateGraph<S: StateSchema> { /* private fields */ }
Expand description

StateGraph - Main graph builder

Manages nodes, edges, and state schema for graph execution. After building, compile to get an executable CompiledGraph.

Implementations§

Source§

impl<S: StateSchema + 'static> StateGraph<S>

Source

pub fn new() -> Self

Create a new empty state graph.

Source

pub fn add_node<N: GraphNode<S> + 'static>(&mut self, node: N) -> &mut Self

Add a node to the graph.

Source

pub fn add_node_fn<F>(&mut self, name: impl Into<String>, func: F) -> &mut Self
where F: Fn(&S) -> Result<StateUpdate<S>, GraphError> + Send + Sync + 'static,

Add a synchronous function node to the graph.

Source

pub fn add_async_node<F>( &mut self, name: impl Into<String>, func: F, ) -> &mut Self
where F: AsyncFn<S> + 'static,

Add an async function node to the graph.

Source

pub fn add_subgraph<SubS: StateSchema + 'static>( &mut self, name: impl Into<String>, subgraph: CompiledGraph<SubS>, input_mapper: impl Fn(&S) -> SubS + Send + Sync + 'static, output_mapper: impl Fn(&SubS, &mut S) + Send + Sync + 'static, ) -> &mut Self

Add a subgraph node with input/output mappers.

Source

pub fn add_subgraph_same_state( &mut self, name: impl Into<String>, subgraph: CompiledGraph<S>, ) -> &mut Self

Add a subgraph node that shares the same state type.

Source

pub fn add_edge( &mut self, source: impl Into<String>, target: impl Into<String>, ) -> &mut Self

Add a fixed edge between two nodes.

Source

pub fn add_conditional_edges( &mut self, source: impl Into<String>, router_name: impl Into<String>, targets: HashMap<String, String>, default: Option<String>, ) -> &mut Self

Add a conditional edge routed by a named router.

Source

pub fn add_fan_out( &mut self, source: impl Into<String>, targets: Vec<String>, ) -> &mut Self

Add a FanOut edge for parallel execution.

Source

pub fn add_fan_in( &mut self, sources: Vec<String>, target: impl Into<String>, ) -> &mut Self

Add a FanIn edge joining multiple sources into one target.

Source

pub fn set_conditional_router<R: ConditionalEdge<S> + 'static>( &mut self, name: impl Into<String>, router: R, ) -> &mut Self

Register a conditional routing function by name.

Source

pub fn set_entry_point(&mut self, node: impl Into<String>) -> &mut Self

Set the entry point node for the graph.

Source

pub fn set_reducer( &mut self, field: impl Into<String>, reducer: Arc<dyn Reducer<S>>, ) -> &mut Self

Register a reducer for a specific state field.

Source

pub fn compile(&self) -> GraphResult<CompiledGraph<S>>

Compile the graph into an executable CompiledGraph.

Trait Implementations§

Source§

impl<S: StateSchema + 'static> Default for StateGraph<S>

Source§

fn default() -> Self

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

Auto Trait Implementations§

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.