Skip to content

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.

  • Rust 1.85 or newer. The crates use edition 2024.
  • An async runtime. The examples use tokio.

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:

Cargo.toml
[dependencies]
warpra = { path = "../warpra-repo/warpra/crates/warpra" }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
futures = "0.3" # only for streaming with StreamExt

Adjust 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" }

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.

src/main.rs
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:

  1. The first invoke runs draft, then review calls ctx.interrupt(..). The run stops and returns the interrupt in paused.interrupts.
  2. The thread t1 is saved by the checkpointer.
  3. The second invoke passes Command::new().resume("yes"). The review node runs again from the top, and this time ctx.interrupt returns "yes".

Always propagate ctx.interrupt(..) with ?. That is how the node stops.

cargo run

From the repository root:

cargo run -p warpra --example chatbot # agent/tool loop with a fake model closure, token streaming
cargo run -p warpra --example human_approval # interrupt + Command::resume + Command::goto
cargo run -p warpra-prebuilt --example react_agent # prebuilt ReAct agent, SQLite checkpoints, human approval

All three run offline. The models are closures or scripted fakes, so you need no API key.

Warpra is open source under Apache-2.0. Made by Liceron.