Skip to main content

lc_langgraph/
lib.rs

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