Skip to main content

Cross-framework cognitive state serializer for AI agents

Project description

๐Ÿงถ StateWeave

Your AI agent switches frameworks. Its memories come with it.

PyPI CI License Python


StateWeave is a cross-framework cognitive state serializer for AI agents. It lets agents migrate between LangGraph, MCP, CrewAI, and AutoGen while preserving their accumulated knowledge โ€” conversation history, working memory, goals, tool results, and trust parameters.

No more rebuilding agent state from scratch when switching frameworks. No more vendor lock-in for your agent's brain.

Why StateWeave?

Every time you move an agent between frameworks, you lose everything it learned. StateWeave solves this with a Universal Schema โ€” a canonical representation of agent cognitive state that all frameworks translate to and from. 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.

Quick Start

Install

pip install stateweave

Export an Agent's State

from stateweave import LangGraphAdapter, StateWeaveSerializer

# Export from LangGraph
adapter = LangGraphAdapter(checkpointer=my_checkpointer)
payload = adapter.export_state("my-thread-id")

# Serialize for transport
serializer = StateWeaveSerializer()
raw_bytes = serializer.dumps(payload)

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

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 Status
LangGraph LangGraphAdapter โœ… โœ… Stable
MCP MCPAdapter โœ… โœ… Stable
CrewAI CrewAIAdapter โœ… โœ… Stable
AutoGen AutoGenAdapter โœ… โœ… Stable
Letta โ€” โ€” โ€” Planned
Custom Extend StateWeaveAdapter โœ… โœ… DIY

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.1.0",
    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)
  • 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

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.

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

Compliance (UCE)

StateWeave enforces its own architectural standards via the Universal Compliance Engine โ€” 10 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
# Run UCE locally
python scripts/uce.py

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

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, migration, portability)
โ”œโ”€โ”€ adapters/      # Framework adapters (LangGraph, MCP, CrewAI, AutoGen)
โ”œโ”€โ”€ mcp_server/    # MCP Server implementation
โ””โ”€โ”€ compliance/    # UCE scanners

License

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


๐Ÿงถ StateWeave โ€” Because your agent's memories shouldn't be locked to one framework.

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.2.0.tar.gz (75.6 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.2.0-py3-none-any.whl (104.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stateweave-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4049a0db4215c0abadc3ea6aa2704d5a3d4be040c45168850b9bceffacc6f7e6
MD5 357330237bed3d690fa2278f138e3dbd
BLAKE2b-256 8a1af9d4d6db101e863e35eb3f4137dc117e42c4b4ce7d20e7ad9260a6c9ae85

See more details on using hashes here.

Provenance

The following attestation bundles were made for stateweave-0.2.0.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: stateweave-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 104.6 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6368a8942cd3f904d55d9f5172308a28f74b4c73c7ea16556223c8f5f09e98f
MD5 5cbb0bb22f21a80cb0ff13d6baf63833
BLAKE2b-256 923cbf9d0a249fcca72bee63851e93f0792fcfdb9e10b4633b23d75ab133c871

See more details on using hashes here.

Provenance

The following attestation bundles were made for stateweave-0.2.0-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