JSON files as database, on Google Cloud Storage (GCS)

Use Google Cloud Storage for JSON-based agent session storage.

Kern supports using Google Cloud Storage (GCS) as a database with the GcsJsonDb class. Session data will be stored as JSON blobs in a GCS bucket.

You can get started with GCS following their Get Started guide.

Usage

1import uuid
2import google.auth
3from kern.agent import Agent
4from kern.db.gcs_json import GcsJsonDb
5
6# Obtain the default credentials and project id from your gcloud CLI session.
7credentials, project_id = google.auth.default()
8
9# Generate a unique bucket name using a base name and a UUID4 suffix.
10base_bucket_name = "example-gcs-bucket"
11unique_bucket_name = f"{base_bucket_name}-{uuid.uuid4().hex[:12]}"
12print(f"Using bucket: {unique_bucket_name}")
13
14# Initialize GCSJsonDb with explicit credentials, unique bucket name, and project.
15db = GcsJsonDb(
16 bucket_name=unique_bucket_name,
17 prefix="agent/",
18 project=project_id,
19 credentials=credentials,
20)
21
22# Setup your Agent with the Database
23agent = Agent(db=db)

Params

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
bucket_namestr-Name of the GCS bucket where JSON files will be stored.
prefixOptional[str]-Path prefix for organizing files in the bucket. Defaults to "kern/".
session_tableOptional[str]-Name of the JSON file to store sessions (without .json extension).
memory_tableOptional[str]-Name of the JSON file to store user 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.
projectOptional[str]-GCP project ID. If None, uses default project.
credentialsOptional[Any]-GCP credentials. If None, uses default credentials.

See the full example here.