Skip to main content
The User Memory Store captures unstructured observations about users - preferences, behaviors, and context that don’t fit into structured profile fields.

Overview

AspectDetails
Data TypeUnstructured text observations
ScopePer user (identified by user_id)
PersistenceLong-term (with optional curation)
Default ModeALWAYS
Supported ModesALWAYS, AGENTIC

Basic Usage

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.learn import LearningMachine, UserMemoryConfig
from agno.models.openai import OpenAIResponses

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
    learning=LearningMachine(
        user_memory=True,
    ),
)

# Session 1: Share preferences
agent.print_response(
    "I prefer code examples over explanations. Also, I'm working on a machine learning project.",
    user_id="[email protected]",
    session_id="session_1",
)

# Session 2: Memory is recalled
agent.print_response(
    "Explain async/await in Python",
    user_id="[email protected]",
    session_id="session_2",
)
# Agent knows to include code examples and may relate to ML context

ALWAYS Mode (Default)

Memories are extracted automatically after each conversation:
from agno.learn import LearningMachine, LearningMode, UserMemoryConfig

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    learning=LearningMachine(
        user_memory=UserMemoryConfig(
            mode=LearningMode.ALWAYS,
        ),
    ),
)

AGENTIC Mode

The agent gets tools to manage memories explicitly:
from agno.learn import LearningMachine, LearningMode, UserMemoryConfig

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    learning=LearningMachine(
        user_memory=UserMemoryConfig(
            mode=LearningMode.AGENTIC,
        ),
    ),
)

# Agent can call save_user_memory and delete_user_memory tools
agent.print_response(
    "Remember that I always want to see error handling in code examples.",
    user_id="[email protected]",
)
Available tools:
  • save_user_memory - Store a new observation
  • delete_user_memory - Remove an outdated memory

What Gets Captured

User Memory is designed for observations that don’t fit structured fields:
Good for User MemoryBetter for User Profile
”Prefers detailed explanations”Name: “Alice Chen"
"Working on ML project”Company: “Acme Corp"
"Struggles with async code”Role: “Data Scientist"
"Uses VS Code”Timezone: “PST"
"Morning person”Plan: “Enterprise”

Memory Data Model

Each memory contains:
FieldTypeDescription
memory_idstrUnique identifier
memorystrThe observation text
topicslistExtracted topics for categorization
user_idstrUser this memory belongs to
created_atdatetimeWhen the memory was created
updated_atdatetimeLast update timestamp

Accessing Memories

# Get all memories for a user
learning = agent.get_learning_machine()
memories = learning.user_memory_store.get_memories(user_id="[email protected]")

for memory in memories:
    print(f"- {memory.memory}")

# Debug output
learning.user_memory_store.print(user_id="[email protected]")

Context Injection

Relevant memories are injected into the agent’s context:
<user_memories>
- Prefers code examples over explanations
- Working on a machine learning project
- Uses Python 3.11
- Prefers concise responses
</user_memories>

Memory Limits

By default, the most recent/relevant memories are included in context. Configure limits:
from agno.learn import LearningMachine, UserMemoryConfig

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    learning=LearningMachine(
        user_memory=UserMemoryConfig(
            max_memories=10,  # Limit memories in context
        ),
    ),
)

Memory Curation

Over time, memories can accumulate. Use the Curator to maintain them:
learning = agent.get_learning_machine()

# Remove old memories
learning.curator.prune(user_id="[email protected]", max_age_days=90)

# Remove duplicates
learning.curator.deduplicate(user_id="[email protected]")

Combining with User Profile

Use both stores together for comprehensive user understanding:
from agno.learn import LearningMachine, UserProfileConfig, UserMemoryConfig

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    learning=LearningMachine(
        user_profile=UserProfileConfig(),  # Structured: name, company
        user_memory=UserMemoryConfig(),    # Unstructured: preferences, context
    ),
)

Example: Personal Assistant

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.learn import LearningMachine, UserMemoryConfig, UserProfileConfig
from agno.models.openai import OpenAIResponses

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
    learning=LearningMachine(
        user_profile=True,
        user_memory=UserMemoryConfig(max_memories=20),
    ),
    instructions="""You are a personal assistant. Use what you know about
    the user to provide personalized, relevant responses.""",
)

# Over time, the assistant learns:
# - Profile: Name, timezone, role
# - Memories: Preferences, ongoing projects, communication style