> ## 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 Skill

> Author a grounded, reusable SKILL.md from any source — codebase, API docs, PDFs, configs, or the current chat — in a single command

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(name="Skill Author", instructions="Distil reusable skills from source material.")
agent.learn("Create a deploy-flow skill from this repo and runbook.")
```

Point an agent at real source material and get one grounded `SKILL.md` back — ready to reuse immediately.

The user points the agent at repos or docs; it distils a reusable SKILL.md the team can invoke on later runs.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Learn Skill Flow"
        R[📝 Request] --> G[🔍 Gather sources]
        G --> D[✍️ Distil SKILL.md]
        D --> W[💾 Write via skill_manage]
        W --> S[✅ Reusable skill]
    end

    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff

    class R agent
    class G,D,W,S tool
```

## Quick Start

<Steps>
  <Step title="Agent: learn from sources">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent

    agent = Agent(name="Skill Author", instructions="You learn and write skills.")
    agent.learn("Read ./my-repo and the docs in ./docs/*.pdf and make a 'deploy-flow' skill")
    ```
  </Step>

  <Step title="Bot: /learn slash command">
    Type `/learn` in any PraisonAI bot chat (Telegram, Slack, Discord):

    ```
    /learn deploy steps from this repo and the runbook PDF
    ```

    <Warning>
      `/learn` is **admin-only by default** when a `CommandAccessPolicy` is configured. See [Bot Command Access Control](/docs/features/bot-command-access-control).
    </Warning>
  </Step>

  <Step title="Async and alias variants">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    # Async variant (event-loop friendly)
    await agent.alearn("Read ./my-repo and make a 'ci-deploy' skill")

    # Backward-compatible aliases
    agent.learn("...")          # alias for learn_skill()
    await agent.alearn("...")   # alias for alearn_skill()
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant BuildPrompt as build_learn_prompt
    participant Tools as skill_manage + readers
    participant SkillFile as SKILL.md

    User->>Agent: agent.learn("Read ./my-repo...")
    Agent->>BuildPrompt: build_learn_prompt(request)
    BuildPrompt-->>Agent: grounded authoring directive
    Agent->>Tools: gather named sources (files, PDFs, URLs)
    Tools-->>Agent: source content
    Agent->>Tools: skill_manage(action="create", ...)
    Tools-->>SkillFile: SKILL.md written to disk
    SkillFile-->>Agent: skill name + summary
    Agent-->>User: "Created 'deploy-flow' skill covering..."
```

`Agent.learn_skill()` calls `build_learn_prompt(request)` to build a curated directive, ensures `skill_manage` (and lightweight file/PDF readers) are available via `_ensure_skill_management_tools()`, then invokes `start()` for a single turn.

***

## What the Grounded Prompt Enforces

The internal `build_learn_prompt` function generates a directive with strict house-style rules:

| Rule                          | Detail                                                                                                                                      |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| **Gather only named sources** | Reads local files/directories, PDFs, fetched URLs, or the current chat — only sources the user named                                        |
| **Verbatim accuracy**         | Uses only flags, paths, commands, env vars, and API names that appear verbatim in the gathered sources — never invented                     |
| **Tight `SKILL.md`**          | Keeps the file \~100–200 lines; moves long reference material (large code, full API tables) to supporting files referenced by relative path |
| **YAML frontmatter**          | Must include at least `name` and `description`                                                                                              |
| **Single write**              | Authors one skill via `skill_manage(action="create", name="kebab-case-name", content="...")`                                                |
| **Supporting files**          | Long material goes to separate files via `skill_manage(action="write_file", ...)`                                                           |

***

## Configuration

| Parameter  | Type  | Default  | Description                                                   |
| ---------- | ----- | -------- | ------------------------------------------------------------- |
| `request`  | `str` | required | Description of sources to learn from and the skill to produce |
| `**kwargs` | `Any` | —        | Forwarded to `start()` / `astart()`                           |

`_ensure_skill_management_tools()` adds `skill_manage`, `read_skill_file`, and `list_skill_scripts` to `self.tools` if they are not already present. This is **idempotent** — safe to call multiple times.

***

## Bot Usage

All PraisonAI bot adapters (Telegram, Slack, Discord) register `/learn` via the shared `CommandRegistry`.

```
/learn <sources and skill to make>
```

**Example:**

```
/learn deploy steps from this repo and the runbook PDF
```

**Usage hint** (when called without arguments):

```
ℹ️ Usage: /learn <sources and skill to make>
Example: /learn deploy steps from this repo and the runbook PDF
```

### Admin-Only Default

`/learn` reads host file system sources and authors skills that alter future agent behaviour. It belongs to `PRIVILEGED_COMMANDS` in `CommandAccessPolicy` — it is **admin-only by default** whenever a policy is configured (`admin_users` or `user_allowed_commands` set).

Without any policy configured, `/learn` is available to all users (backward-compatible behaviour).

See [Bot Command Access Control](/docs/features/bot-command-access-control) to configure `admin_users` and grant selective access.

***

## Common Patterns

### Learn from a Codebase

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(name="Skill Author", instructions="You learn and write skills.")
agent.learn("Read ./my-repo and make a 'dev-setup' skill covering the full local dev workflow")
```

### Learn from PDFs + Code

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
agent.learn(
    "Read ./src and the PDF manuals in ./docs/manuals/*.pdf "
    "and make a 'data-ingestion' skill"
)
```

### Learn from the Current Chat

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
agent.learn("Distil what we just did into a 'feature-branch' skill")
```

### Async in an Event Loop

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import asyncio
from praisonaiagents import Agent

async def main():
    agent = Agent(name="Skill Author", instructions="You learn and write skills.")
    await agent.alearn_skill("Read ./docs and make an 'api-reference' skill")

asyncio.run(main())
```

***

## Best Practices

<AccordionGroup>
  <Accordion title="Name skills explicitly">
    Include the target skill name in the request (e.g., `"make a 'deploy-flow' skill"`) so the agent uses that exact kebab-case name rather than deriving one. Consistent names make it easier to invoke and update skills later.
  </Accordion>

  <Accordion title="Scope the sources tightly">
    List only the directories, files, or PDFs the skill should cover. Broad requests like `"read everything"` risk the agent browsing unrelated material or timing out. Narrow sources produce more accurate skills.
  </Accordion>

  <Accordion title="Use alearn_skill in async code">
    In async contexts (FastAPI endpoints, bot handlers), call `await agent.alearn_skill(...)` instead of `agent.learn_skill(...)` to avoid blocking the event loop during potentially long source-gathering turns.
  </Accordion>

  <Accordion title="Check skill_manage availability">
    `learn_skill` auto-adds `skill_manage` if missing, but if you've set `tools=[]` explicitly on the agent, ensure the agent has read access to the source directories too (the `skill_manage` file readers need filesystem access).
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Skill Management" icon="puzzle-piece" href="/docs/features/skill-manage">
    Create, list, read, and delete skills via the skill\_manage tool
  </Card>

  <Card title="Skill Lifecycle" icon="rotate" href="/docs/features/skill-lifecycle">
    How skills are discovered, activated, and applied during agent runs
  </Card>

  <Card title="Bot Commands" icon="terminal" href="/docs/features/bot-commands">
    Full list of built-in bot commands including /learn
  </Card>

  <Card title="Self Improve" icon="chart-line" href="/docs/features/self-improve">
    Automatic skill improvement loop (distinct from one-shot learn\_skill)
  </Card>
</CardGroup>
