JsonDb
Store sessions, memories, metrics, knowledge, evals, and traces in local JSON files.
JsonDb is a class that implements the Db interface using JSON files as the backend storage system. It provides simple, file-based storage with each table stored as a separate JSON file.
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | Database ID. Derived deterministically from database path when omitted. |
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). |
runs_table | Optional[str] | None | Storage name for individual runs. Defaults to agno_runs, or <session_table>_runs when a custom session name is supplied. |
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. |
Methods
upsert_sessions
Upsert multiple sessions in one method call.
Parameters:
sessions(List[Session]): List of sessions to upsertdeserialize(Optional[bool]): Whether to deserialize the sessions. Defaults toTruepreserve_updated_at(bool): Request preservation of the sessions' existingupdated_attimestamps; see adapter limitations below. Defaults toFalse
Returns: List[Union[Session, Dict[str, Any]]]
upsert_memories
Upsert multiple memories in one method call.
Parameters:
memories(List[UserMemory]): List of memories to upsertdeserialize(Optional[bool]): Whether to deserialize the memories. Defaults toTruepreserve_updated_at(bool): Request preservation of the memories' existingupdated_attimestamps; see adapter limitations below. Defaults toFalse
Returns: List[Union[UserMemory, Dict[str, Any]]]
Timestamp preservation by adapter
JsonDb, GcsJsonDb, FirestoreDb, RedisDb, DynamoDb, and InMemoryDb accept preserve_updated_at but do not forward it to their individual upserts. Their bulk methods replace timestamps even when it is True.
PostgresDb, SingleStoreDb, and ValkeyDb honor the flag. MySQLDb, SqliteDb, and MongoDb honor it on their optimized bulk path; their per-record fallback paths do not forward it. Verify timestamps when a migration depends on preserving them.
In the current implementation, JsonDb.upsert_sessions() and JsonDb.upsert_memories() declare preserve_updated_at, but the JSON backend does not forward it to individual upserts. JsonDb does not preserve supplied updated_at values when this argument is True.