Skip to main content

crewai-persistence-dynamodb

Amazon DynamoDB persistence backend for CrewAI Flows. Persists flow state across runs, with optional built-in message pruning via agentstate-reducer.

Implements CrewAI's FlowPersistence interface, so it drops straight into the @persist decorator.

Installation

pip install crewai-persistence-dynamodb
# with message pruning:
pip install "crewai-persistence-dynamodb[reducer]"

Requires Python 3.10–3.13 (matches CrewAI's supported range).

Usage

from crewai.flow.flow import Flow, start
from crewai.flow.persistence import persist
from crewai_persistence_dynamodb import DynamoDBFlowPersistence

backend = DynamoDBFlowPersistence(table_name="crewai-flows", region_name="us-east-1")

@persist(backend)
class MyFlow(Flow[MyState]):
    @start()
    def begin(self):
        self.state.counter += 1

The table is auto-created (on-demand billing) if it doesn't exist, keyed by flow_uuid.

With message pruning (conversational flows)

from agentstate_reducer import MessageReducer
from crewai_persistence_dynamodb import DynamoDBFlowPersistence

backend = DynamoDBFlowPersistence(
    table_name="crewai-flows",
    reducer=MessageReducer(min_messages=10, max_messages=20),
    messages_key="messages",   # state field holding the message list
)

API

DynamoDBFlowPersistence(table_name, *, region_name=None, boto_session=None, endpoint_url=None, ttl_seconds=None, reducer=None, messages_key="messages")

Parameter Description
table_name DynamoDB table (auto-created if absent)
region_name AWS region
boto_session Optional pre-built boto3.Session
endpoint_url Custom endpoint (DynamoDB Local / LocalStack)
ttl_seconds If set, flow state expires automatically via a ttl attribute
reducer Optional MessageReducer to prune messages_key before each save
messages_key State field holding the message list (default "messages")

Authentication

Standard boto3 credential resolution — env vars, ~/.aws/credentials, AWS_PROFILE, SSO, or IAM roles. Needs permission to create the table (if absent) and read/write items.

Data model

One item per flow, keyed by flow_uuid. The flow state is stored as a JSON string in a data attribute; method_name and saved_at are stored alongside as metadata. Each save upserts, so load_state returns the latest state.

License

MIT

Long-term memory via on_prune (agentstate-reducer >= 0.4.0)

Messages pruned from the flow state are exactly the ones leaving the model's view. The persistence layer forwards a memory namespace to the reducer, and any on_prune hook receives (pruned_messages, namespace) — so pruned turns can flow straight into CrewAI's unified Memory (or any store), with no package coupling:

from agentstate_reducer import MessageReducer, ReducerConfig, Background
from crewai.memory import Memory

memory = Memory(storage=...)                       # e.g. crewai-memory-dynamodb

def remember(pruned, namespace):
    text = "\n".join(m["content"] for m in pruned)
    memory.remember_many(memory.extract_memories(text), scope=namespace)   # LLM calls -> run off-path

reducer = MessageReducer(config=ReducerConfig(max_messages=20, on_prune=[Background(remember)]))

class SupportState(BaseModel):
    id: str = ""
    memory_namespace: str = "/user/kamal"          # long-term scope: the USER, not the flow
    messages: list = []

@persist(DynamoDBFlowPersistence(..., reducer=reducer))
class SupportFlow(Flow[SupportState]):
    ...

The persistence layer reads memory_namespace (or whatever ReducerConfig.namespace_key names) from the flow state on every save_state and passes it through untouched. If the state never sets it, the namespace falls back to "/flow/<flow_uuid>". Each pruned message reaches the hooks once.

Metadata

Release files for crewai_persistence_dynamodb 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crewai_persistence_dynamodb 0.2.1
File Size Uploaded
crewai_persistence_dynamodb-0.2.1.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crewai_persistence_dynamodb 0.2.1
File Interpreter ABI Platform
crewai_persistence_dynamodb-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / crewai_persistence_dynamodb-0.2.1.tar.gz

Download URL crewai_persistence_dynamodb-0.2.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
eba1550604cf18d5a8f6e84078239484f8970ba8c17d392bcc9b320d04472ed3
BLAKE2b-256 checksum
How to use checksums
cfaafdab2a6c47a5b73a2807e77f19415bc70214eb147630419cec72a54fdd81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / crewai_persistence_dynamodb-0.2.1-py3-none-any.whl

Download URL crewai_persistence_dynamodb-0.2.1-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e27f9b53e0d9033ba210aa2d55042f78a5717088100a10030513d1e1dff7ca7e
BLAKE2b-256 checksum
How to use checksums
320bb5e03ed2a51828a1d4c2caa104a8e2b814d8c8bf0eed1efe3e3450019a29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page