Skip to main content

git for agent brains โ€” move, debug, and secure AI agent state across 10 frameworks

Project description

๐Ÿงถ StateWeave

git for agent brains.

Your agent switches frameworks. Its memories come with it.

PyPI CI License Python


StateWeave moves, debugs, and secures AI agent state across 10 frameworks. Export from LangGraph, import into MCP, checkpoint, rollback, diff, encrypt, sign โ€” all through a single Universal Schema.

When your agent needs to switch frameworks, its memories come with it. When a 20-step autonomous workflow derails at step 15, rewind to step 14, fix the issue, and replay. When your enterprise needs to audit agent behavior, every state transition is versioned, signed, and encrypted.

Why StateWeave?

StateWeave solves three critical problems in the AI agent ecosystem:

๐Ÿ” Debugging โ€” Agent workflows are non-deterministic. When they go wrong, you need to pause, rewind, inspect, and replay โ€” not restart. StateWeave gives you git-like version control for agent cognitive state.

๐Ÿ”’ Security โ€” Agent state contains the agent's entire cognitive history. StateWeave encrypts at rest (AES-256-GCM), signs payloads (Ed25519), strips credentials on export, and enforces compliance policies.

๐Ÿ”„ Portability โ€” Every framework has persistence, none have portability. StateWeave's Universal Schema โ€” a canonical representation of agent cognitive state โ€” lets you move state between any of 10 frameworks. One schema, N adapters, zero data loss (with explicit warnings for anything non-portable).

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  LangGraph  โ”‚     โ”‚    MCP      โ”‚     โ”‚   CrewAI    โ”‚     โ”‚   AutoGen   โ”‚
โ”‚   Adapter   โ”‚     โ”‚   Adapter   โ”‚     โ”‚   Adapter   โ”‚     โ”‚   Adapter   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚                   โ”‚                   โ”‚                   โ”‚
       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                   โ”‚
                   โ”‚                   โ”‚                           โ”‚
                   โ–ผ                   โ–ผ                           โ–ผ
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚              ๐Ÿงถ  Universal Schema v1                     โ”‚
            โ”‚                                                          โ”‚
            โ”‚  conversation_history  ยท  working_memory  ยท  goal_tree   โ”‚
            โ”‚  tool_results_cache  ยท  trust_parameters  ยท  audit_trail โ”‚
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Star topology, not mesh. N adapters, not Nยฒ translation pairs. Adding a new framework = one adapter, instant compatibility with everything else.

See it working

StateWeave demo โ€” export, import, diff, time travel, encrypt from pip install

$ pip install stateweave
$ python examples/full_demo.py

โ”โ” 1. Export from LangGraph โ”โ”
  โœ“ Exported 4 messages
  โœ“ Source framework: langgraph

โ”โ” 2. Import into MCP โ”โ”
  โœ“ Imported into mcp
  โœ“ Messages preserved: 4

โ”โ” 3. Verify Round-Trip โ”โ”
  โœ“ Zero data loss: YES

โ”โ” 4. Diff Agent States โ”โ”
  Summary: 7 added, 4 removed, 7 modified

โ”โ” 5. Time Travel โ”โ”
  โœ“ Checkpoint v1 (initial-research)
  โœ“ Checkpoint v2 (after-drug-discovery)
  โœ“ Rolled back โ†’ 4 msgs

โ”โ” 6. Encryption (AES-256-GCM) โ”โ”
  โœ“ 1,733 bytes โ†’ 1,749 bytes encrypted
  โœ“ Decrypted: 4 messages intact

โ”โ” 7. Non-Portable Warnings โ”โ”
  โœ“ No non-portable warnings (clean export)

7/7 steps passed. Everything runs from PyPI.

Try it yourself: pip install stateweave && python examples/quickstart.py (quickstart) or python examples/full_demo.py (all 7 steps)

Quick Start

Install

pip install stateweave

Use with Claude Desktop / Cursor

Add to your MCP config (~/.cursor/mcp.json or Claude Desktop settings):

{
  "mcpServers": {
    "stateweave": {
      "command": "python3",
      "args": ["-m", "stateweave.mcp_server"]
    }
  }
}

Claude and Cursor can now export, import, and diff your agent state directly.

Export an Agent's State

from stateweave import LangGraphAdapter, MCPAdapter, diff_payloads

# Set up a LangGraph agent with some state
lg = LangGraphAdapter()
lg._agents["my-agent"] = {
    "messages": [
        {"type": "human", "content": "What's the weather?"},
        {"type": "ai", "content": "It's 72ยฐF and sunny!"},
    ],
    "current_task": "weather_check",
}

# Export from LangGraph
payload = lg.export_state("my-agent")
print(f"Exported: {len(payload.cognitive_state.conversation_history)} messages")

Import into Another Framework

from stateweave import MCPAdapter

# Import into MCP
mcp_adapter = MCPAdapter()
mcp_adapter.import_state(payload)

# The agent resumes with its memories intact

Auto-Checkpoint Middleware

from stateweave.middleware import auto_checkpoint

# Simple: checkpoint every 5 steps
@auto_checkpoint(every_n_steps=5)
def run_agent(payload):
    return payload

# Smart: only checkpoint on significant state changes
@auto_checkpoint(strategy="on_significant_delta", delta_threshold=3)
def smart_agent(payload):
    return payload

# Manual: zero overhead, checkpoint when you decide
@auto_checkpoint(strategy="manual_only")
def hot_path_agent(payload):
    return payload

Migrate with Encryption

from stateweave import EncryptionFacade, MigrationEngine

# Set up encrypted migration
key = EncryptionFacade.generate_key()
engine = MigrationEngine(
    encryption=EncryptionFacade(key)
)

# Full pipeline: export โ†’ validate โ†’ encrypt โ†’ transport
result = engine.export_state(
    adapter=langgraph_adapter,
    agent_id="my-agent",
    encrypt=True,
)

# Decrypt โ†’ validate โ†’ import on the other side
engine.import_state(
    adapter=mcp_adapter,
    encrypted_data=result.encrypted_data,
    nonce=result.nonce,
)

Diff Two States

from stateweave import diff_payloads

diff = diff_payloads(state_before, state_after)
print(diff.to_report())
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# ๐Ÿ” STATEWEAVE DIFF REPORT
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
#   Changes: 5 (+2 -1 ~2)
#   [working_memory]
#     + working_memory.new_task: 'research'
#     ~ working_memory.confidence: 0.7 โ†’ 0.95

Framework Support

Framework Adapter Export Import Tier
LangGraph LangGraphAdapter โœ… โœ… ๐ŸŸข Tier 1
MCP MCPAdapter โœ… โœ… ๐ŸŸข Tier 1
CrewAI CrewAIAdapter โœ… โœ… ๐ŸŸข Tier 1
AutoGen AutoGenAdapter โœ… โœ… ๐ŸŸข Tier 1
DSPy DSPyAdapter โœ… โœ… ๐ŸŸก Tier 2
OpenAI Agents OpenAIAgentsAdapter โœ… โœ… ๐ŸŸก Tier 2
LlamaIndex LlamaIndexAdapter โœ… โœ… ๐Ÿ”ต Community
Haystack HaystackAdapter โœ… โœ… ๐Ÿ”ต Community
Letta / MemGPT LettaAdapter โœ… โœ… ๐Ÿ”ต Community
Semantic Kernel SemanticKernelAdapter โœ… โœ… ๐Ÿ”ต Community
Custom Extend StateWeaveAdapter โœ… โœ… DIY

Tier definitions: ๐ŸŸข Tier 1 = Core team maintained, guaranteed stability. ๐ŸŸก Tier 2 = Actively maintained, patches may lag. ๐Ÿ”ต Community = Best-effort, contributed by community.

MCP Server

StateWeave ships as an MCP Server โ€” any MCP-compatible AI assistant can use it directly.

Tools

Tool Description
export_agent_state Export an agent's cognitive state from any supported framework
import_agent_state Import state into a target framework with validation
diff_agent_states Compare two states and return a detailed change report

Resources

Resource URI
Universal Schema spec stateweave://schemas/v1
Migration history log stateweave://migrations/history
Live agent snapshot stateweave://agents/{id}/snapshot

Prompts

Prompt Use Case
backup_before_risky_operation Agent self-requests state backup before risky ops
migration_guide Step-by-step framework migration template

The Universal Schema

Every agent's state is represented as a StateWeavePayload:

StateWeavePayload(
    stateweave_version="0.3.4",
    source_framework="langgraph",
    exported_at=datetime,
    cognitive_state=CognitiveState(
        conversation_history=[...],   # Full message history
        working_memory={...},         # Current task state
        goal_tree={...},              # Active goals
        tool_results_cache={...},     # Cached tool outputs
        trust_parameters={...},       # Confidence scores
        long_term_memory={...},       # Persistent knowledge
        episodic_memory=[...],        # Past experiences
    ),
    metadata=AgentMetadata(
        agent_id="my-agent",
        access_policy="private",
    ),
    audit_trail=[...],               # Full operation history
    non_portable_warnings=[...],     # Explicit data loss docs
)

Security

  • AES-256-GCM authenticated encryption with unique nonce per operation
  • PBKDF2 key derivation (600K iterations, OWASP recommended)
  • Ed25519 payload signing โ€” digital signatures verify sender identity and detect tampering
  • Credential stripping โ€” API keys, tokens, and passwords are flagged as non-portable and stripped during export
  • Non-portable warnings โ€” every piece of state that can't fully transfer is explicitly documented (no silent data loss)
  • Associated data โ€” encrypt with AAD to bind ciphertext to specific agent metadata

Payload Signing

from stateweave import EncryptionFacade

# Generate a signing key pair
private_key, public_key = EncryptionFacade.generate_signing_keypair()

# Sign serialized payload
signature = EncryptionFacade.sign(payload_bytes, private_key)

# Verify on receipt
is_authentic = EncryptionFacade.verify(payload_bytes, signature, public_key)

Delta State Transport

For large state payloads, send only the changes:

from stateweave.core.delta import create_delta, apply_delta

# Create delta: only the differences
delta = create_delta(old_payload, new_payload)

# Apply delta on the receiver side
updated = apply_delta(base_payload, delta)

Agent Time Travel

Version, checkpoint, rollback, and branch agent cognitive state:

from stateweave.core.timetravel import CheckpointStore

store = CheckpointStore()

# Save a checkpoint
store.checkpoint(payload, label="before-experiment")

# View history
print(store.format_history("my-agent"))

# Roll back to a previous version
restored = store.rollback("my-agent", version=3)

# Branch from a checkpoint
store.branch("my-agent", version=3, new_agent_id="my-agent-experiment")

# Diff two versions
diff = store.diff_versions("my-agent", version_a=1, version_b=5)
print(diff.to_report())

Content-addressable storage (SHA-256), parent hash chains, delta compression between versions.

A2A Bridge

Bridge between the Agent2Agent (A2A) protocol and StateWeave. A2A defines how agents communicate โ€” StateWeave adds what agents know:

from stateweave.a2a import A2ABridge

bridge = A2ABridge()

# Package state for A2A handoff
artifact = bridge.create_transfer_artifact(payload)

# Extract state from received A2A message
extracted = bridge.extract_payload(a2a_message_parts)

# Generate AgentCard skill for capability advertisement
caps = bridge.get_agent_capabilities()
skill = caps.to_agent_card_skill()

State Merge (CRDT Foundation)

Merge state from parallel agents:

from stateweave.core.merge import merge_payloads, ConflictResolutionPolicy

result = merge_payloads(
    agent_a_state, agent_b_state,
    policy=ConflictResolutionPolicy.LAST_WRITER_WINS,
)
merged_payload = result.payload

Non-Portable State

Not everything can transfer between frameworks. StateWeave handles this honestly:

Category Example Behavior
DB connections sqlite3.Cursor โš ๏ธ Stripped, warning emitted
Credentials api_key, oauth_token ๐Ÿ”ด Stripped, CRITICAL warning
Framework internals LangGraph __channel_versions__ โš ๏ธ Stripped, warning emitted
Thread/async state threading.Lock, asyncio.Task โš ๏ธ Stripped, warning emitted
Live connections Network sockets, file handles โš ๏ธ Stripped, warning emitted

All non-portable elements appear in payload.non_portable_warnings[] with severity, reason, and remediation guidance.

Zero-Loss Translations

Framework-specific state that doesn't map to universal fields is not silently dropped โ€” it's preserved in cognitive_state.framework_specific:

# LangGraph internals survive the round-trip
payload = lg_adapter.export_state("my-thread")
print(payload.cognitive_state.framework_specific)
# {"__channel_versions__": {"messages": 5}, "checkpoint_id": "ckpt-abc"}

# Import back into LangGraph โ€” internal state is restored
target = LangGraphAdapter()
target.import_state(payload)

Three layers of state handling:

Layer Storage Round-Trip
Universal conversation_history, working_memory, etc. โœ… Fully portable
Framework-specific framework_specific dict โœ… Preserved in same-framework
Non-portable non_portable_warnings โš ๏ธ Stripped with warnings

Building a Custom Adapter

Extend StateWeaveAdapter to add support for any framework:

from stateweave.adapters.base import StateWeaveAdapter
from stateweave.schema.v1 import StateWeavePayload, AgentInfo

class MyFrameworkAdapter(StateWeaveAdapter):
    @property
    def framework_name(self) -> str:
        return "my-framework"

    def export_state(self, agent_id: str, **kwargs) -> StateWeavePayload:
        # Translate your framework's state โ†’ Universal Schema
        ...

    def import_state(self, payload: StateWeavePayload, **kwargs):
        # Translate Universal Schema โ†’ your framework's state
        ...

    def list_agents(self) -> list[AgentInfo]:
        # Return available agents
        ...

The UCE adapter_contract scanner automatically validates that all adapters correctly implement the ABC.

CLI

# Show version and available adapters
stateweave version

# Dump the Universal Schema as JSON Schema
stateweave schema -o schema.json

# Validate a payload file
stateweave validate state.json

# Export/import/diff
stateweave export -f langgraph -a my-agent -o state.json
stateweave import -f mcp --payload state.json
stateweave diff before.json after.json

# Auto-detect source framework
stateweave detect state.json

# Scan environment for installed frameworks
stateweave scan

# Time travel โ€” checkpoint, history, rollback
stateweave checkpoint state.json --label "before-experiment"
stateweave history my-agent
stateweave rollback my-agent 3 -o restored.json

# Run diagnostic health checks
stateweave doctor

# List all available adapters
stateweave adapters

# Scaffold a new adapter
stateweave generate-adapter my-framework --output-dir ./adapters

Compliance (UCE)

StateWeave enforces its own architectural standards via the Universal Compliance Engine โ€” 12 automated scanners that run on every commit:

Scanner What It Checks Mode
schema_integrity Universal Schema models have required fields BLOCK
adapter_contract All adapters implement the full ABC BLOCK
serialization_safety No raw pickle/json.dumps outside serializer BLOCK
encryption_compliance All crypto goes through EncryptionFacade BLOCK
mcp_protocol MCP server has all required tools BLOCK
import_discipline No cross-layer imports BLOCK
logger_naming All loggers use stateweave.* convention BLOCK
test_coverage_gate Minimum test file coverage ratio BLOCK
file_architecture No orphan files outside MANIFEST WARN
dependency_cycles No circular imports BLOCK
adapter_isolation Adapters cannot import across isolation boundaries BLOCK
ruff_quality Ruff formatting standards enforced BLOCK
# Run UCE locally
python scripts/uce.py

# Run in CI mode (exit 1 on failure)
python scripts/uce.py --mode=CI --json

Why Not Just Serialize to JSON Yourself?

You could โ€” and it'll work for one framework. Here's what you'd have to build:

Problem DIY JSON StateWeave
Map LangGraph's messages[] to CrewAI's task_output Write it yourself for each pair Handled by adapters
Detect credentials in state (API keys, OAuth tokens) Easy to miss โ†’ leaked secrets Auto-stripped with warnings
Validate state structure after migration Write your own schema checks Pydantic models + UCE scanners
Track what was lost during migration Hope you remember non_portable_warnings[]
Encrypt state for transport DIY crypto (dangerous) AES-256-GCM + Ed25519
Roll back if migration goes wrong No undo CheckpointStore.rollback()
Support 10 frameworks 90 translation pairs (Nยฒ) 10 adapters (N)

StateWeave exists because the translation layer between frameworks is boring, error-prone work that every team rebuilds. We built it once.

Contributing

We welcome contributions! The highest-impact way to contribute is building a new framework adapter. See Building a Custom Adapter above.

Development Setup

git clone https://github.com/GDWN-BLDR/stateweave.git
cd stateweave
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Run UCE
python scripts/uce.py

Architecture

stateweave/
โ”œโ”€โ”€ schema/        # Universal Schema (Pydantic models)
โ”œโ”€โ”€ core/          # Engine (serializer, encryption, diff, delta, timetravel, environment, doctor)
โ”œโ”€โ”€ adapters/      # Framework adapters (10 frameworks)
โ”œโ”€โ”€ a2a/           # A2A protocol bridge
โ”œโ”€โ”€ middleware/    # Auto-checkpoint middleware
โ”œโ”€โ”€ playground/    # Interactive playground (REST API + UI)
โ”œโ”€โ”€ registry/      # Schema registry (publish, search, discover)
โ”œโ”€โ”€ templates/     # Project scaffolding (create-stateweave-agent)
โ”œโ”€โ”€ mcp_server/    # MCP Server implementation
โ””โ”€โ”€ compliance/    # UCE scanners

Additional Tools

Tool Description
VS Code Extension Payload preview, diff, doctor, adapter scaffold โ€” vscode-extension/
TypeScript SDK Universal Schema types, serializer, diff โ€” sdk/typescript/
GitHub Action CI validation + PR diffs โ€” action.yml

Using StateWeave?

Add the badge to your project's README:

[![StateWeave](https://img.shields.io/badge/state-StateWeave-7c3aed)](https://github.com/GDWN-BLDR/stateweave)

StateWeave

License

Apache 2.0 โ€” use it, modify it, ship it. Patent shield included.


๐Ÿงถ StateWeave โ€” git for agent brains.

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

stateweave-0.3.5.tar.gz (119.7 kB view details)

Uploaded Source

Built Distribution

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

stateweave-0.3.5-py3-none-any.whl (153.9 kB view details)

Uploaded Python 3

File details

Details for the file stateweave-0.3.5.tar.gz.

File metadata

  • Download URL: stateweave-0.3.5.tar.gz
  • Upload date:
  • Size: 119.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stateweave-0.3.5.tar.gz
Algorithm Hash digest
SHA256 9ec89c3294538ce29cebd635ecda69ff435ee402e83d11afa3f7a10f6c5c554f
MD5 bd701784efbe79fcb6400999fe10e632
BLAKE2b-256 7051d526a8fa5e39b31ec2e516a9b149c7e76b6a38913c8f1a0f4f303c1eca3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for stateweave-0.3.5.tar.gz:

Publisher: ci.yml on GDWN-BLDR/stateweave

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

File details

Details for the file stateweave-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: stateweave-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 153.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stateweave-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 60974f9dd7a43d032805a14ff6998b22e2fb6e420aa3147c0dc6d74d6130a206
MD5 b4d3506edd30d3b524648c67377be01e
BLAKE2b-256 bf84e19e29161be1db3f2ef3f15b4ad12c349d16cd4e48aa527b1667457427a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for stateweave-0.3.5-py3-none-any.whl:

Publisher: ci.yml on GDWN-BLDR/stateweave

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