Skip to main content
Agno provides a powerful memory system that enables agents to remember information about users across sessions. This allows you to build personalized AI experiences that improve over time.

What is Memory?

Memory in Agno allows agents to:
  • Store and retrieve user preferences and personal information
  • Maintain context across multiple conversations and sessions
  • Build personalized experiences based on past interactions
  • Share memories across multiple agents working with the same user

Key Components

MemoryManager

The MemoryManager is responsible for creating, updating, and retrieving user memories. It uses an LLM to intelligently extract and manage memories from conversations.
from agno.memory import MemoryManager
from agno.db.postgres import PostgresDb

memory_manager = MemoryManager(
    db=PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")
)

UserMemory

UserMemory objects represent individual memories stored in the database:
from agno.db.schemas import UserMemory

memory = UserMemory(
    memory="User's name is John Doe",
    topics=["name"],
    user_id="[email protected]"
)

Memory Workflow

1
Enable Memory on Agent
2
Set update_memory_on_run=True to automatically create memories from conversations:
3
from agno.agent import Agent
from agno.db.postgres import PostgresDb

agent = Agent(
    db=PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
    update_memory_on_run=True,
)
4
Interact with Users
5
As users interact with your agent, memories are automatically created:
6
agent.print_response(
    "My name is John Doe and I like hiking in the mountains",
    user_id="[email protected]"
)
7
Retrieve Memories
8
Memories are automatically added to the agent’s context in future conversations:
9
# Agent will remember the user's name and hobbies
agent.print_response(
    "What are my hobbies?",
    user_id="[email protected]"
)

Memory Storage

Memories are stored in a database and associated with:
  • user_id: Identifies which user the memory belongs to
  • agent_id: Which agent created the memory (optional)
  • team_id: Which team created the memory (optional)
  • topics: Categories or tags for the memory
  • updated_at: Timestamp of the last update

Multi-User Support

Agno’s memory system supports multiple users, with memories isolated by user_id:
# User 1's memories
agent.print_response(
    "My name is Alice",
    user_id="[email protected]"
)

# User 2's memories (completely separate)
agent.print_response(
    "My name is Bob",
    user_id="[email protected]"
)

Memory Optimization

As conversations grow, you may need to optimize memories to reduce token usage. Agno provides optimization strategies:
from agno.memory.strategies.types import MemoryOptimizationStrategyType

memory_manager.optimize_memories(
    user_id="[email protected]",
    strategy=MemoryOptimizationStrategyType.SUMMARIZE,
    apply=True
)
See User Memories for detailed usage and Session State for managing conversation history.

Next Steps

User Memories

Learn how to create, retrieve, and manage user memories

Session State

Manage conversation history and session summaries

Storage Overview

Choose the right database for your application

Database Adapters

Configure PostgreSQL, MongoDB, Redis, and more

Build docs developers (and LLMs) love