Redis for Team

Kern supports using Redis as a storage backend for Teams 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 newspaper4k lxml_html_clean kern-ai redis` to install the dependencies
3"""
4
5from typing import List
6
7from kern.agent import Agent
8from kern.db.redis import RedisDb
9from kern.models.openai import OpenAIResponses
10from kern.team import Team
11from kern.tools.hackernews import HackerNewsTools
12from kern.tools.hackernews import HackerNewsTools
13from pydantic import BaseModel
14
15db = RedisDb(db_url="redis://localhost:6379")
16
17class Article(BaseModel):
18 title: str
19 summary: str
20 reference_links: List[str]
21
22hn_researcher = Agent(
23 name="HackerNews Researcher",
24 model=OpenAIResponses(id="gpt-5.2"),
25 role="Gets top stories from hackernews.",
26 tools=[HackerNewsTools()],
27)
28
29web_searcher = Agent(
30 name="Web Searcher",
31 model=OpenAIResponses(id="gpt-5.2"),
32 role="Searches the web for information on a topic",
33 tools=[HackerNewsTools()],
34 add_datetime_to_context=True,
35)
36
37hn_team = Team(
38 name="HackerNews Team",
39 model=OpenAIResponses(id="gpt-5.2"),
40 members=[hn_researcher, web_searcher],
41 db=db,
42 instructions=[
43 "First, search hackernews for what the user is asking about.",
44 "Then, ask the web searcher to search for each story to get more information.",
45 "Finally, provide a thoughtful and engaging summary.",
46 ],
47 output_schema=Article,
48 markdown=True,
49 show_members_responses=True,
50)
51
52hn_team.print_response("Write an article about the top 2 stories on hackernews")

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.