Multi-model database tool for document, graph, and relational data
SurrealDB tool enables agents to interact with multi-model databases, supporting document, graph, and relational data through native SurrealQL queries.
from praisonaiagents import Agentfrom praisonai_tools import SurrealDBToolagent = Agent(name="DataAgent", tools=[SurrealDBTool()])agent.start("List the ten most recent users in the database")
The user asks a data question; SurrealDB tools let the agent query and update records safely.
from praisonaiagents import Agentfrom praisonai_tools import SurrealDBToolagent = Agent( name="DatabaseAgent", instructions="You analyze multi-model data using SurrealDB", tools=[SurrealDBTool( url="ws://localhost:8000/rpc", namespace="test", database="test" )])response = agent.chat("Create a user and show all records")
2
Direct Tool Usage
from praisonai_tools import SurrealDBTooldb = SurrealDBTool( url="ws://localhost:8000/rpc", namespace="test", database="test")results = db.query("SELECT * FROM users")
# Create nodes and relationshipsdb.query(""" CREATE person:alice SET name = 'Alice', age = 30; CREATE person:bob SET name = 'Bob', age = 25; CREATE company:acme SET name = 'Acme Corp'; RELATE person:alice->works_for->company:acme SET position = 'Engineer'; RELATE person:bob->works_for->company:acme SET position = 'Designer'; RELATE person:alice->knows->person:bob SET since = '2020-01-01';""")# Query relationshipscolleagues = db.query(""" SELECT * FROM person WHERE ->works_for->company.name = 'Acme Corp'""")
# Live queries for real-time updateslive_query = db.query("LIVE SELECT * FROM users WHERE active = true")print(f"Live query ID: {live_query}")# The agent can monitor changes in real-time
from praisonai_tools import SurrealDBTooltry: db = SurrealDBTool( url="ws://localhost:8000/rpc", user="root", password="root", namespace="test", database="test" ) result = db.query("SELECT * FROM users") if isinstance(result, dict) and "error" in result: print(f"Query Error: {result['error']}") else: print(f"Results: {result}")except Exception as e: print(f"Connection Error: {e}")
-- CreateCREATE users SET name = 'John', age = 30;CREATE users:john SET name = 'John Doe';-- Select SELECT * FROM users;SELECT name, age FROM users WHERE age > 25;-- UpdateUPDATE users SET age = 31 WHERE name = 'John';UPDATE users:john SET age += 1;-- DeleteDELETE users WHERE age < 18;DELETE users:john;-- Relate (Graph)RELATE user:alice->likes->product:laptop;-- Live QueriesLIVE SELECT * FROM users;
Leverage SurrealDB’s multi-model capabilities for complex data — combine documents, graphs, and relations in one schema instead of forcing everything into a single model.
Namespace Organisation
Use namespaces to separate environments (dev, staging, prod) so agents and tools never cross wires between datasets.
Security
Always use authentication in production environments; avoid root credentials in agent-facing tools.
Monitoring
Set up monitoring for query performance and resource usage, especially when agents run ad hoc SurrealQL.
Backup Strategy
Implement regular backups for persistent storage setups before relying on agents for write-heavy workflows.