Firestore for Agent

Kern supports using Firestore as a storage backend for Agents using the FirestoreDb class.

Usage

You need to provide a project_id parameter to the FirestoreDb class. Firestore will connect automatically using your Google Cloud credentials.

1from kern.agent import Agent
2from kern.db.firestore import FirestoreDb
3from kern.tools.hackernews import HackerNewsTools
4
5PROJECT_ID = "kern-os-test" # Use your project ID here
6
7# Setup the Firestore database
8db = FirestoreDb(project_id=PROJECT_ID)
9
10agent = Agent(
11 db=db,
12 tools=[HackerNewsTools()],
13 add_history_to_context=True,
14)
15
16agent.print_response("How many people live in Canada?")
17agent.print_response("What is their national anthem called?")

Prerequisites

  1. Ensure your gcloud project is enabled with Firestore. Reference Firestore documentation
  2. Install dependencies: uv pip install openai google-cloud-firestore kern-ai
  3. Make sure your gcloud project is set up and you have the necessary permissions to access Firestore

Params

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
db_clientOptional[Client]-The Firestore client to use.
project_idOptional[str]-The GCP project ID for Firestore.
session_collectionOptional[str]-Name of the collection to store sessions.
memory_collectionOptional[str]-Name of the collection to store memories.
metrics_collectionOptional[str]-Name of the collection to store metrics.
eval_collectionOptional[str]-Name of the collection to store evaluation runs.
knowledge_collectionOptional[str]-Name of the collection to store knowledge documents.
traces_collectionOptional[str]-Name of the collection to store traces.
spans_collectionOptional[str]-Name of the collection to store spans.