Redis for Workflows

Kern supports using Redis as a storage backend for Workflows using the RedisDb class.

Usage

Run Redis

Install docker desktop and run Redis on port 6379 using:

1docker run --name my-redis -p 6379:6379 -d redis
1"""
2Run: `uv pip install openai httpx newspaper4k redis kern-ai` to install the dependencies
3"""
4from kern.agent import Agent
5from kern.db.redis import RedisDb
6from kern.models.openai import OpenAIResponses
7from kern.team import Team
8from kern.tools.hackernews import HackerNewsTools
9from kern.tools.hackernews import HackerNewsTools
10from kern.workflow.step import Step
11from kern.workflow.workflow import Workflow
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=RedisDb(
60 session_table="workflow_session",
61 db_url="redis://localhost:6379",
62 ),
63 steps=[research_step, content_planning_step],
64 )
65 content_creation_workflow.print_response(
66 input="AI trends in 2024",
67 markdown=True,
68 )

Params

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
redis_clientOptional[Redis]-Redis client instance to use. If not provided a new client will be created.
db_urlOptional[str]-Redis connection URL (e.g., "redis://localhost:6379/0" or "rediss://user:pass@host:port/db")
db_prefixstr"kern"Prefix for all Redis keys.
expireOptional[int]-TTL for Redis keys in seconds.
session_tableOptional[str]-Name of the table to store 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.
knowledge_tableOptional[str]-Name of the table to store knowledge documents.
traces_tableOptional[str]-Name of the table to store traces.
spans_tableOptional[str]-Name of the table to store spans.