SurrealDB Memory DB Tools Control
Control memory writes with MemoryManager's add_memories and update_memories flags, backed by SurrealDB.
"""
SurrealDB Memory DB Tools Control
"""
from agno.agent.agent import Agent
from agno.db.surrealdb import SurrealDb
from agno.memory.manager import MemoryManager
from agno.models.openai import OpenAIChat
from rich.pretty import pprint
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
SURREALDB_URL = "ws://localhost:8000"
SURREALDB_USER = "root"
SURREALDB_PASSWORD = "root"
SURREALDB_NAMESPACE = "agno"
SURREALDB_DATABASE = "memories"
creds = {"username": SURREALDB_USER, "password": SURREALDB_PASSWORD}
memory_db = SurrealDb(
None, SURREALDB_URL, creds, SURREALDB_NAMESPACE, SURREALDB_DATABASE
)
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
john_doe_id = "john_doe@example.com"
memory_manager_full = MemoryManager(
model=OpenAIChat(id="gpt-5.6-luna"),
db=memory_db,
add_memories=True,
update_memories=True,
)
agent_full = Agent(
model=OpenAIChat(id="gpt-5.6-luna"),
memory_manager=memory_manager_full,
enable_agentic_memory=True,
db=memory_db,
)
# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
def run_example() -> None:
# Add initial memory
agent_full.print_response(
"My name is John Doe and I like to hike in the mountains on weekends. I also enjoy photography.",
stream=True,
user_id=john_doe_id,
)
# Test memory recall
agent_full.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)
# Test memory update
agent_full.print_response(
"I no longer enjoy photography. Instead, I've taken up rock climbing.",
stream=True,
user_id=john_doe_id,
)
print("\nMemories after update:")
memories = memory_manager_full.get_user_memories(user_id=john_doe_id)
pprint([m.memory for m in memories] if memories else [])
if __name__ == "__main__":
run_example()What the flags control
This run enables both adding and updating memories. The flags control the tools offered to the memory manager during agentic memory updates; they do not block direct database or MemoryManager CRUD calls. Whether the agent requests an update and what it stores depend on the model. Inspect the printed memories to check the result.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openai surrealdbExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Run SurrealDB
Install and start Docker first. This local demonstration uses the agno namespace and memories database with development credentials.
docker run -d --rm --name surrealdb --pull always -p 8000:8000 surrealdb/surrealdb:latest start --user root --pass rootRun the example
Save the code above as db_tools_control.py, then run:
python db_tools_control.pyFull source: cookbook/integrations/surrealdb/db_tools_control.py