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:81from kern.agent import Agent2from kern.db.mysql import MySQLDb3from kern.models.openai import OpenAIResponses4from kern.team import Team5from kern.tools.hackernews import HackerNewsTools6from kern.tools.hackernews import HackerNewsTools7from kern.workflow.step import Step8from kern.workflow.workflow import Workflow910db_url = "mysql+pymysql://ai:ai@localhost:3306/ai"1112db = MySQLDb(db_url=db_url)1314# Define agents15hackernews_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)2728# Define research team for complex analysis29research_team = Team(30 name="Research Team",31 members=[hackernews_agent, web_agent],32 instructions="Research tech topics from Hackernews and the web",33)3435content_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)4344# Define steps45research_step = Step(46 name="Research Step",47 team=research_team,48)4950content_planning_step = Step(51 name="Content Planning Step",52 agent=content_planner,53)5455# Create and use workflow56if __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
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | The ID of the database instance. UUID by default. |
db_engine | Optional[Engine] | - | The SQLAlchemy database engine to use. |
db_schema | Optional[str] | - | The database schema to use. |
db_url | Optional[str] | - | The database URL to connect to. |
session_table | Optional[str] | - | Name of the table to store Agent, Team and Workflow sessions. |
memory_table | Optional[str] | - | Name of the table to store memories. |
metrics_table | Optional[str] | - | Name of the table to store metrics. |
eval_table | Optional[str] | - | Name of the table to store evaluation runs data. |
knowledge_table | Optional[str] | - | Name of the table to store knowledge content. |
traces_table | Optional[str] | - | Name of the table to store traces. |
spans_table | Optional[str] | - | Name of the table to store spans. |