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
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
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.
Quick Start
- 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") - 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.") - 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
| Phase | What happens |
|---|---|
| 1. Conversation | User interacts with the agent normally |
| 2. Extract | Agent identifies persona, insights, and patterns |
| 3. Store | Learnings saved to the configured backend |
| 4. Apply | Future responses adapt based on stored learnings |
Learning Modes
Configuration Options
LearnConfig SDK ReferenceFull parameter reference for LearnConfig
Precedence ladder:
# 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:
| Option | Type | Default | Description |
|---|---|---|---|
persona | bool | True | User preferences and profile |
insights | bool | True | Observations from conversations |
thread | bool | True | Session/conversation context |
patterns | bool | False | Reusable knowledge patterns |
decisions | bool | False | Log decisions made |
feedback | bool | False | Capture outcome signals |
improvements | bool | False | Self-improvement proposals |
Learning mode:
| Option | Type | Default | Description |
|---|---|---|---|
mode | str | "disabled" | "disabled" / "agentic" / "propose" (see note) |
scope | str | "private" | "private" (per user) or "shared" (all agents) |
nudge_interval | int | 0 | Nudge agent to reflect every N turns (0 = off) |
Storage backend:
| Option | Type | Default | Description | |
|---|---|---|---|---|
backend | str | "file" | "file" / "sqlite" / "redis" / "mongodb" | |
db_url | `str \ | None` | None | Connection URL for non-file backends |
store_path | `str \ | None` | None | Custom path for file backend |
max_entries | int | 0 | Max stored entries (0 = unlimited) | |
retention_days | int | 0 | Archive entries older than N days (0 = keep forever) | |
llm | `str \ | None` | None | LLM model for extracting learnings |
Full list of options, types, and defaults — LearnConfig
| Option | Type | Default | Description | |
|---|---|---|---|---|
persona | bool | True | Capture user preferences and profile | |
insights | bool | True | Store observations and learnings | |
thread | bool | True | Track session/conversation context | |
patterns | bool | False | Reusable knowledge patterns | |
decisions | bool | False | Decision logging | |
feedback | bool | False | Outcome signals | |
improvements | bool | False | Self-improvement proposals | |
mode | str | "disabled" | "disabled" or "agentic" | |
scope | str | "private" | "private" or "shared" | |
backend | str | "file" | "file", "sqlite", "redis", "mongodb" | |
db_url | `str \ | None` | None | Database connection URL |
store_path | `str \ | None` | None | Custom file storage path |
max_entries | int | 0 | Per-store cap (0 = unbounded) | |
retention_days | int | 0 | Archive stale entries after N days (0 = never) | |
llm | `str \ | None` | None | LLM for extracting learnings |
nudge_interval | int | 0 | Nudge every N turns (0 = disabled) |
Common Patterns
Pattern 1 — Persona learning for personalized responses
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:
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.