MongoDB
MongoDB state store setup
MongoDB
MongoDB for state storage and document persistence.
Installation
pip install "praisonaiagents[tools]"Docker Setup
docker run -d --name praison-mongo -p 27017:27017 mongoQuick Start
from praisonaiagents import Agent
agent = Agent(
name="Assistant",
instructions="You are a helpful assistant.",
memory={
"backend": "mongodb",
"db": "mongodb://localhost:27017/praisonai",
"session_id": "my-session"
}
)
response = agent.start("Hello!")
print(response)Connection String Format
mongodb://localhost:27017/database
mongodb://user:password@host:port/databaseTuning the connection
For the sync mongodb state store, any pymongo URI query option overrides the SDK’s default. Common examples:
?retryWrites=false— standalone MongoDB (no replica set)?maxPoolSize=10— smaller client-side connection pool?serverSelectionTimeoutMS=3000— fail faster when MongoDB is unreachable
See MongoDB State Store → Tuning the connection for the full default table.
Environment Variables
export PRAISON_STATE_URL="mongodb://localhost:27017/praisonai"import os
from praisonaiagents import Agent
agent = Agent(
name="Assistant",
memory={"db": os.getenv("PRAISON_STATE_URL")}
)CLI
# Validate connection
praisonai persistence doctor \
--state-url "mongodb://localhost:27017/praisonai"See also
- MongoDB State Store — hash / TTL / keys examples and the async (
motor) backend