Async SQLite for Workflow

Kern supports using SQLite asynchronously as a storage backend for Workflows, with the AsyncSqliteDb class.

Usage

1"""
2Run: `uv pip install openai sqlalchemy aiosqlite` to install dependencies
3"""
4
5import asyncio
6
7from kern.agent import Agent
8from kern.db.sqlite import AsyncSqliteDb
9from kern.models.openai import OpenAIResponses
10from kern.team import Team
11from kern.tools.hackernews import HackerNewsTools
12from kern.tools.hackernews import HackerNewsTools
13from kern.workflow.step import Step
14from kern.workflow.workflow import Workflow
15
16# Initialize AsyncSqliteDb with a database file
17db = AsyncSqliteDb(db_file="workflow_storage.db")
18
19hackernews_agent = Agent(
20 name="Hackernews Agent",
21 model=OpenAIResponses(id="gpt-5.2"),
22 tools=[HackerNewsTools()],
23 role="Extract key insights and content from Hackernews posts",
24)
25web_agent = Agent(
26 name="Web Agent",
27 model=OpenAIResponses(id="gpt-5.2"),
28 tools=[HackerNewsTools()],
29 role="Search the web for the latest news and trends",
30)
31content_planner = Agent(
32 name="Content Planner",
33 model=OpenAIResponses(id="gpt-5.2"),
34 instructions=[
35 "Plan a content schedule over 4 weeks for the provided topic and research content",
36 "Ensure that I have posts for 3 posts per week",
37 ],
38)
39
40research_team = Team(
41 name="Research Team",
42 members=[hackernews_agent, web_agent],
43 instructions="Research tech topics from Hackernews and the web",
44)
45
46research_step = Step(
47 name="Research Step",
48 team=research_team,
49)
50content_planning_step = Step(
51 name="Content Planning Step",
52 agent=content_planner,
53)
54content_creation_workflow = Workflow(
55 name="Content Creation Workflow",
56 description="Automated content creation from blog posts to social media",
57 db=db,
58 steps=[research_step, content_planning_step],
59)
60
61if __name__ == "__main__":
62 asyncio.run(
63 content_creation_workflow.aprint_response(
64 input="AI trends in 2024",
65 markdown=True,
66 )
67 )

Params

ParameterTypeDefaultDescription
db_engineOptional[Engine]-The SQLAlchemy database engine to use.
db_urlOptional[str]-The database URL to connect to.
db_fileOptional[str]-The database file 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 user 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 documents data.
traces_tableOptional[str]-Name of the table to store traces.
spans_tableOptional[str]-Name of the table to store spans.