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
gcs_for_agent.py
import uuid
import google.auth
from agno.agent import Agent
from agno.db.gcs_json import GcsJsonDb
# Obtain the default credentials and project id from your gcloud CLI session.
credentials, project_id = google.auth.default()
# Generate a unique bucket name using a base name and a UUID4 suffix.
base_bucket_name = "example-gcs-bucket"
unique_bucket_name = f"{base_bucket_name}-{uuid.uuid4().hex[:12]}"
print(f"Using bucket: {unique_bucket_name}")
# Initialize GCSJsonDb with explicit credentials, unique bucket name, and project.
db = GcsJsonDb(
bucket_name=unique_bucket_name,
prefix="agent/",
project=project_id,
credentials=credentials,
)
# Setup your Agent with the Database
agent = Agent(db=db)
Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | The ID of the database instance. UUID by default. |
bucket_name | str | - | Name of the GCS bucket where JSON files will be stored. |
prefix | Optional[str] | - | Path prefix for organizing files in the bucket. Defaults to "agno/". |
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 user 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. |
project | Optional[str] | - | GCP project ID. If None, uses default project. |
credentials | Optional[Any] | - | GCP credentials. If None, uses default credentials. |