Expand description
§serdes-ai-graph
Graph-based execution and multi-agent orchestration for serdes-ai.
This crate provides a powerful graph execution engine for building complex, multi-step AI workflows with conditional branching and state management.
§Core Concepts
Graph: The main graph type, generic over state, deps, and end resultBaseNode: Trait for nodes that can execute within a graphNodeResult: Enum indicating next step or terminationEdge: Conditional transitions between nodes
§Node Types
FunctionNode: Execute an async functionAgentNode: Run an agent and update stateRouterNode: Dynamic routing based on stateConditionalNode: Branch based on condition
§State Persistence
StatePersistence: Trait for saving/loading stateInMemoryPersistence: In-memory state storageFilePersistence: File-based state storage
§Example
ⓘ
use serdes_ai_graph::{Graph, BaseNode, NodeResult, GraphRunContext};
use async_trait::async_trait;
#[derive(Debug, Clone, Default)]
struct WorkflowState {
query: String,
response: Option<String>,
}
struct ProcessNode;
#[async_trait]
impl BaseNode<WorkflowState, (), String> for ProcessNode {
fn name(&self) -> &str { "process" }
async fn run(
&self,
ctx: &mut GraphRunContext<WorkflowState, ()>,
) -> Result<NodeResult<WorkflowState, (), String>, GraphError> {
ctx.state.response = Some(format!("Processed: {}", ctx.state.query));
Ok(NodeResult::end(ctx.state.response.clone().unwrap()))
}
}
let graph = Graph::new()
.node("process", ProcessNode)
.entry("process")
.build()?;
let result = graph.run(WorkflowState::default(), ()).await?;Re-exports§
pub use edge::Edge;pub use edge::EdgeBuilder;pub use error::GraphError;pub use error::GraphResult;pub use executor::ExecutionOptions;pub use executor::GraphExecutor;pub use executor::NoPersistence;pub use graph::Graph;pub use graph::SimpleGraph;pub use iter::GraphIter;pub use iter::StepResult;pub use mermaid::generate_flowchart;pub use mermaid::generate_mermaid;pub use mermaid::MermaidBuilder;pub use mermaid::MermaidDirection;pub use mermaid::MermaidOptions;pub use node::AgentNode;pub use node::BaseNode;pub use node::ConditionalNode;pub use node::End;pub use node::FunctionNode;pub use node::Node;pub use node::NodeDef;pub use node::NodeResult;pub use node::RouterNode;pub use persistence::FilePersistence;pub use persistence::InMemoryPersistence;pub use persistence::PersistenceError;pub use persistence::StatePersistence;pub use state::generate_run_id;pub use state::GraphRunContext;pub use state::GraphRunResult;pub use state::GraphState;pub use state::PersistableState;
Modules§
- edge
- Graph edge types.
- error
- Graph error types.
- executor
- Graph execution engine.
- graph
- Graph definition and execution.
- iter
- Graph iteration support.
- mermaid
- Mermaid diagram generation for graphs.
- node
- Graph node types.
- persistence
- State persistence for graph execution.
- prelude
- Prelude for common imports.
- state
- Graph state types.