Usage

JSON for Agent

Store agent sessions and run history in local JSON files with JsonDb.

JsonDb stores an Agent's sessions and run history in local JSON files.

Usage

Start in a virtual environment and set the model key before running the example.

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.

export OPENAI_API_KEY=sk-***

Install the openai and ddgs packages:

uv pip install agno openai ddgs
json_for_agent.py
from agno.agent import Agent
from agno.db.json import JsonDb
from agno.models.openai import OpenAIChat
from agno.tools.websearch import WebSearchTools

db = JsonDb(db_path="tmp/json_db")

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,
)
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?")

Parameters

ParameterTypeDefaultDescription
idOptional[str]-Database ID. Derived deterministically from database path when omitted.
db_pathOptional[str]-Path to the directory where JSON files will be stored.
session_tableOptional[str]-Name of the JSON file to store sessions (without .json extension).
runs_tableOptional[str]NoneStorage name for individual runs. Defaults to agno_runs, or <session_table>_runs when a custom session name is supplied.
memory_tableOptional[str]-Name of the JSON file to store memories.
metrics_tableOptional[str]-Name of the JSON file to store metrics.
eval_tableOptional[str]-Name of the JSON file to store evaluation runs.
knowledge_tableOptional[str]-Name of the JSON file to store knowledge content.
traces_tableOptional[str]-Name of the JSON file to store traces.
spans_tableOptional[str]-Name of the JSON file to store spans.

Run the Example

Save the code as json_for_agent.py, complete the prerequisites above, then run:

python json_for_agent.py