MongoDB

MongoDB state store setup

MongoDB

MongoDB for state storage and document persistence.

Installation

bash
pip install "praisonaiagents[tools]"

Docker Setup

bash
docker run -d --name praison-mongo -p 27017:27017 mongo

Quick Start

python
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/database

Tuning 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

bash
export PRAISON_STATE_URL="mongodb://localhost:27017/praisonai"
python
import os
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    memory={"db": os.getenv("PRAISON_STATE_URL")}
)

CLI

bash
# Validate connection
praisonai persistence doctor \
    --state-url "mongodb://localhost:27017/praisonai"

See also