JSON for Agent
Use JSON files as the database for an Agent.
Use JSON files as the database for an Agent. Useful for simple demos where performance is not critical.
"""
Use JSON files as the database for an Agent.
Useful for simple demos where performance is not critical.
Run `uv pip install ddgs openai` to install dependencies."""
from agno.agent import Agent
from agno.db.json import JsonDb
from agno.models.openai import OpenAIChat
from agno.tools.websearch import WebSearchTools
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = JsonDb(db_path="tmp/json_db")
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=OpenAIChat(id="gpt-5.2"),
db=db,
session_id="session_storage",
tools=[WebSearchTools()],
add_history_to_context=True,
num_history_runs=3,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
agent.print_response("How many people live in France?")
agent.print_response("What is their national anthem called?")
agent.print_response("What have we been talking about?")Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno ddgs openaiExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Run the example
Save the code above as json_for_agent.py, then run:
python json_for_agent.pyFull source: cookbook/06_storage/json_db/json_for_agent.py