Control Memory Database Tools

Control which memory database operations are available to the AI model using DB tool flags.

db_tools_control.py
"""
Control Memory Database Tools
=============================

This example demonstrates how to control which memory database operations are
available to the AI model using DB tool flags.
"""

from agno.agent.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.memory.manager import MemoryManager
from agno.models.openai import OpenAIChat
from rich.pretty import pprint

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
memory_db = SqliteDb(db_file="tmp/memory_control_demo.db")
john_doe_id = "john_doe@example.com"

# ---------------------------------------------------------------------------
# Create Memory Manager and Agent
# ---------------------------------------------------------------------------
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 Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    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,
    )

    agent_full.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)

    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 [])

Change which operations are available

The saved example enables both add and update operations, which are already the defaults. To demonstrate the restriction, set update_memories=False on memory_manager_full before constructing the agent. The memory manager then omits its update tool; it can still add new memories, so this setting does not enforce an immutable user profile. Deletion and clearing are disabled by default and have separate delete_memories and clear_memories flags.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai sqlalchemy

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

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

python db_tools_control.py

Full source: cookbook/11_memory/memory_manager/05_db_tools_control.py