MongoDb stores a Team’s sessions and run history in MongoDB.
Usage
Provide eitherdb_url or db_client. The default database name is agno; set db_name to use another database. The following example uses db_url.
Install the agno, pymongo, openai, and ddgs packages:
uv pip install agno pymongo openai ddgs
Run MongoDB
Install Docker Desktop, then start MongoDB on port27017:
docker run -d \
--name local-mongo \
-p 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=mongoadmin \
-e MONGO_INITDB_ROOT_PASSWORD=secret \
mongo
mongodb_for_team.py
from typing import List
from agno.agent import Agent
from agno.db.mongo import MongoDb
from agno.models.openai import OpenAIResponses
from agno.team import Team
from agno.tools.hackernews import HackerNewsTools
from agno.tools.websearch import WebSearchTools
from pydantic import BaseModel
db_url = "mongodb://mongoadmin:secret@localhost:27017"
db = MongoDb(db_url=db_url)
class Article(BaseModel):
title: str
summary: str
reference_links: List[str]
hn_researcher = Agent(
name="HackerNews Researcher",
model=OpenAIResponses(id="gpt-5.2"),
role="Gets top stories from HackerNews.",
tools=[HackerNewsTools()],
)
web_searcher = Agent(
name="Web Searcher",
model=OpenAIResponses(id="gpt-5.2"),
role="Searches the web for information on a topic",
tools=[WebSearchTools()],
add_datetime_to_context=True,
)
hn_team = Team(
name="HackerNews Team",
model=OpenAIResponses(id="gpt-5.2"),
members=[hn_researcher, web_searcher],
db=db,
instructions=[
"First, search HackerNews for what the user is asking about.",
"Then, ask the web searcher to search for each story to get more information.",
"Finally, provide a thoughtful and engaging summary.",
],
output_schema=Article,
markdown=True,
show_members_responses=True,
)
hn_team.print_response("Write an article about the top 2 stories on HackerNews")
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | The ID of the database instance. UUID by default. |
db_client | Optional[MongoClient] | - | The MongoDB client to use. |
db_name | Optional[str] | - | The name of the database to use. |
db_url | Optional[str] | - | The database URL to connect to. |
session_collection | Optional[str] | - | Name of the collection to store sessions. |
memory_collection | Optional[str] | - | Name of the collection to store memories. |
metrics_collection | Optional[str] | - | Name of the collection to store metrics. |
eval_collection | Optional[str] | - | Name of the collection to store evaluation runs. |
knowledge_collection | Optional[str] | - | Name of the collection to store knowledge documents. |
culture_collection | Optional[str] | - | Name of the collection to store cultural knowledge. |
traces_collection | Optional[str] | - | Name of the collection to store traces. |
spans_collection | Optional[str] | - | Name of the collection to store spans. |
schedules_collection | Optional[str] | - | Name of the collection to store cron schedules. |
schedule_runs_collection | Optional[str] | - | Name of the collection to store schedule run history. |
learnings_collection | Optional[str] | - | Name of the collection to store learnings. |