Agno supports using MongoDB as a storage backend for Agents using the MongoDbAgentStorage class.

Usage

You need to provide either db_url or client. The following example uses db_url.

storage.py
from agno.storage.agent.mongodb import MongoDbAgentStorage

db_url = "mongodb://ai:ai@localhost:27017/agno"

# Create a storage backend using the Mongo database
storage = MongoDbAgentStorage(
    # store sessions in the agent_sessions collection
    collection_name="agent_sessions",
    db_url=db_url,
)

# Add storage to the Agent
agent = Agent(storage=storage)

Params

ParameterTypeDefaultDescription
collection_namestr-Name of the collection to be used.
db_urlOptional[str]NoneDatabase URL, if provided.
db_namestr"agno"Database Name.
clientOptional[MongoClient]NoneMongoDB client, if provided.

Developer Resources