Skip to main content

Crate rust_langgraph

Crate rust_langgraph 

Source
Expand description

§Rust LangGraph — community graph runtime for LLM apps

Rust LangGraph is an independent Rust library inspired by LangGraph (not affiliated with LangChain). It helps you build stateful, multi-actor LLM workflows with a graph execution model similar in spirit to Google’s Pregel, with checkpointing, streaming, and conditional routing.

§Quick Start

use rust_langgraph::prelude::*;

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
struct MyState {
    count: i32,
}

impl State for MyState {
    fn merge(&mut self, other: Self) -> Result<(), Error> {
        self.count += other.count;
        Ok(())
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut graph = StateGraph::new();
     
    graph.add_node("increment", |state: MyState, _config: &Config| async move {
        Ok(MyState { count: state.count + 1 })
    });
     
    graph.set_entry_point("increment");
    graph.set_finish_point("increment");
     
    let app = graph.compile(None)?;
    let result = app.invoke(MyState { count: 0 }, Config::default()).await?;
     
    println!("Final count: {}", result.count);
    Ok(())
}

§Features

  • Stateful Execution: Build graphs where nodes communicate through shared state
  • Checkpointing: Save and resume execution at any point
  • Streaming: Stream events as the graph executes
  • Conditional Logic: Dynamic routing based on state
  • Parallel Execution: Execute independent nodes concurrently
  • Human-in-the-Loop: Interrupt and resume with human input
  • LLM Integration: OpenAI, OpenRouter, Anthropic, and Ollama adapters (feature-gated)

§More documentation

  • README.md — full user guide (install, tutorial, API table, examples)
  • AGENTS.md — cheat sheet for AI coding agents and contributors (correct crate name, features, patterns, pitfalls)

Re-exports§

pub use config::Config;
pub use errors::Error;
pub use errors::Result;
pub use state::State;
pub use graph::StateGraph;

Modules§

channels
Channels for state communication in graphs.
checkpoint
Checkpoint system for graph state persistence.
checkpoint_backends
Checkpoint backend implementations.
config
Configuration for graph execution.
errors
Error types for LangGraph operations.
graph
Graph builder API and compiled graph.
nodes
Node abstraction for graph execution.
pregel
Pregel execution engine and related types.
prelude
Re-exports of commonly used types for convenient imports
runtime
Runtime context for node execution.
state
State management and message handling.
types
Core types for LangGraph execution.