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 Agent2from kern.db.firestore import FirestoreDb3from kern.tools.hackernews import HackerNewsTools45PROJECT_ID = "kern-os-test" # Use your project ID here67# Setup the Firestore database8db = FirestoreDb(project_id=PROJECT_ID)910agent = Agent(11 db=db,12 tools=[HackerNewsTools()],13 add_history_to_context=True,14)1516agent.print_response("How many people live in Canada?")17agent.print_response("What is their national anthem called?")Prerequisites
- Ensure your gcloud project is enabled with Firestore. Reference Firestore documentation
- Install dependencies:
uv pip install openai google-cloud-firestore kern-ai - Make sure your gcloud project is set up and you have the necessary permissions to access Firestore
Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | The ID of the database instance. UUID by default. |
db_client | Optional[Client] | - | The Firestore client to use. |
project_id | Optional[str] | - | The GCP project ID for Firestore. |
session_collection | Optional[str] | - | Name of the collection to store sessions. |
memory_collection | Optional[str] | - | Name of the collection to store memories. |
metrics_collection | Optional[str] | - | Name of the collection to store metrics. |
eval_collection | Optional[str] | - | Name of the collection to store evaluation runs. |
knowledge_collection | Optional[str] | - | Name of the collection to store knowledge documents. |
traces_collection | Optional[str] | - | Name of the collection to store traces. |
spans_collection | Optional[str] | - | Name of the collection to store spans. |