Singlestore for Workflow

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

Usage

Obtain the credentials for Singlestore from here

1from kern.agent import Agent
2from kern.db.singlestore import SingleStoreDb
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
10# Configure SingleStore DB connection
11USERNAME = getenv("SINGLESTORE_USERNAME")
12PASSWORD = getenv("SINGLESTORE_PASSWORD")
13HOST = getenv("SINGLESTORE_HOST")
14PORT = getenv("SINGLESTORE_PORT")
15DATABASE = getenv("SINGLESTORE_DATABASE")
16SSL_CERT = getenv("SINGLESTORE_SSL_CERT", None)
17
18db_url = (
19 f"mysql+pymysql://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DATABASE}?charset=utf8mb4"
20)
21db = SingleStoreDb(db_url=db_url)
22
23# Define agents
24hackernews_agent = Agent(
25 name="Hackernews Agent",
26 model=OpenAIResponses(id="gpt-5.2"),
27 tools=[HackerNewsTools()],
28 role="Extract key insights and content from Hackernews posts",
29)
30web_agent = Agent(
31 name="Web Agent",
32 model=OpenAIResponses(id="gpt-5.2"),
33 tools=[HackerNewsTools()],
34 role="Search the web for the latest news and trends",
35)
36
37# Define research team for complex analysis
38research_team = Team(
39 name="Research Team",
40 members=[hackernews_agent, web_agent],
41 instructions="Research tech topics from Hackernews and the web",
42)
43
44content_planner = Agent(
45 name="Content Planner",
46 model=OpenAIResponses(id="gpt-5.2"),
47 instructions=[
48 "Plan a content schedule over 4 weeks for the provided topic and research content",
49 "Ensure that I have posts for 3 posts per week",
50 ],
51)
52
53# Define steps
54research_step = Step(
55 name="Research Step",
56 team=research_team,
57)
58
59content_planning_step = Step(
60 name="Content Planning Step",
61 agent=content_planner,
62)
63
64# Create and use workflow
65if __name__ == "__main__":
66 content_creation_workflow = Workflow(
67 name="Content Creation Workflow",
68 description="Automated content creation from blog posts to social media",
69 db=db,
70 steps=[research_step, content_planning_step],
71 )
72 content_creation_workflow.print_response(
73 input="AI trends in 2024",
74 markdown=True,
75 )

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.