Postgres for Team
Kern supports using PostgreSQL as a storage backend for Teams using the PostgresDb class.
Usage
Run PgVector
Install docker desktop and run PgVector on port 5532 using:
1docker run -d \2 -e POSTGRES_DB=ai \3 -e POSTGRES_USER=ai \4 -e POSTGRES_PASSWORD=ai \5 -e PGDATA=/var/lib/postgresql/data/pgdata \6 -v pgvolume:/var/lib/postgresql/data \7 -p 5532:5432 \8 --name pgvector \9 agnohq/pgvector:161"""2Run: `uv pip install openai newspaper4k lxml_html_clean kern-ai` to install the dependencies3"""45from typing import List67from kern.agent import Agent8from kern.db.postgres import PostgresDb9from kern.models.openai import OpenAIResponses10from kern.team import Team11from kern.tools.hackernews import HackerNewsTools12from kern.tools.hackernews import HackerNewsTools13from pydantic import BaseModel1415db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"16db = PostgresDb(db_url=db_url)1718class Article(BaseModel):19 title: str20 summary: str21 reference_links: List[str]2223hn_researcher = Agent(24 name="HackerNews Researcher",25 model=OpenAIResponses(id="gpt-5.2"),26 role="Gets top stories from hackernews.",27 tools=[HackerNewsTools()],28)2930web_searcher = Agent(31 name="Web Searcher",32 model=OpenAIResponses(id="gpt-5.2"),33 role="Searches the web for information on a topic",34 tools=[HackerNewsTools()],35 add_datetime_to_context=True,36)3738hn_team = Team(39 name="HackerNews Team",40 model=OpenAIResponses(id="gpt-5.2"),41 members=[hn_researcher, web_searcher],42 db=db,43 instructions=[44 "First, search hackernews for what the user is asking about.",45 "Then, ask the web searcher to search for each story to get more information.",46 "Finally, provide a thoughtful and engaging summary.",47 ],48 output_schema=Article,49 markdown=True,50 show_members_responses=True,51)5253hn_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. |
db_url | Optional[str] | - | The database URL to connect to. |
db_engine | Optional[Engine] | - | The SQLAlchemy database engine to use. |
db_schema | Optional[str] | - | The database schema to use. |
session_table | Optional[str] | - | Name of the table to store Agent, Team and Workflow 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 data. |
knowledge_table | Optional[str] | - | Name of the table to store knowledge content. |
traces_table | Optional[str] | - | Name of the table to store traces. |
spans_table | Optional[str] | - | Name of the table to store spans. |