SurrealDB for Workflow
Kern supports using SurrealDB as a storage backend for Workflows 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.team import Team5from kern.tools.hackernews import HackerNewsTools6from kern.tools.hackernews import HackerNewsTools7from kern.workflow.step import Step8from kern.workflow.workflow import Workflow910# SurrealDB connection parameters11SURREALDB_URL = "ws://localhost:8000"12SURREALDB_USER = "root"13SURREALDB_PASSWORD = "root"14SURREALDB_NAMESPACE = "kern"15SURREALDB_DATABASE = "surrealdb_for_workflow"1617creds = {"username": SURREALDB_USER, "password": SURREALDB_PASSWORD}18db = SurrealDb(None, SURREALDB_URL, creds, SURREALDB_NAMESPACE, SURREALDB_DATABASE)1920# Define agents21hackernews_agent = Agent(22 name="Hackernews Agent",23 model=Claude(id="claude-sonnet-4-5-20250929"),24 tools=[HackerNewsTools()],25 role="Extract key insights and content from Hackernews posts",26)27web_agent = Agent(28 name="Web Agent",29 model=Claude(id="claude-sonnet-4-5-20250929"),30 tools=[HackerNewsTools()],31 role="Search the web for the latest news and trends",32)3334# Define research team for complex analysis35research_team = Team(36 name="Research Team",37 model=Claude(id="claude-sonnet-4-5-20250929"),38 members=[hackernews_agent, web_agent],39 instructions="Research tech topics from Hackernews and the web",40)4142content_planner = Agent(43 name="Content Planner",44 model=Claude(id="claude-sonnet-4-5-20250929"),45 instructions=[46 "Plan a content schedule over 4 weeks for the provided topic and research content",47 "Ensure that I have posts for 3 posts per week",48 ],49)5051# Define steps52research_step = Step(53 name="Research Step",54 team=research_team,55)5657content_planning_step = Step(58 name="Content Planning Step",59 agent=content_planner,60)6162# Create and use workflow63if __name__ == "__main__":64 content_creation_workflow = Workflow(65 name="Content Creation Workflow",66 description="Automated content creation from blog posts to social media",67 db=db,68 steps=[research_step, content_planning_step],69 )70 content_creation_workflow.print_response(71 input="AI trends in 2024",72 markdown=True,73 )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. |