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 root
1from kern.agent import Agent
2from kern.db.surrealdb import SurrealDb
3from kern.models.anthropic import Claude
4from kern.team import Team
5from kern.tools.hackernews import HackerNewsTools
6from kern.tools.hackernews import HackerNewsTools
7from kern.workflow.step import Step
8from kern.workflow.workflow import Workflow
9
10# SurrealDB connection parameters
11SURREALDB_URL = "ws://localhost:8000"
12SURREALDB_USER = "root"
13SURREALDB_PASSWORD = "root"
14SURREALDB_NAMESPACE = "kern"
15SURREALDB_DATABASE = "surrealdb_for_workflow"
16
17creds = {"username": SURREALDB_USER, "password": SURREALDB_PASSWORD}
18db = SurrealDb(None, SURREALDB_URL, creds, SURREALDB_NAMESPACE, SURREALDB_DATABASE)
19
20# Define agents
21hackernews_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)
33
34# Define research team for complex analysis
35research_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)
41
42content_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)
50
51# Define steps
52research_step = Step(
53 name="Research Step",
54 team=research_team,
55)
56
57content_planning_step = Step(
58 name="Content Planning Step",
59 agent=content_planner,
60)
61
62# Create and use workflow
63if __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

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.