> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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)
```

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

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Learning Loop"
        CONV["💬 Conversation"] --> EXTRACT["🧠 Extract\nInsights"]
        EXTRACT --> STORE["🗄️ Store in\nMemory"]
        STORE --> RECALL["📚 Recall in\nNext Conv"]
        RECALL --> BETTER["✅ Better\nResponse"]
    end

    classDef input fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef storage fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef success fill:#10B981,stroke:#7C90A0,color:#fff

    class CONV input
    class EXTRACT process
    class STORE storage
    class RECALL,BETTER success
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    Enable learning with a boolean — the agent captures persona and insights by default:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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")
    ```
  </Step>

  <Step title="With LearnConfig">
    Choose what to learn and how to store it:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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.")
    ```
  </Step>

  <Step title="With Database Backend">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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.")
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Learn

    User->>Agent: Message with preference or insight
    Agent->>Learn: Extract learnable content
    Learn-->>Agent: Stored learning ID
    Agent-->>User: Response (adapted to learnings)
    Note over Learn: Future sessions recall stored patterns
```

| 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

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    Q{Which mode?}
    Q -->|Disabled| D[Manual only\nno auto-extract]
    Q -->|Agentic| A[Auto-extract after\neach conversation]

    classDef decision fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef option fill:#6366F1,stroke:#7C90A0,color:#fff

    class Q decision
    class D,A option
```

<Note>
  `mode="propose"` is defined in the SDK but not yet implemented — it behaves the same as `disabled` until the approval workflow is added. Do not use it in production.
</Note>

***

## Configuration Options

<Card title="LearnConfig SDK Reference" icon="code" href="/docs/sdk/reference/python/classes/LearnConfig">
  Full parameter reference for LearnConfig
</Card>

**Precedence ladder:**

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# 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)      |

<Note>
  `propose` mode is defined in the SDK but not yet implemented. Setting `mode="propose"` currently behaves the same as `"disabled"`.
</Note>

**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                   |

<Card icon="code" href="/docs/sdk/reference/python/LearnConfig">
  Full list of options, types, and defaults — `LearnConfig`
</Card>

| 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

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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
    )
)
````

***

## Best Practices

<AccordionGroup>
  <Accordion title="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.
  </Accordion>

  <Accordion title="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).
  </Accordion>

  <Accordion title="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.
  </Accordion>

  <Accordion title="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.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Learning Retention" icon="brain" href="/docs/features/learning-retention">
    How learned data persists between sessions
  </Card>

  <Card title="Advanced Memory" icon="database" href="/docs/features/advanced-memory">
    Full memory system configuration
  </Card>

  <Card title="Learn Skill" icon="graduation-cap" href="/docs/features/learn-skill">
    Agent skill learning system
  </Card>

  <Card title="Self Improve" icon="sparkles" href="/docs/features/self-improve">
    Agent self-improvement mechanisms
  </Card>
</CardGroup>
