Expand description
LangGraph - Graph-based orchestration framework for building stateful LLM applications
LangGraph provides a low-level graph orchestration framework that enables:
- Stateful, long-running agent workflows
- Conditional routing and branching
- Subgraph composition
- Cycle support for iterative processes
§Core Concepts
- StateGraph: Main graph class that manages State, Nodes, and Edges
- Node: Execution unit that takes state and produces state updates
- Edge: Transition between nodes (fixed or conditional)
- State: Data structure that flows through the graph
§Example
ⓘ
use lc_langgraph::{StateGraph, GraphNode, StateSchema, START, END};
use serde::{Deserialize, Serialize};
// Define state
#[derive(Serialize, Deserialize, Clone)]
struct MyState {
messages: Vec<String>,
count: usize,
}
impl StateSchema for MyState {}
// Create graph
let mut graph = StateGraph::<MyState>::new();
// Add nodes
graph.add_node("process", |state: MyState| {
MyState {
messages: state.messages.clone(),
count: state.count + 1,
}
});
// Add edges
graph.add_edge(START, "process");
graph.add_edge("process", END);
// Compile and run
let compiled = graph.compile();
let result = compiled.invoke(MyState { messages: vec![], count: 0 }).await?;Re-exports§
pub use checkpointer::CheckpointData;pub use checkpointer::Checkpointer;pub use checkpointer::FileCheckpointer;pub use checkpointer::MemoryCheckpointer;pub use checkpointer::ThreadSafeMemoryCheckpointer;pub use compiled::CompiledGraph;pub use compiled::DynamicInjection;pub use compiled::DynamicPlanner;pub use compiled::DynamicTask;pub use compiled::ExecutionStep;pub use compiled::GraphExecution;pub use compiled::GraphInvocation;pub use compiled::ParallelBranch;pub use compiled::ParallelInvocation;pub use compiled::StreamEvent;pub use edge::AsyncFunctionRouter;pub use edge::ConditionalEdge;pub use edge::EdgeTarget;pub use edge::FunctionRouter;pub use edge::GraphEdge;pub use errors::GraphError;pub use errors::GraphResult;pub use graph::GraphBuilder;pub use graph::StateGraph;pub use graph::END;pub use graph::START;pub use node::AsyncFn;pub use node::AsyncNode;pub use node::GraphNode;pub use node::NodeConfig;pub use node::NodeResult;pub use persistence::EdgeDefinition;pub use persistence::EdgeType;pub use persistence::FilePersistence;pub use persistence::GraphDefinition;pub use persistence::GraphPersistence;pub use persistence::MemoryPersistence;pub use persistence::NodeDefinition;pub use persistence::NodeType;pub use persistence::PersistenceError;pub use persistence::RouterDefinition;pub use state::AgentState;pub use state::AppendMessagesReducer;pub use state::AppendReducer;pub use state::AppendStepsReducer;pub use state::MessageEntry;pub use state::MessageRole;pub use state::Reducer;pub use state::ReplaceReducer;pub use state::StateSchema;pub use state::StateUpdate;pub use state::StepEntry;pub use subgraph::SubgraphBuilder;pub use subgraph::SubgraphNode;
Modules§
- checkpointer
- Checkpointing for state persistence
- compiled
- CompiledGraph - Executable graph with state management
- edge
- Edge definition for LangGraph
- errors
- Graph error types and result aliases.
- graph
- StateGraph - Main graph class for LangGraph
- node
- Node definition for LangGraph
- persistence
- Graph persistence for serialization and storage
- state
- State management for LangGraph
- subgraph
- Subgraph Support for LangGraph