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 redis1"""2Run: `uv pip install openai newspaper4k lxml_html_clean kern-ai redis` to install the dependencies3"""45from typing import List67from kern.agent import Agent8from kern.db.redis import RedisDb9from kern.models.openai import OpenAIResponses10from kern.team import Team11from kern.tools.hackernews import HackerNewsTools12from kern.tools.hackernews import HackerNewsTools13from pydantic import BaseModel1415db = RedisDb(db_url="redis://localhost:6379")1617class Article(BaseModel):18 title: str19 summary: str20 reference_links: List[str]2122hn_researcher = Agent(23 name="HackerNews Researcher",24 model=OpenAIResponses(id="gpt-5.2"),25 role="Gets top stories from hackernews.",26 tools=[HackerNewsTools()],27)2829web_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)3637hn_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)5152hn_team.print_response("Write an article about the top 2 stories on hackernews")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. |