SurrealDB for Team
Kern supports using SurrealDB as a storage backend for Teams using the SurrealDb class.
Usage
Run SurreabDB locally with the following command:
1docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:latest start --user root --pass root1from typing import List23from kern.agent import Agent4from kern.db.surrealdb import SurrealDb5from kern.models.anthropic import Claude6from kern.team import Team7from kern.tools.hackernews import HackerNewsTools8from kern.tools.hackernews import HackerNewsTools9from pydantic import BaseModel1011# SurrealDB connection parameters12SURREALDB_URL = "ws://localhost:8000"13SURREALDB_USER = "root"14SURREALDB_PASSWORD = "root"15SURREALDB_NAMESPACE = "kern"16SURREALDB_DATABASE = "surrealdb_for_team"1718creds = {"username": SURREALDB_USER, "password": SURREALDB_PASSWORD}19db = SurrealDb(None, SURREALDB_URL, creds, SURREALDB_NAMESPACE, SURREALDB_DATABASE)2021class Article(BaseModel):22 title: str23 summary: str24 reference_links: List[str]2526hn_researcher = Agent(27 name="HackerNews Researcher",28 model=Claude(id="claude-sonnet-4-5-20250929"),29 role="Gets top stories from hackernews.",30 tools=[HackerNewsTools()],31)3233web_searcher = Agent(34 name="Web Searcher",35 model=Claude(id="claude-sonnet-4-5-20250929"),36 role="Searches the web for information on a topic",37 tools=[HackerNewsTools()],38 add_datetime_to_context=True,39)4041hn_team = Team(42 name="HackerNews Team",43 model=Claude(id="claude-sonnet-4-5-20250929"),44 members=[hn_researcher, web_searcher],45 db=db,46 instructions=[47 "First, search hackernews for what the user is asking about.",48 "Then, ask the web searcher to search for each story to get more information.",49 "Finally, provide a thoughtful and engaging summary.",50 ],51 output_schema=Article,52 markdown=True,53 show_members_responses=True,54)5556hn_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. |
client | Optional[Union[BlockingWsSurrealConnection, BlockingHttpSurrealConnection]] | - | A blocking connection, either HTTP or WebSocket. |
db_url | str | - | The SurrealDB connection URL. |
db_creds | dict[str, str] | - | Database credentials dictionary (username, password). |
db_ns | str | - | The SurrealDB namespace to use. |
db_db | str | - | The SurrealDB database name 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 user 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 documents data. |
culture_table | Optional[str] | - | Name of the table to store cultural knowledge data. |
traces_table | Optional[str] | - | Name of the table to store traces. |
spans_table | Optional[str] | - | Name of the table to store spans. |