Skip to main content

crewai-persistence-mongodb

MongoDB persistence backend for CrewAI Flows. Persists flow state across runs, with optional built-in message pruning via agentstate-reducer. Implements CrewAI's FlowPersistence interface.

Installation

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

Requires Python 3.10–3.13 and a reachable MongoDB (local, Atlas, self-hosted).

Usage

from crewai.flow.flow import Flow, start
from crewai.flow.persistence import persist
from crewai_persistence_mongodb import MongoDBFlowPersistence

backend = MongoDBFlowPersistence(connection_string="mongodb://127.0.0.1:27017/")

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

With message pruning:

from agentstate_reducer import MessageReducer
backend = MongoDBFlowPersistence(
    connection_string="mongodb://127.0.0.1:27017/",
    reducer=MessageReducer(min_messages=10, max_messages=20),
    messages_key="messages",
)

API

MongoDBFlowPersistence(*, connection_string="mongodb://127.0.0.1:27017/", database_name="crewai_flows", collection_name="flow_states", client=None, reducer=None, messages_key="messages")

Parameter Description
connection_string MongoDB URI (local / Atlas mongodb+srv://…)
database_name / collection_name where flow states live
client optional pre-built pymongo.MongoClient
reducer optional MessageReducer to prune messages_key before save
messages_key state field holding the message list (default "messages")

Data model

One document per flow, keyed by flow_uuid (unique index); the flow state is stored in a data field, with method_name and saved_at alongside. Each save upserts, so load_state returns the latest.

License

MIT

Metadata

Release files for crewai_persistence_mongodb 0.1.0

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_mongodb 0.1.0
File Size Uploaded
crewai_persistence_mongodb-0.1.0.tar.gz 3.5 kB Details

Built distribution (wheel)

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

Total release size: 7.1 kB

Release files / crewai_persistence_mongodb-0.1.0.tar.gz

Download URL crewai_persistence_mongodb-0.1.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e8e784e36c5d44a28d46089a90c01ed397587deaaffdc9c89d1061030a5abc38
BLAKE2b-256 checksum
How to use checksums
8dcce69e93094c835a86f60bc674e76e0ad9c9975ec9c5531cac7f41022aff15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / crewai_persistence_mongodb-0.1.0-py3-none-any.whl

Download URL crewai_persistence_mongodb-0.1.0-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79ec0799a929f5b79681706aad168062d051d575c4b970f305c3864086b22975
BLAKE2b-256 checksum
How to use checksums
14a233c860459294c240181e69ea7d7337632712965085c55b1697fefffd116e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.0 This release

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