Skip to main content
The basic memory setup covers most use cases, but sometimes you need more control. This guide covers advanced patterns for customizing memory behavior, controlling what gets stored, and building complex multi-agent systems with shared memory.

Customizing the Memory Manager

The MemoryManager controls which LLM creates and updates memories, plus how those memories are generated. You can customize it to use a specific model, add privacy rules, or change how memories are extracted:
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.memory import MemoryManager
from agno.models.openai import OpenAIChat

# Setup your database
db = SqliteDb(db_file="agno.db")

# Setup your Memory Manager, to adjust how memories are created
memory_manager = MemoryManager(
    db=db,
    # Select the model used for memory creation and updates. If unset, the default model of the Agent is used.
    model=OpenAIChat(id="gpt-5-mini"),
    # You can also provide additional instructions
    additional_instructions="Don't store the user's real name",
)

# Now provide the adjusted Memory Manager to your Agent
agent = Agent(
    db=db,
    memory_manager=memory_manager,
    enable_user_memories=True,
)

agent.print_response("My name is John Doe and I like to play basketball on the weekends.")

agent.print_response("What's do I do in weekends?")
In this example, the memory manager will store memories about hobbies, but won’t include the user’s actual name. This is useful for healthcare, legal, or other privacy-sensitive applications.

Memories and Context

When enabled, memories about the current user are automatically added to the agent’s context on each request. But in some scenarios, like when you’re building analytics on memories or want the agent to explicitly search for memories using tools, you might want to store memories without auto-including them. Use add_memories_to_context=False to collect memories in the background while keeping the agent’s context lean:
from agno.agent import Agent
from agno.db.sqlite import SqliteDb

# Setup your database
db = SqliteDb(db_file="agno.db")

# Setup your Agent with Memory
agent = Agent(
    db=db,
    enable_user_memories=True, # This enables Memory for the Agent
    add_memories_to_context=False, # This disables adding memories to the context
)

Using Memory Tools

Instead of automatic memory management, you can give your agent explicit tools to create, retrieve, update, and delete memories. This approach gives the agent more control and reasoning ability, so it can decide when to store something versus when to search for existing memories. When to use Memory Tools:
  • You want the agent to reason about whether something is worth remembering
  • You need fine-grained control over memory operations (create, update, delete separately)
  • You’re building a system where the agent should explicitly search memories rather than having them auto-loaded
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIChat
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=OpenAIChat(id="gpt-5-mini"),
    tools=[memory_tools],
    markdown=True,
)

if __name__ == "__main__":
    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")
See the Memory Tools documentation for more details.

Sharing Memory Between Agents

In multi-agent systems, you often want agents to share knowledge about users. For example, a support agent might learn a user’s preferences, and a sales agent should be aware of them too. This is simple in Agno: just connect multiple agents to the same database.
from agno.agent import Agent
from agno.db.sqlite import SqliteDb

# Setup your database
db = SqliteDb(db_file="agno.db")

# Setup your Agents with the same database and Memory enabled
agent_1 = Agent(db=db, enable_user_memories=True)
agent_2 = Agent(db=db, enable_user_memories=True)

# The first Agent will create a Memory about the user name here:
agent_1.print_response("Hi! My name is John Doe")

# The second Agent will be able to retrieve the Memory about the user name here:
agent_2.print_response("What is my name?")
All agents connected to the same database automatically share memories for each user. This works across agent types, teams, and workflows, as long as they use the same user_id.
I