JsonDb stores a Team’s sessions and run history in local JSON files.
Usage
Install theopenai and ddgs packages:
uv pip install openai ddgs
json_for_team.py
from typing import List
from agno.agent import Agent
from agno.db.json import JsonDb
from agno.models.openai import OpenAIChat
from agno.team import Team
from agno.tools.hackernews import HackerNewsTools
from agno.tools.websearch import WebSearchTools
from pydantic import BaseModel
db = JsonDb(db_path="tmp/json_db")
class Article(BaseModel):
title: str
summary: str
reference_links: List[str]
hn_researcher = Agent(
name="HackerNews Researcher",
model=OpenAIChat("gpt-4o"),
role="Gets top stories from HackerNews.",
tools=[HackerNewsTools()],
)
web_searcher = Agent(
name="Web Searcher",
model=OpenAIChat("gpt-4o"),
role="Searches the web for information on a topic",
tools=[WebSearchTools()],
add_datetime_to_context=True,
)
hn_team = Team(
name="HackerNews Team",
model=OpenAIChat("gpt-4o"),
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, summarize each story and include its reference links.",
],
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_path | Optional[str] | - | Path to the directory where JSON files will be stored. |
session_table | Optional[str] | - | Name of the JSON file to store sessions (without .json extension). |
memory_table | Optional[str] | - | Name of the JSON file to store memories. |
metrics_table | Optional[str] | - | Name of the JSON file to store metrics. |
eval_table | Optional[str] | - | Name of the JSON file to store evaluation runs. |
knowledge_table | Optional[str] | - | Name of the JSON file to store knowledge content. |
culture_table | Optional[str] | - | Name of the JSON file to store cultural knowledge. |
traces_table | Optional[str] | - | Name of the JSON file to store traces. |
spans_table | Optional[str] | - | Name of the JSON file to store spans. |