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;
54pub mod compiled;
55pub mod edge;
56/// Graph error types and result aliases.
57pub mod errors;
58pub mod graph;
59pub mod node;
60pub mod persistence;
61pub mod state;
62pub mod subgraph;
63
64// Re-export core types
65pub use checkpointer::{
66 CheckpointData, Checkpointer, FileCheckpointer, MemoryCheckpointer,
67 ThreadSafeMemoryCheckpointer,
68};
69pub use compiled::{
70 CompiledGraph, DynamicInjection, DynamicPlanner, DynamicTask, ExecutionStep, GraphExecution,
71 GraphInvocation, ParallelBranch, ParallelInvocation, StreamEvent,
72};
73pub use edge::{AsyncFunctionRouter, ConditionalEdge, EdgeTarget, FunctionRouter, GraphEdge};
74pub use errors::{GraphError, GraphResult};
75pub use graph::{GraphBuilder, StateGraph, END, START};
76pub use node::{AsyncFn, AsyncNode, GraphNode, NodeConfig, NodeResult};
77pub use persistence::{
78 EdgeDefinition, EdgeType, FilePersistence, GraphDefinition, GraphPersistence,
79 MemoryPersistence, NodeDefinition, NodeType, PersistenceError, RouterDefinition,
80};
81pub use state::{
82 AgentState, AppendMessagesReducer, AppendReducer, AppendStepsReducer, MessageEntry,
83 MessageRole, Reducer, ReplaceReducer, StateSchema, StateUpdate, StepEntry,
84};
85pub use subgraph::{SubgraphBuilder, SubgraphNode};
86
87#[cfg(feature = "mongodb-persistence")]
88pub use persistence::{MongoConfig, MongoPersistence};