Concepts at a glance
This page lists Warpra’s main concepts and the Rust call for each. Follow the links for the full pages.
The basics
Section titled “The basics”- State is JSON. State is a
serde_json::Valuewith one channel per key. A typed layer exists:StateGraph::<S>withadd_typed_nodeandadd_typed_conditional_edges, whereS: Serialize + DeserializeOwned.StateGraph::<S>::typed()derives the keys fromS::default(). - Nodes are async closures. A node takes
(state: Value, ctx: NodeCtx)and returns a future ofResult<_, NodeError>. - Interrupts use
?.ctx.interrupt(payload)?must be propagated. On resume the node re-runs from the top. - Channels are declared on the builder. You declare each key with
last_value,reducerormessages. - Ids are deterministic. Task and interrupt ids are xxh3-128 hashes.
Quick reference
Section titled “Quick reference”| Concept | Rust |
|---|---|
| State | StateGraph::new().last_value("k"), or typed StateGraph::<S>::typed() |
| Reducer channel | .reducer_with_initial("log", reducers::append, json!([])) |
| Messages channel | .messages("messages"); the reducer is warpra::add_messages |
| Node | g.add_node_fn("a", |s: Value, ctx: NodeCtx| async move { .. })? |
| Node with retry, cache and destinations | g.add_node_with("a", node_fn(..), NodeOpts::new().retry(..).cache(..).destinations([..]))? |
| Sequence of nodes | g.add_sequence(..)? |
| Edge | g.add_edge(START, "a")? |
| Conditional edge | g.add_conditional_edges("a", |s: &Value| .., Some(&[("x", "x"), (END, END)]))? |
Send fan-out |
SendPacket::new("worker", json!(..)) (warpra::types::Send) |
Command with update and goto |
Command::new().update(json!(..)).goto("node") |
Command to the parent graph |
Command::new().parent() |
| Interrupt | ctx.interrupt(json!(..))? |
| Resume | app.invoke(Command::new().resume(v), cfg).await? |
| Static breakpoint | CompileOpts::new().interrupt_before(["tools"]) |
| Checkpointer | g.compile(CompileOpts::new().checkpointer(Arc::new(InMemorySaver::new())))? |
| SQLite and Postgres savers | warpra_checkpoint_sqlite::SqliteSaver, warpra_checkpoint_postgres::PostgresSaver |
| Thread | RunConfig::thread("1") |
| Invoke | app.invoke(input, cfg).await? |
| Streaming | app.stream(input, cfg, &[StreamMode::Updates], StreamOpts::default()) |
| State, history and update | app.get_state(&cfg, false), app.get_state_history(&cfg, None, None, None), app.update_state(&cfg, Some(values), Some("node")) |
| Store | warpra::InMemoryStore |
| Functional API | Entrypoint::new(..).checkpointer(..).build() / TaskDef::new(..) |
| Final value with separate saved value | EntryResult::final_(value, save) |
| Run context | RunConfig::new().with_context(..), get_runtime() |
| Prebuilt agent | warpra_prebuilt::create_react_agent(model, tools, AgentOptions::new()) |
| Tool node and condition | warpra_prebuilt::ToolNode::new(tools), warpra_prebuilt::tools_condition |
| Mermaid drawing | app.draw_mermaid() |
Stream modes are values, updates, checkpoints, tasks, debug, messages, custom and tools. Durability modes are sync, async and exit. Both parse from these names with serde and FromStr.
Reading msgpack checkpoints
Section titled “Reading msgpack checkpoints”Checkpoints serialized with msgpack by Python clients are readable. PythonCompatSerde reads the tags null, empty, bytes, bytearray, legacy json and msgpack. It writes like the default JsonSerde. pickle is refused with an error, by design.
Attach it to a saver:
use std::sync::Arc;use warpra::PythonCompatSerde;use warpra_checkpoint_sqlite::SqliteSaver;
let saver = Arc::new(SqliteSaver::from_path(&path).await?.with_serde(Arc::new(PythonCompatSerde)));PostgresSaver has the same with_serde method.
What is not supported yet
Section titled “What is not supported yet”See Status and roadmap for the engine and prebuilt agent, and the server gaps.
Warpra is open source under Apache-2.0. Made by Liceron.