MongoAgentStorage class.
Usage
You need to provide eitherdb_url or client. The following example uses db_url.
storage.py
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
MongoAgentStorage class.
db_url or client. The following example uses db_url.
from phi.storage.agent.mongodb import MongoAgentStorage
db_url = "mongodb://ai:ai@localhost:27017/phi"
# Create a storage backend using the Mongo database
storage = MongoAgentStorage(
# store sessions in the agent_sessions collection
collection_name="agent_sessions",
db_url=db_url,
)
# Add storage to the Agent
agent = Agent(storage=storage)
| Parameter | Type | Default | Description |
|---|---|---|---|
collection_name | str | - | Name of the collection to be used. |
db_url | Optional[str] | None | Database URL, if provided. |
db_name | str | "phi" | Database Name. |
client | Optional[MongoClient] | None | MongoDB client, if provided. |
Was this page helpful?