> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SurrealDB Memory DB Tools Control

> Control memory writes with MemoryManager's add_memories and update_memories flags, backed by SurrealDB.

```python db_tools_control.py theme={null}
"""
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()
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno openai surrealdb
```

**2. Export your OpenAI API key**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Run SurrealDB**

```bash theme={null}
docker run -d --rm --name surrealdb --pull always -p 8000:8000 surrealdb/surrealdb:latest start --user root --pass root
```

**4. Run the example**

Save the code above as `db_tools_control.py`, then run:

```bash theme={null}
python db_tools_control.py
```

Full source: [cookbook/integrations/surrealdb/db\_tools\_control.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/integrations/surrealdb/db_tools_control.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.