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 root
1from typing import List
2
3from kern.agent import Agent
4from kern.db.surrealdb import SurrealDb
5from kern.models.anthropic import Claude
6from kern.team import Team
7from kern.tools.hackernews import HackerNewsTools
8from kern.tools.hackernews import HackerNewsTools
9from pydantic import BaseModel
10
11# SurrealDB connection parameters
12SURREALDB_URL = "ws://localhost:8000"
13SURREALDB_USER = "root"
14SURREALDB_PASSWORD = "root"
15SURREALDB_NAMESPACE = "kern"
16SURREALDB_DATABASE = "surrealdb_for_team"
17
18creds = {"username": SURREALDB_USER, "password": SURREALDB_PASSWORD}
19db = SurrealDb(None, SURREALDB_URL, creds, SURREALDB_NAMESPACE, SURREALDB_DATABASE)
20
21class Article(BaseModel):
22 title: str
23 summary: str
24 reference_links: List[str]
25
26hn_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)
32
33web_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)
40
41hn_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)
55
56hn_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.
clientOptional[Union[BlockingWsSurrealConnection, BlockingHttpSurrealConnection]]-A blocking connection, either HTTP or WebSocket.
db_urlstr-The SurrealDB connection URL.
db_credsdict[str, str]-Database credentials dictionary (username, password).
db_nsstr-The SurrealDB namespace to use.
db_dbstr-The SurrealDB database name to use.
session_tableOptional[str]-Name of the table to store Agent, Team and Workflow sessions.
memory_tableOptional[str]-Name of the table to store user memories.
metrics_tableOptional[str]-Name of the table to store metrics.
eval_tableOptional[str]-Name of the table to store evaluation runs data.
knowledge_tableOptional[str]-Name of the table to store knowledge documents data.
culture_tableOptional[str]-Name of the table to store cultural knowledge data.
traces_tableOptional[str]-Name of the table to store traces.
spans_tableOptional[str]-Name of the table to store spans.