MySQL Workflow Storage

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

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.