Skip to main content
The Learning Machine enables agents to learn from every interaction. Instead of building memory, knowledge, and feedback systems separately, configure one system that handles all learning. The goal: An agent on interaction 1000 is fundamentally better than it was on interaction 1.
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIResponses

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

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    learning=True,  # Enable all learning stores
)

# Session 1
agent.run("I'm Alex, I prefer concise answers.", user_id="[email protected]")

# Session 2 - agent remembers
agent.run("What do you know about me?", user_id="[email protected]")
# -> "You're Alex, you prefer concise answers"

Learning Stores

The Learning Machine coordinates five specialized stores:
StoreWhat It CapturesScope
User ProfileStructured fields (name, preferences)Per user
User MemoryUnstructured observationsPer user
Session ContextGoal, plan, progress, summaryPer session
Entity MemoryFacts, events, relationshipsConfigurable
Learned KnowledgeInsights, patterns, best practicesGlobal

Configuration Levels

from agno.learn import LearningMachine, UserProfileConfig, SessionContextConfig, LearningMode

# Level 1: Dead Simple
agent = Agent(model=model, db=db, learning=True)

# Level 2: Pick What You Want
agent = Agent(
    model=model,
    db=db,
    learning=LearningMachine(
        user_profile=True,
        session_context=True,
        entity_memory=False,
        learned_knowledge=False,
    ),
)

# Level 3: Full Control
agent = Agent(
    model=model,
    db=db,
    learning=LearningMachine(
        user_profile=UserProfileConfig(mode=LearningMode.AGENTIC),
        session_context=SessionContextConfig(enable_planning=True),
    ),
)

Learning Modes

Each store can run in different modes:
ModeBehaviorBest For
ALWAYSAutomatic extraction after each turnUser profiles, session context
AGENTICAgent decides when to saveLearned knowledge
PROPOSEAgent proposes, user confirmsHigh-stakes knowledge

Run the Examples

git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/08_learning

# Setup
./setup_venv.sh

# Run examples
python 01_basics/1a_user_profile_always.py
python 07_patterns/personal_assistant.py