JSON for Workflows

Kern supports using local JSON files as a storage backend for Workflows using the JsonDb class.

Usage

1from kern.agent import Agent
2from kern.db.json import JsonDb
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# Setup the JSON database
11db = JsonDb(db_path="tmp/json_db")
12
13# Define agents
14hackernews_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)
26
27# Define research team for complex analysis
28research_team = Team(
29 name="Research Team",
30 members=[hackernews_agent, web_agent],
31 instructions="Research tech topics from Hackernews and the web",
32)
33
34content_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)
42
43# Define steps
44research_step = Step(
45 name="Research Step",
46 team=research_team,
47)
48
49content_planning_step = Step(
50 name="Content Planning Step",
51 agent=content_planner,
52)
53
54# Create and use workflow
55if __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

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
db_pathOptional[str]-Path to the directory where JSON files will be stored.
session_tableOptional[str]-Name of the JSON file to store sessions (without .json extension).
memory_tableOptional[str]-Name of the JSON file to store memories.
metrics_tableOptional[str]-Name of the JSON file to store metrics.
eval_tableOptional[str]-Name of the JSON file to store evaluation runs.
knowledge_tableOptional[str]-Name of the JSON file to store knowledge content.
traces_tableOptional[str]-Name of the JSON file to store traces.
spans_tableOptional[str]-Name of the JSON file to store spans.