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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crewai_persistence_mongodb-0.1.0.tar.gz.
File metadata
- Download URL: crewai_persistence_mongodb-0.1.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8e784e36c5d44a28d46089a90c01ed397587deaaffdc9c89d1061030a5abc38
|
|
| MD5 |
635b9973ee218a72ae1ca8d824bd6cb1
|
|
| BLAKE2b-256 |
8dcce69e93094c835a86f60bc674e76e0ad9c9975ec9c5531cac7f41022aff15
|
File details
Details for the file crewai_persistence_mongodb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: crewai_persistence_mongodb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79ec0799a929f5b79681706aad168062d051d575c4b970f305c3864086b22975
|
|
| MD5 |
abd6dbb4294724bba135fd2bb48075fb
|
|
| BLAKE2b-256 |
14a233c860459294c240181e69ea7d7337632712965085c55b1697fefffd116e
|