Getting started
Warpra is a Rust library for stateful agent graphs. This page adds it to a project, builds a small graph with an interrupt, and runs it.
Requirements
Section titled “Requirements”- Rust 1.85 or newer. The crates use edition 2024.
- An async runtime. The examples use
tokio.
Add the crates
Section titled “Add the crates”Warpra is not on crates.io yet. Publishing comes with the first release. Until then, depend on the crates from the source tree with a path dependency.
| Crate | What it holds |
|---|---|
warpra |
Engine, StateGraph, channels, InMemorySaver, InMemoryStore, streaming, functional API |
warpra-checkpoint-sqlite |
SqliteSaver and SqliteStore |
warpra-checkpoint-postgres |
PostgresSaver and PostgresStore |
warpra-prebuilt |
create_react_agent, ToolNode, tools_condition, ValidationNode |
warpra-server |
An HTTP API (assistants, threads, runs, crons, store) for your graphs |
Clone the repository next to your project, then point Cargo.toml at the crates you need:
[dependencies]warpra = { path = "../warpra-repo/warpra/crates/warpra" }serde_json = "1"tokio = { version = "1", features = ["full"] }futures = "0.3" # only for streaming with StreamExtAdjust the path to where you cloned the repository. Add warpra-checkpoint-sqlite, warpra-prebuilt or warpra-server the same way, from warpra/crates/<name>.
A git dependency works the same way once the repository is public. Cargo finds each crate by name inside the repository:
warpra = { git = "https://github.com/Liceron/warpra" }A minimal graph
Section titled “A minimal graph”State is a serde_json::Value with one channel per key. Here topic keeps its last value and log is a list that every node appends to. The review node pauses the run with an interrupt. A checkpointer is required for that: it saves the paused thread.
use warpra::*;use warpra::graph::reducers;use serde_json::{json, Value};
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { let mut g = StateGraph::new() .last_value("topic") .reducer_with_initial("log", reducers::append, json!([])); g.add_node_fn("draft", |s: Value, _ctx: NodeCtx| async move { Ok::<Value, NodeError>(json!({"log": [format!("draft about {}", s["topic"])]})) })?; g.add_node_fn("review", |_s: Value, ctx: NodeCtx| async move { let verdict = ctx.interrupt(json!("approve?"))?; // pauses the run until resumed Ok::<Value, NodeError>(json!({"log": [format!("verdict: {verdict}")]})) })?; g.add_edge(START, "draft")?.add_edge("draft", "review")?.add_edge("review", END)?;
let app = g.compile(CompileOpts::new().checkpointer(std::sync::Arc::new(InMemorySaver::new())))?; let cfg = RunConfig::thread("t1");
let paused = app.invoke(json!({"topic": "rust"}), cfg.clone()).await?; println!("paused with: {}", paused.interrupts[0].value); // "approve?"
let done = app.invoke(Command::new().resume("yes"), cfg).await?; println!("log: {}", done.value["log"]); // both entries Ok(())}What happens:
- The first
invokerunsdraft, thenreviewcallsctx.interrupt(..). The run stops and returns the interrupt inpaused.interrupts. - The thread
t1is saved by the checkpointer. - The second
invokepassesCommand::new().resume("yes"). Thereviewnode runs again from the top, and this timectx.interruptreturns"yes".
Always propagate ctx.interrupt(..) with ?. That is how the node stops.
Run it
Section titled “Run it”cargo runRunnable examples in the repository
Section titled “Runnable examples in the repository”From the repository root:
cargo run -p warpra --example chatbot # agent/tool loop with a fake model closure, token streamingcargo run -p warpra --example human_approval # interrupt + Command::resume + Command::gotocargo run -p warpra-prebuilt --example react_agent # prebuilt ReAct agent, SQLite checkpoints, human approvalAll three run offline. The models are closures or scripted fakes, so you need no API key.
- Concepts at a glance lists each concept with its Rust call.
- State and channels explains reducers and
add_messages. - Warpra server serves your graph over Warpra’s HTTP API.
Warpra is open source under Apache-2.0. Made by Liceron.