Skip to main content

lc_langgraph/
lib.rs

1// crates/lc-langgraph/src/lib.rs
2//! LangGraph - Graph-based orchestration framework for building stateful LLM applications
3//!
4//! LangGraph provides a low-level graph orchestration framework that enables:
5//! - Stateful, long-running agent workflows
6//! - Conditional routing and branching
7//! - Subgraph composition
8//! - Cycle support for iterative processes
9//!
10//! # Core Concepts
11//!
12//! - **StateGraph**: Main graph class that manages State, Nodes, and Edges
13//! - **Node**: Execution unit that takes state and produces state updates
14//! - **Edge**: Transition between nodes (fixed or conditional)
15//! - **State**: Data structure that flows through the graph
16//!
17//! # Example
18//!
19//! ```rust,ignore
20//! use lc_langgraph::{StateGraph, GraphNode, StateSchema, START, END};
21//! use serde::{Deserialize, Serialize};
22//!
23//! // Define state
24//! #[derive(Serialize, Deserialize, Clone)]
25//! struct MyState {
26//!     messages: Vec<String>,
27//!     count: usize,
28//! }
29//!
30//! impl StateSchema for MyState {}
31//!
32//! // Create graph
33//! let mut graph = StateGraph::<MyState>::new();
34//!
35//! // Add nodes
36//! graph.add_node("process", |state: MyState| {
37//!     MyState {
38//!         messages: state.messages.clone(),
39//!         count: state.count + 1,
40//!     }
41//! });
42//!
43//! // Add edges
44//! graph.add_edge(START, "process");
45//! graph.add_edge("process", END);
46//!
47//! // Compile and run
48//! let compiled = graph.compile();
49//! let result = compiled.invoke(MyState { messages: vec![], count: 0 }).await?;
50//! ```
51
52pub mod checkpointer;
53pub mod compiled;
54pub mod edge;
55pub mod errors;
56pub mod graph;
57pub mod node;
58pub mod persistence;
59pub mod state;
60pub mod subgraph;
61
62// Re-export core types
63pub use checkpointer::{
64    CheckpointData, Checkpointer, FileCheckpointer, MemoryCheckpointer,
65    ThreadSafeMemoryCheckpointer,
66};
67pub use compiled::{
68    CompiledGraph, DynamicInjection, DynamicPlanner, DynamicTask, ExecutionStep, GraphExecution,
69    GraphInvocation, ParallelBranch, ParallelInvocation, StreamEvent,
70};
71pub use edge::{AsyncFunctionRouter, ConditionalEdge, EdgeTarget, FunctionRouter, GraphEdge};
72pub use errors::{GraphError, GraphResult};
73pub use graph::{GraphBuilder, StateGraph, END, START};
74pub use node::{AsyncFn, AsyncNode, GraphNode, NodeConfig, NodeResult};
75pub use persistence::{
76    EdgeDefinition, EdgeType, FilePersistence, GraphDefinition, GraphPersistence,
77    MemoryPersistence, NodeDefinition, NodeType, PersistenceError, RouterDefinition,
78};
79pub use state::{
80    AgentState, AppendMessagesReducer, AppendReducer, AppendStepsReducer, MessageEntry,
81    MessageRole, Reducer, ReplaceReducer, StateSchema, StateUpdate, StepEntry,
82};
83pub use subgraph::{SubgraphBuilder, SubgraphNode};
84
85#[cfg(feature = "mongodb-persistence")]
86pub use persistence::{MongoConfig, MongoPersistence};