Skip to content

Warpra server

warpra-server is an HTTP server for graphs built with warpra. It serves Warpra’s HTTP API (assistants, threads, runs, crons, store) over REST and SSE. The official Python client and RemoteGraph can call it. See Python and JavaScript clients.

use warpra::{CompileOpts, NodeCtx, NodeError, StateGraph, END, START};
use warpra_server::{GraphContext, Server};
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Server::builder()
.graph("echo", |ctx: GraphContext| async move {
let mut g = StateGraph::new().last_value("text");
g.add_node_fn("echo", |s: Value, _c: NodeCtx| async move {
Ok::<Value, NodeError>(json!({"text": format!("{} echoed", s["text"].as_str().unwrap_or(""))}))
})?;
g.add_edge(START, "echo")?;
g.add_edge("echo", END)?;
g.compile(CompileOpts::new().checkpointer(ctx.checkpointer.clone()).store(ctx.store.clone()))
})
.build()?
.serve()
.await?;
Ok(())
}

The factory receives a GraphContext with the server’s checkpointer and store. Compile with them so threads persist in the server’s backend. The factory runs per run and per state or introspection request, so it can build a graph per assistant.

The server reads its settings from the environment. Auth is on by default, so set an API key of at least 24 characters before you start it:

export WARPRA_API_KEYS=dev-key-0123456789abcdefghij
cargo run

Without a database URL the server uses the in-memory backend and logs a warning. It listens on 127.0.0.1:8000 by default.

Other builder methods: graph_description, schemas, message_keys, wire_messages, model_registry, config_file, config_json and env.

The warpra-server binary serves graphs declared in warpra.json (declarative ReAct agents). Subcommands:

Command What it does
serve (default) Run until SIGTERM or Ctrl-C
healthcheck GET /ok on the local port; exit 0 on 200, else 1
migrate Apply database migrations and exit
check-config Validate the configuration, print the resolved graphs and exit

The released image contains no code graphs. For code graphs, build your own binary on the library as above.

  • Assistants: create, get, update (new version), delete, search, count, versions, set latest, graph drawing (xray), schemas, subgraphs. Each registered graph gets a default assistant whose id is uuid5 of the graph id.
  • Threads: create, get, update, delete, search, count, copy, prune, TTL, state (latest, by checkpoint id, by checkpoint), state update, history, thread stream.
  • Runs: stateful and stateless; create, stream, wait, batch, list, get, delete, join, join stream, cancel, cancel many. Multitask strategies reject, enqueue (default), interrupt and rollback. Resumable streams with Last-Event-ID replay. Delayed runs (after_seconds). Interrupts and command.resume, by value or by interrupt id. interrupt_before and interrupt_after.
  • Crons: 5-field schedules and aliases such as @daily, in an IANA timezone, with end_time, enable and disable, search and count.
  • Store: put, get, delete, search (with semantic search when an index is configured), list namespaces, TTL.
  • Webhooks: sent once per finished run, signed with X-Nexura-Signature (HMAC-SHA256) when a signing secret is set, with up to 3 retries. Private, loopback and metadata addresses are rejected.
  • Auth: API keys (x-api-key or Authorization: Bearer), CORS.
  • Persistence: memory, SQLite or Postgres. One database holds checkpoints, the store and the server’s tables.
  • Process lifecycle: startup recovery, run leases and heartbeats, SIGTERM drain, TTL and event-log sweepers.
  • Meta: GET /ok (public health check) and GET /info.

Runs stream these modes over SSE: values, updates, messages, messages-tuple, custom, checkpoints, tasks, debug and tools. messages is accumulated on the server into messages/metadata, messages/partial and messages/complete events. Subgraph events carry |ns suffixes.

With Postgres, run several replicas. Any replica serves any request. Runs are claimed from the database (SKIP LOCKED), streams and cancels reach other replicas through LISTEN/NOTIFY with a polling fallback, and crons and sweepers take advisory locks. Tests cover two worker pools that never run a run twice, and a stream and cancel on an API-only replica for a run another replica executes. Set WARPRA_N_JOBS_PER_WORKER=0 for an API-only replica.

SQLite and memory support exactly one replica. SQLite takes a file lock and refuses to start when it is held.

These are not yet supported, or are limited by design:

  • v3 protocol: threads.stream(), RemoteGraph.stream_events(version="v3"), the /threads/{id}/commands and /threads/{id}/stream/events routes, and the WebSocket transport answer 501.
  • Stream modes: events and lifecycle return 422 unsupported_stream_mode. lifecycle belongs to v3.
  • Ids: thread and assistant ids must be UUIDs. A non-UUID id, such as RemoteGraph with thread_id="1", returns 422 invalid_uuid.
  • Reserved keys: __* keys in configurable return 422, except __pregel_resuming, __pregel_resume_map and __pregel_durability, which RemoteGraph forwards when it runs as a node of a local graph.
  • Credentials in config: keys that look like credentials or endpoints (api_key, base_url, *_token, *_secret, …) in configurable or context return 422. Model credentials come only from server config and environment.
  • Thread stream: the event names of threads.join_stream are a design guess.
  • Python graphs: Python import paths in the config are refused. Custom auth handlers, per-user resource isolation, /docs, /openapi.json and /metrics are not available. All authenticated keys see all resources.
  • Thread stream scope on Postgres: the thread stream only sees runs executed and state updates handled by the same replica.
  • Graph caching: not implemented. Graphs are built per request.
  • MCP servers: wired in the config, but only exercised through configuration errors in tests.
  • Web UI: not yet available. Warpra Studio is planned.
  • In-process HTTP tests over memory and SQLite for every route, every stream mode’s event names and payload keys, interrupts and resume, multitask strategies, cancel, resumable streams, crons, webhooks, lease recovery and SIGTERM drain.
  • The same suite against Postgres, plus live multi-replica tests.
  • Tested with the official Python client and RemoteGraph: 58/58 suite tests and 22/22 client integration tests, on the memory and Postgres backends. See Python and JavaScript clients.

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