Singlestore for Team

Kern supports using Singlestore as a storage backend for Teams using the SingleStoreDb class.

Usage

Obtain the credentials for Singlestore from here

1"""
2Run: `uv pip install openai newspaper4k lxml_html_clean kern-ai` to install the dependencies
3"""
4from os import getenv
5from typing import List
6
7from kern.agent import Agent
8from kern.db.singlestore.singlestore import SingleStoreDb
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# Configure SingleStore DB connection
16USERNAME = getenv("SINGLESTORE_USERNAME")
17PASSWORD = getenv("SINGLESTORE_PASSWORD")
18HOST = getenv("SINGLESTORE_HOST")
19PORT = getenv("SINGLESTORE_PORT")
20DATABASE = getenv("SINGLESTORE_DATABASE")
21SSL_CERT = getenv("SINGLESTORE_SSL_CERT", None)
22
23db_url = (
24 f"mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}?charset=utf8mb4"
25)
26db = SingleStoreDb(db_url=db_url)
27
28class Article(BaseModel):
29 title: str
30 summary: str
31 reference_links: List[str]
32
33hn_researcher = Agent(
34 name="HackerNews Researcher",
35 model=OpenAIResponses(id="gpt-5.2"),
36 role="Gets top stories from hackernews.",
37 tools=[HackerNewsTools()],
38)
39
40web_searcher = Agent(
41 name="Web Searcher",
42 model=OpenAIResponses(id="gpt-5.2"),
43 role="Searches the web for information on a topic",
44 tools=[HackerNewsTools()],
45 add_datetime_to_context=True,
46)
47
48hn_team = Team(
49 name="HackerNews Team",
50 model=OpenAIResponses(id="gpt-5.2"),
51 members=[hn_researcher, web_searcher],
52 db=db,
53 instructions=[
54 "First, search hackernews for what the user is asking about.",
55 "Then, ask the web searcher to search for each story to get more information.",
56 "Finally, provide a thoughtful and engaging summary.",
57 ],
58 output_schema=Article,
59 markdown=True,
60 show_members_responses=True,
61)
62
63hn_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_engineOptional[Engine]-The SQLAlchemy database engine to use.
db_schemaOptional[str]-The database schema to use.
db_urlOptional[str]-The database URL to connect to.
session_tableOptional[str]-Name of the table to store Agent, Team and Workflow sessions.
memory_tableOptional[str]-Name of the table to store memories.
metrics_tableOptional[str]-Name of the table to store metrics.
eval_tableOptional[str]-Name of the table to store evaluation runs data.
knowledge_tableOptional[str]-Name of the table to store knowledge content.
traces_tableOptional[str]-Name of the table to store traces.
spans_tableOptional[str]-Name of the table to store spans.