Skip to main content
Agent Learn enables agents to capture and recall patterns, preferences, and insights from interactions, improving future responses through persistent learning stores.

Quick Start

1

Simple Shorthand (Recommended)

The easiest way to enable Agent Learn:
from praisonaiagents import Agent

agent = Agent(
    name="Learning Agent",
    instructions="You are a helpful assistant that learns from interactions",
    memory="learn"  # Simple shorthand for enabling learn
)

agent.start("What's my preferred coding style?")
memory="learn" is equivalent to memory=MemoryConfig(learn=True) but much simpler.
2

Explicit Configuration

For more control over the memory backend:
from praisonaiagents import Agent, MemoryConfig

agent = Agent(
    name="Learning Agent",
    instructions="You are a helpful assistant that learns from interactions",
    memory=MemoryConfig(learn=True)
)

agent.start("What's my preferred coding style?")
3

With Specific Capabilities

from praisonaiagents import Agent, MemoryConfig, LearnConfig

agent = Agent(
    name="Learning Agent",
    instructions="You learn and adapt to user preferences",
    memory=MemoryConfig(
        learn=LearnConfig(
            persona=True,      # User preferences
            insights=True,     # Observations
            patterns=True,     # Reusable knowledge
            decisions=True,    # Decision logging
        )
    )
)
4

All 7 Stores (Full Learning)

from praisonaiagents import Agent

# Enable all 7 learning stores for comprehensive learning
agent = Agent(
    name="Full Learning Agent",
    instructions="You are a comprehensive learner",
    memory={
        "backend": "file",
        "learn": {
            "persona": True,       # User preferences & profile
            "insights": True,      # Observations & learnings
            "thread": True,        # Session context
            "patterns": True,      # Reusable knowledge
            "decisions": True,     # Decision rationale
            "feedback": True,      # Outcome signals
            "improvements": True,  # Self-improvement proposals
        }
    }
)

How It Works

Auto-Injection: When memory="learn" is enabled, learned context is automatically injected into the agent’s system prompt before each response. No manual wiring needed!
PhaseDescription
Retrieveget_learn_context() fetches learnings from all enabled stores
Auto-InjectContext automatically added to system prompt as “Learned Context” section
GenerateAgent uses learned context to personalize response
PersistLearnings stored in JSON files for cross-session persistence

What Gets Injected

When memory="learn" is enabled, the agent’s system prompt automatically includes a “Learned Context” section with:
## Learned Context

### User Persona
- Prefers dark mode and vim keybindings
- Senior developer working on Python projects

### Insights  
- User values concise, technical responses
- Prefers code examples over lengthy explanations

### Patterns
- Common workflow: test → implement → refactor
- Prefers pytest over unittest

### Decisions
- Chose PostgreSQL over MySQL for type safety
- Selected FastAPI for async performance

### Feedback
- Positive: step-by-step debugging approach
- Improvement: add more context in error messages

### Improvements
- Consider caching frequent queries
- Add retry logic for API calls
Each section only appears if the corresponding store is enabled AND contains data. Thread context is excluded from injection as it’s session-specific.

Learning Stores

Agent Learn organizes knowledge into specialized stores:
StorePurposeDefault
personaUser preferences, communication style, profileTrue
insightsObservations and learnings from interactionsTrue
threadSession and conversation contextTrue
patternsReusable knowledge patternsFalse
decisionsDecision logging and rationaleFalse
feedbackOutcome signals and correctionsFalse
improvementsSelf-improvement proposalsFalse

Configuration Options

from praisonaiagents import LearnConfig

config = LearnConfig(
    # Learning capabilities
    persona=True,           # User preferences and profile
    insights=True,          # Observations and learnings
    thread=True,            # Session/conversation context
    patterns=False,         # Reusable knowledge patterns
    decisions=False,        # Decision logging
    feedback=False,         # Outcome signals
    improvements=False,     # Self-improvement proposals
    
    # Scope configuration
    scope="private",        # "private" or "shared"
    
    # Storage
    store_path=None,        # Custom storage path
    
    # Maintenance
    auto_consolidate=True,  # Auto-consolidate learnings
    retention_days=None,    # Days to retain (None = forever)
)
OptionTypeDefaultDescription
personaboolTrueCapture user preferences and profile
insightsboolTrueStore observations and learnings
threadboolTrueMaintain session context
patternsboolFalseStore reusable knowledge patterns
decisionsboolFalseLog decisions with rationale
feedbackboolFalseCapture outcome signals
improvementsboolFalseTrack self-improvement proposals
scopestr"private"Learning visibility: "private" or "shared"
store_pathstrNoneCustom storage directory
auto_consolidateboolTrueAutomatically consolidate learnings
retention_daysintNoneDays to retain entries (None = forever)

CLI Commands

Manage learning data via the command line:

Show Status

praisonai memory learn status --user-id default

Show Learned Entries

# Show all stores
praisonai memory learn show all --limit 10

# Show specific store
praisonai memory learn show persona --user-id default

Add Learning Entry

# Add to insights store
praisonai memory learn add "User prefers concise responses" --store insights

# Add to persona store
praisonai memory learn add "Prefers Python over JavaScript" --store persona

Search Learnings

praisonai memory learn search "coding style" --limit 5

Clear Learnings

# Clear all stores
praisonai memory learn clear all --force

# Clear specific store
praisonai memory learn clear persona --user-id default

Common Patterns

Personal Assistant with Memory

from praisonaiagents import Agent, MemoryConfig, LearnConfig

agent = Agent(
    name="Personal Assistant",
    instructions="You are a personal assistant that remembers user preferences",
    memory=MemoryConfig(
        backend="sqlite",
        user_id="user123",
        learn=LearnConfig(
            persona=True,
            insights=True,
            patterns=True,
        )
    )
)

# First interaction
agent.start("I prefer dark mode and vim keybindings")

# Later interaction - agent remembers preferences
agent.start("Set up my development environment")

Team Knowledge Base

from praisonaiagents import Agent, MemoryConfig, LearnConfig

agent = Agent(
    name="Team Knowledge Agent",
    instructions="You help the team by learning from shared experiences",
    memory=MemoryConfig(
        learn=LearnConfig(
            scope="shared",      # Share learnings across team
            patterns=True,       # Capture reusable patterns
            decisions=True,      # Log architectural decisions
            improvements=True,   # Track improvement proposals
        )
    )
)

Feedback-Driven Learning

from praisonaiagents import Agent, MemoryConfig, LearnConfig

agent = Agent(
    name="Adaptive Agent",
    instructions="You improve based on feedback",
    memory=MemoryConfig(
        learn=LearnConfig(
            feedback=True,       # Capture outcome signals
            improvements=True,   # Track self-improvement
            auto_consolidate=True,
        )
    )
)

Best Practices

Keep scope="private" (default) when storing user-specific preferences or sensitive information. Use scope="shared" only for team knowledge that should benefit all agents.
Start with the default stores (persona, insights, thread) and enable additional stores (patterns, decisions, feedback, improvements) as your use case requires them.
Use retention_days for stores that capture temporal patterns. Thread context often benefits from 7-30 day retention to avoid clutter.
Keep auto_consolidate=True to automatically merge and summarize learnings over time, preventing store bloat.