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 redis1"""2Run: `uv pip install openai httpx newspaper4k redis kern-ai` to install the dependencies3"""4from kern.agent import Agent5from kern.db.redis import RedisDb6from kern.models.openai import OpenAIResponses7from kern.team import Team8from kern.tools.hackernews import HackerNewsTools9from kern.tools.hackernews import HackerNewsTools10from kern.workflow.step import Step11from kern.workflow.workflow import Workflow1213# 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=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
| Parameter | Type | Default | Description |
|---|---|---|---|
id | Optional[str] | - | The ID of the database instance. UUID by default. |
redis_client | Optional[Redis] | - | Redis client instance to use. If not provided a new client will be created. |
db_url | Optional[str] | - | Redis connection URL (e.g., "redis://localhost:6379/0" or "rediss://user:pass@host:port/db") |
db_prefix | str | "kern" | Prefix for all Redis keys. |
expire | Optional[int] | - | TTL for Redis keys in seconds. |
session_table | Optional[str] | - | Name of the table to store sessions. |
memory_table | Optional[str] | - | Name of the table to store memories. |
metrics_table | Optional[str] | - | Name of the table to store metrics. |
eval_table | Optional[str] | - | Name of the table to store evaluation runs. |
knowledge_table | Optional[str] | - | Name of the table to store knowledge documents. |
traces_table | Optional[str] | - | Name of the table to store traces. |
spans_table | Optional[str] | - | Name of the table to store spans. |