MySQL for Team

Kern supports using MySQL as a storage backend for Teams using the MySQLDb class.

Usage

Run MySQL

Install docker desktop and run MySQL on port 3306 using:

1docker run -d \
2 --name mysql \
3 -e MYSQL_ROOT_PASSWORD=ai \
4 -e MYSQL_DATABASE=ai \
5 -e MYSQL_USER=ai \
6 -e MYSQL_PASSWORD=ai \
7 -p 3306:3306 \
8 -d mysql:8
1from typing import List
2
3from kern.agent import Agent
4from kern.db.mysql import MySQLDb
5from kern.models.openai import OpenAIResponses
6from kern.team import Team
7from kern.tools.hackernews import HackerNewsTools
8from kern.tools.hackernews import HackerNewsTools
9from pydantic import BaseModel
10
11# MySQL connection settings
12db_url = "mysql+pymysql://ai:ai@localhost:3306/ai"
13db = MySQLDb(db_url=db_url)
14
15class Article(BaseModel):
16 title: str
17 summary: str
18 reference_links: List[str]
19
20hn_researcher = Agent(
21 name="HackerNews Researcher",
22 model=OpenAIResponses(id="gpt-5.2"),
23 role="Gets top stories from hackernews.",
24 tools=[HackerNewsTools()],
25)
26
27web_searcher = Agent(
28 name="Web Searcher",
29 model=OpenAIResponses(id="gpt-5.2"),
30 role="Searches the web for information on a topic",
31 tools=[HackerNewsTools()],
32 add_datetime_to_context=True,
33)
34
35hn_team = Team(
36 name="HackerNews Team",
37 model=OpenAIResponses(id="gpt-5.2"),
38 members=[hn_researcher, web_searcher],
39 db=db,
40 instructions=[
41 "First, search hackernews for what the user is asking about.",
42 "Then, ask the web searcher to search for each story to get more information.",
43 "Finally, provide a thoughtful and engaging summary.",
44 ],
45 output_schema=Article,
46 markdown=True,
47 show_members_responses=True,
48)
49
50hn_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.