Memory Tools
Give Agents create, update, and delete access to stored user memories with the MemoryTools toolkit's think, get_memories, add_memory, update_memory, delete_memory, and analyze tools.
The MemoryTools toolkit enables Agents to manage user memories through create, update, and delete operations. This toolkit integrates with a provided database where memories are stored.
The toolkit implements a "Think → Operate → Analyze" cycle that allows an Agent to:
- Think through memory management requirements and plan operations
- Execute memory operations (add, update, delete) on the database
- Analyze the results to ensure operations completed successfully and meet requirements
This approach gives Agents the ability to persistently store, retrieve, and manage user information, preferences, and context across conversations.
The toolkit includes the following tools:
think: A scratchpad for planning memory operations, brainstorming content, and refining approaches. These are explicit tool notes. Your application controls their visibility in events, stored messages, reasoning displays, and logs.get_memories: Gets a list of memories for the current user from the database.add_memory: Creates new memories in the database with specified content and optional topics.update_memory: Modifies existing memories by memory ID, allowing updates to content and topics.delete_memory: Removes memories from the database by memory ID.analyze: Evaluates whether memory operations completed successfully and produced the expected results.
Setup
In an activated virtual environment:
uv pip install -U agno openai sqlalchemy
export OPENAI_API_KEY="your_api_key"
mkdir -p tmpShared-store ownership
get_memories filters by the current user, but built-in update_memory and delete_memory look up the memory ID without enforcing that user's ownership. Use isolated stores or authorized wrappers for mutations. Disable enable_update_memory and enable_delete_memory when exposing the toolkit to users sharing a store. The example below uses one user's dedicated database.
Example
Here's an example of how to use the MemoryTools toolkit:
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.tools.memory import MemoryTools
# Create a database connection
db = SqliteDb(
db_file="tmp/memory.db"
)
memory_tools = MemoryTools(
db=db,
)
agent = Agent(
model=OpenAIResponses(id="gpt-5.2"),
tools=[memory_tools],
markdown=True,
)
agent.print_response(
"My name is John Doe and I like to hike in the mountains on weekends. "
"I like to travel to new places and experience different cultures. "
"I am planning to travel to Africa in December. ",
user_id="john_doe@example.com",
stream=True
)
# This won't use the session history, but instead will use the memory tools to get the memories
agent.print_response("What have you remembered about me?", stream=True, user_id="john_doe@example.com")Here is how you can configure the toolkit:
from agno.tools.memory import MemoryTools
memory_tools = MemoryTools(
db=db,
enable_think=True, # Enable the think tool (true by default)
enable_get_memories=True, # Enable the get_memories tool (true by default)
enable_add_memory=True, # Enable the add_memory tool (true by default)
enable_update_memory=True, # Enable the update_memory tool (true by default)
enable_delete_memory=True, # Enable the delete_memory tool (true by default)
enable_analyze=True, # Enable the analyze tool (true by default)
add_instructions=True, # Add default instructions
instructions=None, # Optional custom instructions
add_few_shot=True, # Add few-shot examples
few_shot_examples=None, # Optional custom few-shot examples
)