JSON for Workflows
Kern supports using local JSON files as a storage backend for Workflows using the JsonDb class.
Usage
1from kern.agent import Agent2from kern.db.json import JsonDb3from 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 Workflow910# Setup the JSON database11db = JsonDb(db_path="tmp/json_db")1213# Define agents14hackernews_agent = Agent(15 name="Hackernews Agent",16 model=OpenAIResponses(id="gpt-5.2"),17 tools=[HackerNewsTools()],18 role="Extract key insights and content from Hackernews posts",19)20web_agent = Agent(21 name="Web Agent",22 model=OpenAIResponses(id="gpt-5.2"),23 tools=[HackerNewsTools()],24 role="Search the web for the latest news and trends",25)2627# Define research team for complex analysis28research_team = Team(29 name="Research Team",30 members=[hackernews_agent, web_agent],31 instructions="Research tech topics from Hackernews and the web",32)3334content_planner = Agent(35 name="Content Planner",36 model=OpenAIResponses(id="gpt-5.2"),37 instructions=[38 "Plan a content schedule over 4 weeks for the provided topic and research content",39 "Ensure that I have posts for 3 posts per week",40 ],41)4243# Define steps44research_step = Step(45 name="Research Step",46 team=research_team,47)4849content_planning_step = Step(50 name="Content Planning Step",51 agent=content_planner,52)5354# Create and use workflow55if __name__ == "__main__":56 content_creation_workflow = Workflow(57 name="Content Creation Workflow",58 description="Automated content creation from blog posts to social media",59 db=db,60 steps=[research_step, content_planning_step],61 )62 content_creation_workflow.print_response(63 input="AI trends in 2024",64 markdown=True,65 )Params
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | The ID of the database instance. UUID by default. |
db_path | Optional[str] | - | Path to the directory where JSON files will be stored. |
session_table | Optional[str] | - | Name of the JSON file to store sessions (without .json extension). |
memory_table | Optional[str] | - | Name of the JSON file to store memories. |
metrics_table | Optional[str] | - | Name of the JSON file to store metrics. |
eval_table | Optional[str] | - | Name of the JSON file to store evaluation runs. |
knowledge_table | Optional[str] | - | Name of the JSON file to store knowledge content. |
traces_table | Optional[str] | - | Name of the JSON file to store traces. |
spans_table | Optional[str] | - | Name of the JSON file to store spans. |