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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crewai_persistence_mongodb-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

crewai_persistence_mongodb-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file crewai_persistence_mongodb-0.1.0.tar.gz.

File metadata

File hashes

Hashes for crewai_persistence_mongodb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e8e784e36c5d44a28d46089a90c01ed397587deaaffdc9c89d1061030a5abc38
MD5 635b9973ee218a72ae1ca8d824bd6cb1
BLAKE2b-256 8dcce69e93094c835a86f60bc674e76e0ad9c9975ec9c5531cac7f41022aff15

See more details on using hashes here.

File details

Details for the file crewai_persistence_mongodb-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for crewai_persistence_mongodb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79ec0799a929f5b79681706aad168062d051d575c4b970f305c3864086b22975
MD5 abd6dbb4294724bba135fd2bb48075fb
BLAKE2b-256 14a233c860459294c240181e69ea7d7337632712965085c55b1697fefffd116e

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 Sentry Error logging StatusPage Status page