Learning Modes

Control when and how agents learn.

Learning modes control when and how a Learning Machine captures information. Each store can use a different mode.

ModeHow it worksTradeoff
AlwaysExtraction runs automatically in the background, without waiting for the response to finishOne extraction call for each enabled Always-mode store
AgenticAgent receives tools and decides what to saveMay miss implicit information
ProposeAgent is instructed to propose learnings and wait for confirmationConfirmation depends on model compliance

Setup

pip install agno openai sqlalchemy "psycopg[binary]" pgvector
export OPENAI_API_KEY="your-api-key"

The examples use a local PostgreSQL database on port 5532. With Docker running, start it using:

Run PgVector

docker run -d \
  -e POSTGRES_DB=ai \
  -e POSTGRES_USER=ai \
  -e POSTGRES_PASSWORD=ai \
  -e PGDATA=/var/lib/postgresql \
  -v pgvolume:/var/lib/postgresql \
  -p 5532:5432 \
  --name pgvector \
  agnohq/pgvector:18

Later configuration fragments reuse the imports and db from the first complete example.

Always Mode

Extraction happens automatically in the background. No agent tools involved.

Extraction starts concurrently with the model call, not after it. It sees the conversation up to the current user message, not the assistant's response or tool calls from that same turn.

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.learn import LearningMachine, LearningMode, UserProfileConfig
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=LearningMachine(
        user_profile=UserProfileConfig(mode=LearningMode.ALWAYS),
    ),
)

# Profile info extracted automatically - no tool calls visible
agent.print_response(
    "I'm Alice Chen, but please call me Ali.",
    user_id="alice@example.com",
)

Best for: User Profile, User Memory, Session Context

Agentic Mode

The agent receives tools and decides when to save.

from agno.learn import LearningMachine, LearningMode, UserProfileConfig

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

# Agent decides to call update_profile tool
agent.print_response(
    "My name is Alice Chen; please call me Ali.",
    user_id="alice@example.com",
)

Best for: Learned Knowledge, Decision Log

Tools by Store

StoreTools
User Profileupdate_profile
User Memoryupdate_user_memory
Entity Memoryremember_about, link_entities, search_entities, forget
Learned Knowledgesearch_learnings, save_learning
Decision Loglog_decision, record_outcome, search_decisions

Propose Mode

The Propose and combined-store examples below require a knowledge object configured using the Learned Knowledge prerequisites.

The agent proposes learnings. The user must confirm before saving.

from agno.learn import LearningMachine, LearningMode, LearnedKnowledgeConfig

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    learning=LearningMachine(
        knowledge=knowledge,
        learned_knowledge=LearnedKnowledgeConfig(mode=LearningMode.PROPOSE),
    ),
)

# Agent proposes, user confirms
agent.print_response(
    "That's a great insight about API rate limits - we should remember that.",
    user_id="alice@example.com",
)

Propose mode is enforced through system prompt instructions, not application code. The save_learning tool stays available throughout the run, so confirmation depends on the agent following its instructions rather than a code-level approval gate.

Note: Propose mode is currently intended for Learned Knowledge.

Do not use Propose mode as the sole approval control for high-stakes, regulated, or compliance-sensitive workflows. Enforce required approval in application code before persisting a learning.

Best for: Low-risk learned knowledge that benefits from prompt-guided review

Combining Modes

Use different modes for different stores:

from agno.learn import (
    LearningMachine,
    LearningMode,
    UserProfileConfig,
    UserMemoryConfig,
    LearnedKnowledgeConfig,
)

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=db,
    learning=LearningMachine(
        knowledge=knowledge,
        user_profile=UserProfileConfig(mode=LearningMode.ALWAYS),     # Automatic
        user_memory=UserMemoryConfig(mode=LearningMode.ALWAYS),       # Automatic
        learned_knowledge=LearnedKnowledgeConfig(mode=LearningMode.AGENTIC),  # Agent-driven
    ),
)

Defaults by Store

StoreDefault modeReason
User ProfileAlwaysNames and preferences should be captured consistently
User MemoryAlwaysObservations accumulate passively
Session ContextAlwaysSession state needs continuous tracking
Entity MemoryAgentic onlyThe agent records entities through its four tools; no extraction pass
Learned KnowledgeAgenticAgent decides what insights are worth saving
Decision LogAgentic onlyBoth DecisionLogConfig() and decision_log=True expose explicit logging tools

Choosing a Mode

ScenarioMode
Capture user names and preferencesAlways
Build user memory automaticallyAlways
Track session progressAlways
Agent-driven knowledge captureAgentic
Build entity knowledge graphsAgentic
Audit agent decisionsAgentic
Prompt-guided review of learned knowledgePropose