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."""23from kern.agent import Agent4from kern.db.json import JsonDb5from kern.models.openai import OpenAIResponses6from kern.tools.hackernews import HackerNewsTools78# Setup the JSON database9db = JsonDb(db_path="tmp/json_db")1011agent = 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
| 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. |
traces_table | Optional[str] | - | Name of the JSON file to store traces. |
spans_table | Optional[str] | - | Name of the JSON file to store spans. |