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

# Agent Learning

> Teach your agents to improve over time with the Unified Learning System — capture feedback, corrections, and insights that make your agent smarter.

# Agent Learning

The **Unified Learning System** enables your agents to improve over time. When users provide feedback or corrections, the system captures those insights and applies them to future conversations. Your agent literally learns from its mistakes.

## How It Works

```
User gives feedback     →    Learning captured    →    Agent context enriched
"That's not right,           Insight stored with       Future responses
the return policy is         confidence score          incorporate the
30 days, not 14"             and metadata              corrected information
```

1. **Capture** — A learning is recorded from user feedback, manual input, or automated extraction.
2. **Store** — The insight is saved with metadata (type, confidence, source).
3. **Apply** — On future conversations, relevant learnings are injected into the agent's context.
4. **Validate** — Learnings can be reviewed, confirmed, or invalidated by humans.

## Learning Types

| Type           | Description                              | Source             |
| -------------- | ---------------------------------------- | ------------------ |
| `manual`       | Manually added by a human                | Dashboard or API   |
| `feedback`     | Extracted from user feedback/corrections | User conversation  |
| `conversation` | Derived from conversation patterns       | Automated analysis |
| `correction`   | Direct factual correction                | User interaction   |

## Capturing Learnings

### From the Dashboard

1. Go to your agent's **Learning** tab.
2. Click **Add Learning**.
3. Enter the insight text and select a type.
4. Set the confidence level (0.0 to 1.0).
5. Click **Save**.

You can also capture learnings directly from conversation transcripts:

1. Open a conversation in **Call Logs** or **Chat History**.
2. Highlight a correction or feedback message.
3. Click **Capture as Learning**.

### From User Feedback

When a user provides feedback during a conversation, the system can automatically extract learnings:

```bash theme={null}
curl -X POST https://api.thinnest.ai/learning/capture-feedback \
  -H "Authorization: Bearer $THINNESTAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "agent_abc123",
    "query": "What is the return policy?",
    "original_response": "Our return policy allows returns within 14 days of purchase.",
    "feedback": "Actually, it is 30 days not 14 days. Please update this.",
    "session_id": "session_xyz"
  }'
```

The system extracts the correction and stores it as a learning.

### Manual Capture

```bash theme={null}
curl -X POST https://api.thinnest.ai/learning/capture \
  -H "Authorization: Bearer $THINNESTAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "agent_abc123",
    "insight": "The company holiday hours are 9 AM - 3 PM on December 24 and 31. The office is fully closed on December 25 and January 1.",
    "learning_type": "manual",
    "confidence": 1.0,
    "metadata": {
      "source": "HR department",
      "valid_until": "2027-01-02"
    }
  }'
```

## Listing Learnings

### From the Dashboard

The **Learning** tab shows all learnings for an agent with:

* Insight text
* Type and confidence
* Status (active or invalidated)
* Creation date
* Source metadata

### Via the API

```bash theme={null}
curl "https://api.thinnest.ai/learning/list?agent_id=agent_abc123&status=active&sort=created_at" \
  -H "Authorization: Bearer $THINNESTAI_API_KEY"
```

### Query Parameters

| Parameter  | Type   | Default       | Description                                  |
| ---------- | ------ | ------------- | -------------------------------------------- |
| `agent_id` | string | Required      | Agent ID                                     |
| `type`     | string | null          | Filter by learning type                      |
| `status`   | string | "active"      | Filter by status ("active" or "invalidated") |
| `sort`     | string | "created\_at" | Sort field                                   |

### Response

```json theme={null}
{
  "learnings": [
    {
      "id": 1,
      "agent_id": 42,
      "insight": "Return policy is 30 days, not 14 days",
      "learning_type": "feedback",
      "confidence": 0.95,
      "status": "active",
      "metadata": {
        "original_query": "What is the return policy?",
        "session_id": "session_xyz"
      },
      "created_at": "2026-03-06T10:30:00Z"
    }
  ]
}
```

## Learning Statistics

Get aggregate statistics about an agent's learnings:

```bash theme={null}
curl "https://api.thinnest.ai/learning/stats?agent_id=agent_abc123" \
  -H "Authorization: Bearer $THINNESTAI_API_KEY"
```

```json theme={null}
{
  "total": 47,
  "active": 42,
  "invalidated": 5,
  "by_type": {
    "manual": 12,
    "feedback": 25,
    "conversation": 8,
    "correction": 2
  },
  "avg_confidence": 0.87
}
```

## Managing Learnings

### Invalidate a Learning

If a learning is incorrect or outdated, invalidate it so it's no longer applied:

```bash theme={null}
curl -X PATCH https://api.thinnest.ai/learning/1/invalidate \
  -H "Authorization: Bearer $THINNESTAI_API_KEY"
```

### Delete a Learning

```bash theme={null}
curl -X DELETE https://api.thinnest.ai/learning/1 \
  -H "Authorization: Bearer $THINNESTAI_API_KEY"
```

### Get a Single Learning

```bash theme={null}
curl https://api.thinnest.ai/learning/1 \
  -H "Authorization: Bearer $THINNESTAI_API_KEY"
```

## How Learnings Are Applied

When an agent receives a message, the system:

1. Searches for relevant active learnings based on the conversation context.
2. Injects matching learnings into the agent's system prompt as additional context.
3. The agent uses this enriched context to formulate its response.

This happens automatically — no configuration needed beyond capturing the learnings.

### Prompt Injection Protection

The learning system includes built-in protection against prompt injection. Learnings are sanitized before being injected into the agent context, preventing malicious users from manipulating the agent through crafted feedback.

## Best Practices

* **Review feedback-based learnings** — Automated extraction isn't perfect. Periodically review and confirm learnings.
* **Set appropriate confidence levels** — Higher confidence (0.9+) for verified facts, lower (0.5-0.7) for inferred patterns.
* **Invalidate rather than delete** — Invalidation preserves the learning history for auditing.
* **Use metadata** — Add source information, expiration dates, and context to learnings for better organization.
* **Monitor learning stats** — A high volume of corrections may indicate your base prompt needs updating.
* **Combine with knowledge sources** — Learnings are for dynamic corrections. Stable information should go in knowledge sources.
* **Pair with Dash** — The [Dash (Self-Learning DB)](/docs/tools/dash) tool has its own SQL-specific learning system that complements platform learnings. Dash learns query patterns and error corrections, while Agent Learning captures conversation-level feedback.
