Skip to main content

ACID-like memory for Agents. Atomically syncs Pydantic models & Vector DBs with Git-style versioning.

Project description

MemState - Transactional Memory for AI Agents

PyPI version Python versions License Tests

ACID-like consistency layer for agent state. Ensures Structured Data (SQL) and Semantic Data (Vector Embeddings) stay synchronized, reversible, and type-safe.


Demo: Without MemState → memory gets inconsistent ❌   |   With MemState → atomic, type-safe, rollbackable agent state ✅
All demo scripts are available in the examples/ folder for reproducibility.


The Problem: Agent State Corruption

In most frameworks, agent state is treated as a second-class citizen:

  • Scattered JSON blobs.
  • Ad-hoc RAG embeddings that drift from the source of truth.
  • Inconsistent partial updates during failures.
  • No rollback mechanisms.

This leads to Data Drift: The SQL database says one thing, the Vector DB says another. The agent becomes unpredictable and hallucinates because its memory is fractured.

Agents need reliable state. Not a document dump.


MemState: A Consistency Layer

MemState treats agent memory as a transactional system, offering database semantics for application logic:

  • ⚛️ Atomicity — SQL and Vector DB changes succeed or rollback together.
  • 🛡️ Isolation — Intermediate steps in a workflow never leak to the main memory.
  • ⏪ Rollback — Revert any number of committed steps instantly.
  • 🔒 Schema Safety — Pydantic validation prevents data corruption at runtime.

It is the missing architecture between your Agent Logic and your Storage.


Quick Example

pip install memstate[chromadb]
from memstate import MemoryStore, Fact, SQLiteStorage
from memstate.integrations.chroma import ChromaSyncHook
import chromadb

# 1. Setup Storage
sqlite = SQLiteStorage("state.db")
chroma = chromadb.Client()

# 2. Define Transactional Sync
# This hook binds the Vector DB to the Atomic Lifecycle of the MemoryStore
hook = ChromaSyncHook(
    client=chroma,
    collection_name="agent_memory",
    text_field="content",
    metadata_fields=["role", "topic"]
)

memory = MemoryStore(sqlite)
memory.add_hook(hook=hook)

# 3. Atomic Write
# Persists to SQLite AND upserts to ChromaDB.
# If either fails, both are rolled back.
memory.commit(Fact(
    payload={
        "content": "User prefers vegetarian options",
        "role": "profile"
    }
))

# 4. Rollback
# Restores SQLite state AND deletes the vector from ChromaDB.
memory.rollback(1)

Why this matters

Standard tooling stores memory as a single opaque document. This breaks for:

  • Long-running agents where state accumulates errors.
  • Multi-step workflows requiring intermediate checkpoints.
  • Compliance/Audit systems needing a ledger of changes.
  • Hybrid Search where structured state and RAG context must match.

MemState introduces determinism to your agent's behavior.


Integrates with LangGraph

Drop-in replacement for the default checkpointer. Your graph state becomes structured, queryable, and transaction-safe.

from memstate.integrations.langgraph import MemStateCheckpointer

checkpointer = MemStateCheckpointer(memory=memory)
app = workflow.compile(checkpointer=checkpointer)

Key Capabilities

  • Hybrid Transactional Storage (SQL + Vectors)
  • Pydantic Schema Enforcement
  • Fact-based Versioning (Append-only Log)
  • Multi-step Atomic Commits
  • Pluggable Backends: SQLite (JSON1), Redis, In-Memory

Status

Alpha. The API is stable enough for building reliable agent prototypes. We follow Semantic Versioning.


📄 License

Licensed under the Apache 2.0 License.


🤝 Contributing

Issues and PRs welcome. See CONTRIBUTING.md for details.

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

memstate-0.3.2.tar.gz (355.9 kB view details)

Uploaded Source

Built Distribution

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

memstate-0.3.2-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file memstate-0.3.2.tar.gz.

File metadata

  • Download URL: memstate-0.3.2.tar.gz
  • Upload date:
  • Size: 355.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for memstate-0.3.2.tar.gz
Algorithm Hash digest
SHA256 23f0681802c5a967fe8f54643002c7a2d8e6f8a9eaf1f46b93c97bb36aebcd6a
MD5 f359616f66e68da35de7c0cfc9dee963
BLAKE2b-256 84fad9610b0af8d4ab661a8d6b90d9b54f0bc8fbed06dec44ea9b0a3707fc605

See more details on using hashes here.

File details

Details for the file memstate-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: memstate-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for memstate-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 91bd39257e8a0fa5beba12aef775c95cc905c953fe2fe75647c3506acb84a3d3
MD5 ff2535034da759e417b61fa087487840
BLAKE2b-256 f559972d6c104405b03d6324a242a1021a872186494abdfd71d9b5a0da808b70

See more details on using hashes here.

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