Firestore for Workflows

Kern supports using Firestore as a storage backend for Workflows 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.models.openai import OpenAIResponses
4from kern.team import Team
5from kern.tools.hackernews import HackerNewsTools
6from kern.tools.hackernews import HackerNewsTools
7from kern.workflow.step import Step
8from kern.workflow.workflow import Workflow
9
10PROJECT_ID = "kern-os-test" # Use your project ID here
11
12# Setup the Firestore database
13db = FirestoreDb(project_id=PROJECT_ID)
14
15# Define agents
16hackernews_agent = Agent(
17 name="Hackernews Agent",
18 model=OpenAIResponses(id="gpt-5.2"),
19 tools=[HackerNewsTools()],
20 role="Extract key insights and content from Hackernews posts",
21)
22web_agent = Agent(
23 name="Web Agent",
24 model=OpenAIResponses(id="gpt-5.2"),
25 tools=[HackerNewsTools()],
26 role="Search the web for the latest news and trends",
27)
28
29# Define research team for complex analysis
30research_team = Team(
31 name="Research Team",
32 members=[hackernews_agent, web_agent],
33 instructions="Research tech topics from Hackernews and the web",
34)
35
36content_planner = Agent(
37 name="Content Planner",
38 model=OpenAIResponses(id="gpt-5.2"),
39 instructions=[
40 "Plan a content schedule over 4 weeks for the provided topic and research content",
41 "Ensure that I have posts for 3 posts per week",
42 ],
43)
44
45# Define steps
46research_step = Step(
47 name="Research Step",
48 team=research_team,
49)
50
51content_planning_step = Step(
52 name="Content Planning Step",
53 agent=content_planner,
54)
55
56# Create and use workflow
57if __name__ == "__main__":
58 content_creation_workflow = Workflow(
59 name="Content Creation Workflow",
60 description="Automated content creation from blog posts to social media",
61 db=db,
62 steps=[research_step, content_planning_step],
63 )
64 content_creation_workflow.print_response(
65 input="AI trends in 2024",
66 markdown=True,
67 )

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.