Skip to main content

Drop-in state backend for LangGraph, CrewAI & custom agent loops - Rust core, framework-agnostic, built for production.

Project description

swarmstate

Drop-in state backend for LangGraph, CrewAI & custom agent loops - Rust core, framework-agnostic, built for production.

~12.8× faster checkpoint writes than SqliteSaver on LangGraph's interface, and O(1) state snapshots (hundreds of thousands× faster than a deepcopy on large state). Reproducible numbers → swarmstate.github.io/benchmarks.

swarmstate is a state and checkpointing backend with a Rust core and a Python API for multi-agent systems. It does not compete with visible agent frameworks; it acts as low-level infrastructure - much like engines such as DuckDB, ClickHouse, Arrow, or Polars sit underneath data applications without replacing them.

It solves three production pains:

  1. State lock-in across frameworks - a framework-agnostic store so migrating frameworks doesn't lose state.
  2. Checkpointing cost and latency - a Rust-backed implementation of LangGraph's checkpointer interface.
  3. Deterministic routing paid for in tokens - a native handoff graph that resolves rule-based transitions in microseconds.

Installation

pip install swarmstate            # prebuilt abi3 wheels, no compiler required
uv add swarmstate                 # or with uv

Optional extras: swarmstate[langgraph], swarmstate[crewai], swarmstate[redis], swarmstate[disk], swarmstate[postgres], swarmstate[otel], swarmstate[all].

Usage

import swarmstate as ss

store = ss.Store()                              # in-memory, msgpack codec
store.set("workflow", "onboarding", {"step": 3, "data": {...}})
snap = store.snapshot()                          # cheap, immutable snapshot
store.set("workflow", "onboarding", {"step": 4})
store.restore(snap)                              # rollback
store.get("workflow", "onboarding")              # -> {"step": 3, "data": {...}}

snap2 = store.snapshot()
snap2.diff(snap)                                 # {"added": [...], "removed": [...], "changed": [...]}

# Deterministic, LLM-free routing (resolved natively in Rust)
g = ss.HandoffGraph()
g.add_edge("triage", "billing", when="category == 'billing'")
g.add_edge("triage", "human")                    # unconditional default
g.route("triage", {"category": "billing"})       # -> "billing"

Drop-in LangGraph checkpointer (pip install "swarmstate[langgraph]"):

from swarmstate.integrations.langgraph import SwarmStateSaver

graph = builder.compile(checkpointer=SwarmStateSaver())   # replaces SqliteSaver, 1 line

Optional metrics on checkpoint operations (opt-in, zero overhead when unused):

from swarmstate.observability import InMemoryMetrics       # or OpenTelemetryMetrics

metrics = InMemoryMetrics()
saver = SwarmStateSaver(metrics=metrics)
# ... run the graph ...
metrics.summary()   # {"put": {"count": 12, "p50_ms": 0.006, ...}, "get_tuple": {...}}

OpenTelemetry tracing (each checkpoint op becomes a swarmstate.checkpoint.<op> span):

from swarmstate.observability import get_tracer     # needs swarmstate[otel]

saver = SwarmStateSaver(tracer=get_tracer())         # composes with metrics=...

Status

Early development.

  • M0 (scaffolding) ✅ - Rust core builds; import swarmstate works.
  • M1 (Rust store) ✅ - concurrent KV store, msgpack codec, O(1) immutable snapshots, incremental diffs, GIL released on hot paths.
  • M2 (HandoffGraph) ✅ - deterministic conditional routing with a safe Rust condition evaluator (no eval), cycle detection.
  • M3 (LangGraph adapter) ✅ - SwarmStateSaver, a drop-in BaseCheckpointSaver backed by the Store; snapshot/roll back the whole checkpoint DB at once.
  • M4 (Benchmarks) ✅ - SwarmStateSaver.put ~12.8× faster than SqliteSaver; Store.snapshot() is O(1) (hundreds of thousands× faster than deep-copying large state). Reproducible: benchmarks/run.py; charts & tables in the docs.
  • M5 (CrewAI adapter + backends) ✅ - persistent, drop-in checkpointer backends RedisStore, DiskStore (SQLite) and PostgresStore, all msgpack wire-format, plus SwarmStateStorage (portable memory backed by a shared Store).
  • M6 (docs · wheels · PyPI) ✅ - full docs site, benchmarks, cross-platform abi3 wheels, and PyPI publishing via Trusted Publishing (OIDC).
  • Observability ✅ - opt-in metrics hooks and OpenTelemetry tracing on checkpoint ops (put / put_writes / get_tuple): an in-memory sink, an OpenTelemetry metrics sink, and per-op spans (swarmstate[otel]). Zero overhead when unused. Strict mypy in CI.

Examples

Runnable, offline, deterministic demos in examples/:

  • support_triage.py - a LangGraph workflow tying together HandoffGraph routing, SwarmStateSaver checkpointing and snapshot/restore time-travel.
  • state_portability.py - state as standard msgpack bytes, read back and cross-checked against the msgpack package.

Development

python -m venv .venv && source .venv/bin/activate
pip install maturin pytest
maturin develop --release     # compile the Rust core and install it locally
cargo test                    # Rust core tests
pytest -q                     # Python API tests

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmstate-0.9.2.tar.gz (85.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

swarmstate-0.9.2-cp39-abi3-win_amd64.whl (257.2 kB view details)

Uploaded CPython 3.9+Windows x86-64

swarmstate-0.9.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (378.0 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

swarmstate-0.9.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (374.9 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

swarmstate-0.9.2-cp39-abi3-macosx_11_0_arm64.whl (352.5 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

swarmstate-0.9.2-cp39-abi3-macosx_10_12_x86_64.whl (366.2 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file swarmstate-0.9.2.tar.gz.

File metadata

  • Download URL: swarmstate-0.9.2.tar.gz
  • Upload date:
  • Size: 85.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for swarmstate-0.9.2.tar.gz
Algorithm Hash digest
SHA256 f2fb5a32586ef4221b30d1de7cba91188f53e25c0a66c560460c2e568b8c24aa
MD5 fedfaab2e47354f886f01e5e78484f81
BLAKE2b-256 0c9cbe5dec4a53ffb5fafd996f62690fe5eb0a6fd4e8652960cb5c6ed63175f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarmstate-0.9.2.tar.gz:

Publisher: release.yml on swarmstate/swarmstate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file swarmstate-0.9.2-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: swarmstate-0.9.2-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 257.2 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for swarmstate-0.9.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 933100d1d817a71dae9efb87b47a7bdd5908329c836d86425bf52f921d476adc
MD5 03aa351f19952058d490ee2df1aab823
BLAKE2b-256 d8a8f0e444c4bae6c6e15e36351cac0f3bf5186cecd1ea66ae3e56543be9991d

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarmstate-0.9.2-cp39-abi3-win_amd64.whl:

Publisher: release.yml on swarmstate/swarmstate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file swarmstate-0.9.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for swarmstate-0.9.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6706f80bd6bf3b2f76a46b3f1dbe08b620e4b3b8ac744b3de7c9dbdd3861205
MD5 7899196b13a914d390a0096f9d1fc691
BLAKE2b-256 dc60111ec77a53afa88da5e5ed02643d0df0790afc390a55c8ccf2eb9e6a97f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarmstate-0.9.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on swarmstate/swarmstate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file swarmstate-0.9.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for swarmstate-0.9.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 defa63233e744c92dbf570a57ec8fe23d54594dadad320e7bd978b680213c4e5
MD5 c31390dfa786e1aae0bac29fb3be73e6
BLAKE2b-256 606851c5593665313ce6fd3947c8db522f47208c962922f5a864795e642a8f52

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarmstate-0.9.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on swarmstate/swarmstate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file swarmstate-0.9.2-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for swarmstate-0.9.2-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7a95a17afb78bd568118962393a146db22b70f2ae8e91b6a01e833ff8a2d8288
MD5 d11e226d499fa860fdfb433a27a72b0c
BLAKE2b-256 57ea3141c6415c298427ad56b12a16eca81f842315c1bff68e02226fec5f70b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarmstate-0.9.2-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on swarmstate/swarmstate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file swarmstate-0.9.2-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for swarmstate-0.9.2-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fd5b74c1411f59b60c39b833177dbe4290302d1fff41bd6d6ba88af38e957656
MD5 c52a8e0c29afea52ffab3148455f78af
BLAKE2b-256 6cc7279b14b291cf09d99e931f9c7a5e81eeb7b3d1a83c7b74f2a8b1a17d7da0

See more details on using hashes here.

Provenance

The following attestation bundles were made for swarmstate-0.9.2-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on swarmstate/swarmstate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page