rust_langgraph/lib.rs
1//! # Rust LangGraph — community graph runtime for LLM apps
2//!
3//! **Rust LangGraph** is an independent Rust library inspired by [LangGraph](https://github.com/langchain-ai/langgraph)
4//! (not affiliated with LangChain). It helps you build stateful, multi-actor LLM workflows with a graph execution
5//! model similar in spirit to Google’s Pregel, with checkpointing, streaming, and conditional routing.
6//!
7//! ## Quick Start
8//!
9//! ```rust,no_run
10//! use rust_langgraph::prelude::*;
11//!
12//! #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
13//! struct MyState {
14//! count: i32,
15//! }
16//!
17//! impl State for MyState {
18//! fn merge(&mut self, other: Self) -> Result<(), Error> {
19//! self.count += other.count;
20//! Ok(())
21//! }
22//! }
23//!
24//! #[tokio::main]
25//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
26//! let mut graph = StateGraph::new();
27//!
28//! graph.add_node("increment", |state: MyState, _config: &Config| async move {
29//! Ok(MyState { count: state.count + 1 })
30//! });
31//!
32//! graph.set_entry_point("increment");
33//! graph.set_finish_point("increment");
34//!
35//! let app = graph.compile(None)?;
36//! let result = app.invoke(MyState { count: 0 }, Config::default()).await?;
37//!
38//! println!("Final count: {}", result.count);
39//! Ok(())
40//! }
41//! ```
42//!
43//! ## Features
44//!
45//! - **Stateful Execution**: Build graphs where nodes communicate through shared state
46//! - **Checkpointing**: Save and resume execution at any point
47//! - **Streaming**: Stream events as the graph executes
48//! - **Conditional Logic**: Dynamic routing based on state
49//! - **Parallel Execution**: Execute independent nodes concurrently
50//! - **Human-in-the-Loop**: Interrupt and resume with human input
51//! - **LLM Integration**: OpenAI, OpenRouter, Anthropic, and Ollama adapters (feature-gated)
52//!
53//! ## More documentation
54//!
55//! - **README.md** — full user guide (install, tutorial, API table, examples)
56//! - **AGENTS.md** — cheat sheet for AI coding agents and contributors (correct crate name, features, patterns, pitfalls)
57
58pub mod config;
59pub mod errors;
60pub mod state;
61pub mod types;
62
63pub mod channels;
64pub mod nodes;
65pub mod pregel;
66pub mod graph;
67pub mod checkpoint;
68
69#[cfg(feature = "memory-checkpoint")]
70pub mod checkpoint_backends;
71
72#[cfg(any(
73 feature = "openai",
74 feature = "openrouter",
75 feature = "anthropic",
76 feature = "ollama"
77))]
78pub mod llm;
79
80#[cfg(feature = "prebuilt")]
81pub mod prebuilt;
82
83pub mod runtime;
84
85/// Re-exports of commonly used types for convenient imports
86pub mod prelude {
87 pub use crate::config::Config;
88 pub use crate::errors::{Error, Result};
89 pub use crate::state::{State, MessagesState, Message, add_messages};
90 pub use crate::types::{Send, Command, StreamMode, StreamEvent};
91 pub use crate::nodes::Node;
92 pub use crate::graph::{StateGraph, CompiledGraph};
93 pub use crate::checkpoint::{BaseCheckpointSaver, Checkpoint};
94
95 #[cfg(feature = "memory-checkpoint")]
96 pub use crate::checkpoint_backends::memory::MemorySaver;
97
98 #[cfg(feature = "prebuilt")]
99 pub use crate::prebuilt::{create_react_agent, Tool, ToolNode};
100
101 #[cfg(any(
102 feature = "openai",
103 feature = "openrouter",
104 feature = "anthropic",
105 feature = "ollama"
106 ))]
107 pub use crate::llm::ChatModel;
108}
109
110// Re-export commonly used types at the crate root
111pub use config::Config;
112pub use errors::{Error, Result};
113pub use state::State;
114pub use graph::StateGraph;