Skip to main content

Module graph

Module graph 

Source
Expand description

Graph-based Workflow Engine with Cycle Support

A LangGraph-inspired execution engine that supports:

  • Cycles for iterative reasoning loops
  • Conditional edges with dynamic routing
  • State checkpointing and recovery
  • Parallel branch execution
  • Maximum iteration limits to prevent infinite loops

§Example

use cortexai_crew::graph::{Graph, GraphBuilder, StateGraph};

// Create a reasoning loop that iterates until done
let graph = GraphBuilder::new("reasoning_loop")
    .add_node("think", think_node)
    .add_node("act", act_node)
    .add_node("evaluate", evaluate_node)
    .add_edge("think", "act")
    .add_edge("act", "evaluate")
    // Conditional: loop back to think or finish
    .add_conditional_edge("evaluate", |state| {
        if state.get("done").unwrap_or(&false) {
            "END"
        } else {
            "think"  // Loop back
        }
    })
    .set_entry("think")
    .set_finish("END")
    .build()?;

let result = graph.invoke(initial_state).await?;

Structs§

Checkpoint
State checkpoint for recovery
ConditionRouter
Condition-based router
FnNode
Simple function wrapper for node execution
FnRouter
Simple function-based router
Graph
The main graph structure
GraphBuilder
Builder for creating graphs
GraphConfig
Graph configuration
GraphMetadata
Execution metadata
GraphNode
A node in the graph
GraphResult
Result of graph execution
GraphState
Graph state - the data that flows through the graph
GraphStream
Streaming graph execution
InMemoryCheckpointStore
In-memory checkpoint store
StateGraph
StateGraph - a higher-level API for common patterns

Enums§

GraphEdge
Edge types in the graph
GraphStatus
Graph execution status

Constants§

END
START
Special node IDs

Traits§

CheckpointStore
Checkpoint storage trait
EdgeRouter
Router for conditional edges
NodeFn
Function type for node execution