Firestore for Team

Kern supports using Firestore as a storage backend for Teams 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.

1"""
2Run: `uv pip install openai newspaper4k lxml_html_clean kern-ai` to install the dependencies
3"""
4
5from typing import List
6
7from kern.agent import Agent
8from kern.db.firestore import FirestoreDb
9from kern.models.openai import OpenAIResponses
10from kern.team import Team
11from kern.tools.hackernews import HackerNewsTools
12from kern.tools.hackernews import HackerNewsTools
13from pydantic import BaseModel
14
15# Setup the Firestore database
16PROJECT_ID = "kern-os-test" # Use your project ID here
17db = FirestoreDb(project_id=PROJECT_ID)
18
19class Article(BaseModel):
20 title: str
21 summary: str
22 reference_links: List[str]
23
24hn_researcher = Agent(
25 name="HackerNews Researcher",
26 model=OpenAIResponses(id="gpt-5.2"),
27 role="Gets top stories from hackernews.",
28 tools=[HackerNewsTools()],
29)
30
31web_searcher = Agent(
32 name="Web Searcher",
33 model=OpenAIResponses(id="gpt-5.2"),
34 role="Searches the web for information on a topic",
35 tools=[HackerNewsTools()],
36 add_datetime_to_context=True,
37)
38
39hn_team = Team(
40 name="HackerNews Team",
41 model=OpenAIResponses(id="gpt-5.2"),
42 members=[hn_researcher, web_searcher],
43 db=db,
44 instructions=[
45 "First, search hackernews for what the user is asking about.",
46 "Then, ask the web searcher to search for each story to get more information.",
47 "Finally, provide a thoughtful and engaging summary.",
48 ],
49 output_schema=Article,
50 markdown=True,
51 show_members_responses=True,
52)
53
54hn_team.print_response("Write an article about the top 2 stories on hackernews")

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.