Learn (Continuous Learning)

Let your agent capture and reuse insights, patterns, and user preferences across conversations

Make your agent smarter over time — it learns from every conversation and applies those insights automatically.

Python

python
from praisonaiagents import Agent

agent = Agent(
    name="LearningAssistant",
    instructions="You are a helpful personal assistant.",
    learn=True  # Agent captures and reuses learnings automatically
)

result = agent.start("I prefer concise bullet points over long paragraphs")
print(result)

TypeScript

typescript
import { Agent } from 'praisonai';

const agent = new Agent({
  name: 'LearningAssistant',
  instructions: 'You are a helpful personal assistant.',
  learn: true, // Agent captures and reuses learnings automatically
});

const result = await agent.start('I prefer concise bullet points over long paragraphs');
console.log(result);

The user shares preferences in chat; the agent stores learnings and applies them on the next turn.

Diagram

Learning Loop

💬 Conversation

🧠 Extract\nInsights

🗄️ Store in\nMemory

📚 Recall in\nNext Conv

✅ Better\nResponse

Quick Start

  1. Simple Usage

    Enable learning with a boolean — the agent captures persona and insights by default:

    python
    from praisonaiagents import Agent
    
    agent = Agent(
        name="PersonalAssistant",
        instructions="You are my personal assistant.",
        learn=True
    )
    
    agent.start("Remember: I always want responses in markdown format")
  2. With LearnConfig

    Choose what to learn and how to store it:

    python
    from praisonaiagents import Agent, LearnConfig
    
    agent = Agent(
        instructions="You are a helpful assistant.",
        learn=LearnConfig(
            persona=True,
            insights=True,
            patterns=True,
            mode="agentic",
        ),
    )
    agent.start("I work in finance and need data-focused answers.")
  3. With Database Backend
    python
    from praisonaiagents import Agent, LearnConfig
    
    agent = Agent(
        instructions="You are a helpful assistant.",
        learn=LearnConfig(
            backend="sqlite",
            db_url="sqlite:///learn.db",
            mode="agentic",
        ),
    )
    agent.start("My team prefers Python over JavaScript for all scripts.")

How It Works

Diagram
LearnAgentUserLearnAgentUserFuture sessions recall stored patternsMessage with preference or insightExtract learnable contentStored learning IDResponse (adapted to learnings)
PhaseWhat happens
1. ConversationUser interacts with the agent normally
2. ExtractAgent identifies persona, insights, and patterns
3. StoreLearnings saved to the configured backend
4. ApplyFuture responses adapt based on stored learnings

Learning Modes

Diagram

Disabled

Agentic

Which mode?

Manual only\nno auto-extract

Auto-extract after\neach conversation


Configuration Options

LearnConfig SDK Reference

Full parameter reference for LearnConfig

Precedence ladder:

python
# Level 1: Bool (enable with defaults)
agent = Agent(learn=True)

# Level 2: LearnConfig (full control)
agent = Agent(learn=LearnConfig(
    persona=True,
    mode="agentic",
    backend="sqlite",
))

What the agent can learn:

OptionTypeDefaultDescription
personaboolTrueUser preferences and profile
insightsboolTrueObservations from conversations
threadboolTrueSession/conversation context
patternsboolFalseReusable knowledge patterns
decisionsboolFalseLog decisions made
feedbackboolFalseCapture outcome signals
improvementsboolFalseSelf-improvement proposals

Learning mode:

OptionTypeDefaultDescription
modestr"disabled""disabled" / "agentic" / "propose" (see note)
scopestr"private""private" (per user) or "shared" (all agents)
nudge_intervalint0Nudge agent to reflect every N turns (0 = off)

Storage backend:

OptionTypeDefaultDescription
backendstr"file""file" / "sqlite" / "redis" / "mongodb"
db_url`str \None`NoneConnection URL for non-file backends
store_path`str \None`NoneCustom path for file backend
max_entriesint0Max stored entries (0 = unlimited)
retention_daysint0Archive entries older than N days (0 = keep forever)
llm`str \None`NoneLLM model for extracting learnings
Card

Full list of options, types, and defaults — LearnConfig

OptionTypeDefaultDescription
personaboolTrueCapture user preferences and profile
insightsboolTrueStore observations and learnings
threadboolTrueTrack session/conversation context
patternsboolFalseReusable knowledge patterns
decisionsboolFalseDecision logging
feedbackboolFalseOutcome signals
improvementsboolFalseSelf-improvement proposals
modestr"disabled""disabled" or "agentic"
scopestr"private""private" or "shared"
backendstr"file""file", "sqlite", "redis", "mongodb"
db_url`str \None`NoneDatabase connection URL
store_path`str \None`NoneCustom file storage path
max_entriesint0Per-store cap (0 = unbounded)
retention_daysint0Archive stale entries after N days (0 = never)
llm`str \None`NoneLLM for extracting learnings
nudge_intervalint0Nudge every N turns (0 = disabled)

Common Patterns

Pattern 1 — Persona learning for personalized responses

python
from praisonaiagents import Agent, LearnConfig

agent = Agent(
    name="PersonalCoach",
    instructions="You are a personal productivity coach.",
    learn=LearnConfig(
        persona=True,
        insights=True,
        patterns=True,
        mode="agentic",
        backend="sqlite",
        db_url="sqlite:///coach_memory.db",
    )
)

# The agent builds a profile of you over time
agent.start("I struggle with time management in the mornings")
agent.start("I prefer evening workouts")
agent.start("What routine would work best for me?")

Shared learning across agents:

python
from praisonaiagents import Agent, LearnConfig

shared_learn = LearnConfig(
    insights=True,
    patterns=True,
    scope="shared",  # All agents share this learning store
    backend="redis",
    db_url="redis://localhost:6379",
)

agent1 = Agent(name="SupportAgent1", instructions="Handle customer support.", learn=shared_learn)
agent2 = Agent(name="SupportAgent2", instructions="Handle customer support.", learn=shared_learn)

Nudge-based self-improvement:

instructions=”You are a writing assistant.”, learn=LearnConfig(persona=True, insights=True, mode=”agentic”), ) response = agent.start(“I prefer formal British English in all my documents.”) print(response)

### Pattern 2 — Shared patterns across agents
```python
from praisonaiagents import Agent, LearnConfig

agent = Agent(
    name="ImprovingAgent",
    instructions="You are a coding assistant that gets better over time.",
    learn=LearnConfig(
        improvements=True,
        nudge_interval=5,  # Reflect and propose improvements every 5 turns
        nudge_min_tool_iters=3,  # Only nudge if agent did real work
    )
)

Concurrency safety

The file backend is built on BaseJSONStore, whose file lock now tolerates long critical sections. Concurrent agent.remember(...) and autosave paths across multiple agents or processes will not clobber each other’s learnings even if a save legitimately takes longer than the lock timeout, thanks to the mtime + heartbeat staleness rule. See Thread Safety for details (PR #5136).


Best Practices

Start with learn=True, then tune

The default settings (persona=True, insights=True) cover most use cases. Only add patterns=True or decisions=True when you need those specific learning types — they add overhead per turn.

Use sqlite or redis for production

The default file backend is great for development and local agents. For production, switch to sqlite (single-node) or redis/mongodb (multi-node or high throughput).

Set max_entries to prevent unbounded growth

For long-lived agents, set max_entries (e.g., max_entries=1000) and retention_days (e.g., retention_days=30) to prevent the learning store from growing indefinitely.

Use scope='shared' carefully

Shared learning means all agents read and write to the same store. This is powerful for multi-agent coordination but can cause unexpected behavior if different agents learn conflicting patterns.


Related