Async Postgres for Team
Kern supports using PostgreSQL asynchronously, with the AsyncPostgresDb 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:161import asyncio2from typing import List34from kern.agent import Agent5from kern.db.postgres import AsyncPostgresDb6from kern.models.openai import OpenAIResponses7from kern.team import Team8from kern.tools.hackernews import HackerNewsTools9from kern.tools.hackernews import HackerNewsTools10from pydantic import BaseModel1112db_url = "postgresql+psycopg_async://ai:ai@localhost:5532/ai"13db = AsyncPostgresDb(db_url=db_url)1415class Article(BaseModel):16 title: str17 summary: str18 reference_links: List[str]1920hn_researcher = Agent(21 name="HackerNews Researcher",22 model=OpenAIResponses(id="gpt-5.2"),23 role="Gets top stories from hackernews.",24 tools=[HackerNewsTools()],25)2627web_searcher = Agent(28 name="Web Searcher",29 model=OpenAIResponses(id="gpt-5.2"),30 role="Searches the web for information on a topic",31 tools=[HackerNewsTools()],32 add_datetime_to_context=True,33)3435hn_team = Team(36 name="HackerNews Team",37 model=OpenAIResponses(id="gpt-5.2"),38 members=[hn_researcher, web_searcher],39 db=db,40 instructions=[41 "First, search hackernews for what the user is asking about.",42 "Then, ask the web searcher to search for each story to get more information.",43 "Finally, provide a thoughtful and engaging summary.",44 ],45 output_schema=Article,46 markdown=True,47 show_members_responses=True,48)4950asyncio.run(51 hn_team.aprint_response("Write an article about the top 2 stories on hackernews")52)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[AsyncEngine] | - | The SQLAlchemy asyncdatabase 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. |