JSON for Agent

Kern supports using local JSON files as a storage backend for Agents using the JsonDb class.

Usage

1"""Run `uv pip install openai` to install dependencies."""
2
3from kern.agent import Agent
4from kern.db.json import JsonDb
5from kern.models.openai import OpenAIResponses
6from kern.tools.hackernews import HackerNewsTools
7
8# Setup the JSON database
9db = JsonDb(db_path="tmp/json_db")
10
11agent = Agent(
12 model=OpenAIResponses(id="gpt-5.2"),
13 db=db,
14 tools=[HackerNewsTools()],
15 add_history_to_context=True,
16)
17agent.print_response("How many people live in Canada?")
18agent.print_response("What is their national anthem called?")

Params

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
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).
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.