json_for_agent.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run the example
Save the code above as
json_for_agent.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
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.
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?")
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno ddgs openai
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run the example
json_for_agent.py, then run:python json_for_agent.py
Was this page helpful?