SurrealDB for Agent
Kern supports using SurrealDB as a storage backend for Agents 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 kern.agent import Agent2from kern.db.surrealdb import SurrealDb3from kern.models.anthropic import Claude4from kern.tools.hackernews import HackerNewsTools56# SurrealDB connection parameters7SURREALDB_URL = "ws://localhost:8000"8SURREALDB_USER = "root"9SURREALDB_PASSWORD = "root"10SURREALDB_NAMESPACE = "kern"11SURREALDB_DATABASE = "surrealdb_for_agent"1213creds = {"username": SURREALDB_USER, "password": SURREALDB_PASSWORD}14db = SurrealDb(None, SURREALDB_URL, creds, SURREALDB_NAMESPACE, SURREALDB_DATABASE)1516agent = Agent(17 db=db,18 model=Claude(id="claude-sonnet-4-5-20250929"),19 tools=[HackerNewsTools()],20 add_history_to_context=True,21)22agent.print_response("How many people live in Costa Rica?")23agent.print_response("What is their national anthem called?")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. |