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 dependencies3"""45import asyncio67from kern.agent import Agent8from kern.db.sqlite import AsyncSqliteDb9from kern.models.openai import OpenAIResponses10from kern.team import Team11from kern.tools.hackernews import HackerNewsTools12from kern.tools.hackernews import HackerNewsTools13from kern.workflow.step import Step14from kern.workflow.workflow import Workflow1516# Initialize AsyncSqliteDb with a database file17db = AsyncSqliteDb(db_file="workflow_storage.db")1819hackernews_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)3940research_team = Team(41 name="Research Team",42 members=[hackernews_agent, web_agent],43 instructions="Research tech topics from Hackernews and the web",44)4546research_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)6061if __name__ == "__main__":62 asyncio.run(63 content_creation_workflow.aprint_response(64 input="AI trends in 2024",65 markdown=True,66 )67 )Params
| Parameter | Type | Default | Description |
|---|---|---|---|
db_engine | Optional[Engine] | - | The SQLAlchemy database engine to use. |
db_url | Optional[str] | - | The database URL to connect to. |
db_file | Optional[str] | - | The database file 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 user 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 documents data. |
traces_table | Optional[str] | - | Name of the table to store traces. |
spans_table | Optional[str] | - | Name of the table to store spans. |