# Skills

Polyant has three skill surfaces: the per-agent **Skills** section (covered first), the **organization's catalogue**, and the **platform catalogue** in the Admin Console.

A skill is owned by **an organization or by the platform** - never by the deployment at large. Two organizations on the same engine keep separate catalogues.

## Per-agent Skills section

The **Skills** section of an agent (its *Resources* group) is where you attach skills from the catalogue to that agent.

### What you see

One table, **Name**, **Category** and **Active**, of every skill the organization can see - its own, plus any the platform has granted it - sorted by name, with a search box above it. A row shows the skill's name with its description under it (at most two lines, the whole text on hover), its pinned version (`v0.3.0`) and **Update available** when the catalogue has a newer one, and its **Active** switch. Click a row to open the skill in a side panel: its required variables (**Configure *name***), its required tools, **Auto Load** (inject the skill's content straight into the system prompt) and **Upgrade**. Switching a skill on or off is a draft until you click the page's **Save**. With managed services a banner counts the enabled skills this workspace does not carry, which stay out of the prompt.

### Enabling a skill

Toggling a skill **on** does three things:

1. Inserts a row in `instance_skills` linking this agent to that skill.
2. Pins the **current version** of the skill (semantic versioning). Future bumps to the global skill do not auto-apply - you upgrade explicitly.
3. Recomputes the per-agent tool set: tools declared as `skillTools` for this skill become enabled.

### Configuring environment variables

Skills can declare required environment variables in their YAML frontmatter:

```yaml
---
name: hubspot
description: HubSpot CRM operations
requiredEnv:
  - name: HUBSPOT_API_KEY
    description: HubSpot private app token (Bearer)
    sensitive: true
  - name: HUBSPOT_PORTAL_ID
    description: Numeric portal id, used in deep links
    sensitive: false
---
```

For each enabled skill, open its panel: the **Configure *name*** section has one row per `requiredEnv` entry, and a disabled skill says to turn it on first. Sensitive entries hide the value behind a password input; non-sensitive entries show in clear text.

Values are stored per agent and skill. Sensitive entries are encrypted at rest with **AES-256-GCM** using the engine's `ENCRYPTION_KEY`; `readSkill` shows only `{{skill_env.<skill>.<KEY>}}`, and the runtime resolves that placeholder immediately before an eligible in-process tool executes. The engine records the placeholder in tool and audit arguments. Non-sensitive settings may remain visible, and `runSkillScript` receives its environment only in the child process when the script runs. A tool that returns a resolved value, or a script that prints one, can still expose it in its result.

### Versioning and pinning

Skills are versioned (e.g. `0.4.0`). When the catalogue ships a new version, the row says **Update available**, and you have to **explicitly upgrade** with **Upgrade** in the skill's panel.

Pinning protects production: a skill author can publish a breaking change without breaking every instance that has the skill enabled.

### Disabling

Toggling a skill **off** removes the `instance_skills` row. The encrypted env vars are kept, so turning the skill back on restores them; the panel has no control that clears them, and the API removes one with `DELETE /api/instances/{slug}/skills/{skillSlug}/env/{key}`.

## The organization's catalogue

The **Skills** page is the organization's own catalogue: in the sidebar on the open-source build, and with managed services under *Resources* in the organization's navigation (`/organizations/{org}/skills`). Reading it needs `skill.catalog:read` - every role holds it, Viewer included; authoring needs `skill.catalog:write`, which is Admin and above. With managed services a role without `skill.catalog:write` sees the catalogue read-only: a notice says so, and **Add** and **Import Skills** are off with the reason.

A skill in the catalogue is **assignable** anywhere in the organization, but it is not automatically **available** everywhere: it reaches an agent only in a workspace it has been assigned to. Being in the catalogue is the first of two boundaries - see [What a workspace may draw on](https://docs.polyant.ai/admin-panel/workspaces#what-a-workspace-may-draw-on).

### What a skill is

A skill is a bundle of:

- **Slug + name + description + category.** The slug, shown as the **Identifier**, is what agents read the skill by, so it never changes; the name and the description are what people read, and can be edited.
- **One or more versions.** Each version has a content blob (the skill's prompt + script bundle) and metadata.
- **A list of tools** the skill enables when active (the `skillTools` link).
- **Required environment variables.** Declared in YAML frontmatter; their values are configured per instance.

### CRUD

- **List.** Tabular, sorted by name: **Name** with the description under it (at most two lines, the whole text on hover) and **Category** (with managed services also **Source**), under a search box. The workspace's skills and the Admin Console's catalogue show the description the same way.
- **Create.** Click **Add**. Fill in the name (the identifier is derived from it), the description, the required variables and the content, then save. The skill starts at version `0.1.0`.
- **Edit.** Click a row. The skill opens in a side drawer, and the old `/skills/{name}` address opens the list with that drawer. The **Content** tab edits the name, the description, the required tools and variables, the content and a changelog note; **Versions** lists every version. The drawer's footer holds **Delete** and **Export**.
- **Versions.** Every save writes a new version, raising the minor number (`0.1.0` → `0.2.0`); you do not pick it. Old versions remain - agents pinned to `0.1.0` keep using it until you upgrade them.
- **Archive.** The delete action archives the skill: it leaves the catalogue and stops being served, so agents that had it enabled keep the assignment but no longer receive it, and their [Status](https://docs.polyant.ai/admin-panel/instances#status) reports it.

Through the API, `PUT .../skills/{name}` accepts `displayName` beside `description`: the name may be left out but never blank, at most 255 characters, and the description at most 2,000. The identifier in the address is not an input.

> **Managed services.** A workspace's **Skills** page opens the same drawer, so whoever holds `skill.catalog:write` can edit a skill's name and description from there; its content and archiving stay on the catalogue.

### Importing skill bundles

The catalog supports importing JSON bundles. Use this to share a skill set across deployments or to onboard from a marketplace. Click **Import**, choose the JSON file, confirm the diff (any conflicting slugs are flagged), import.

There is no catalog-level Export **button** in this screen, but the endpoints exist: `GET /api/organizations/{org}/skills/catalog/export` for the whole catalogue and `GET .../skills/{name}/export` for one skill. See [Export and import an agent](https://docs.polyant.ai/how-to/export-import-instance#bonus---export-and-import-an-organizations-skill-catalogue).

### Categories

Skills are grouped by category for ergonomics: `crm`, `comms`, `productivity`, `internal`, `experimental`, etc. Categories are free-form strings; the catalog shows them in the **Category** column, and its search matches them.

## The platform catalogue

**Admin Console → Platform skills** (`/platform/settings/skills`) holds skills owned by the installation, and hands them out per organization. It is platform-admin-only - a *grantable* right to widen a tenant's capabilities would itself be a privilege-escalation surface, so this is a role check rather than a permission.

The page lists one row per skill with a **"granted to N organizations"** count that opens a searchable dialog of switches. A column per organization was tried and grows sideways with the tenant roster.

Its create and edit pages are the organization catalogue's own editor, reused - not a second one.

### What a grant means

A platform skill is visible to **no** organization until it is granted, exactly like an [installed plugin](https://docs.polyant.ai/admin-panel/tools#plugins-are-installed-per-organization). Once granted:

- **Reads are the union** of what the organization owns and what it has been granted.
- **Writes stay owner-exact.** Editing or archiving a granted platform skill is refused **403, not 404** - the organization can legitimately *see* the row, so pretending it does not exist would be a lie.
- **A granted skill is viewable at the organization's own detail page, read-only.** What that view removes is precisely what the engine would refuse: Save, the archive control, the single-skill export, and the authoring-only affordances (env-var editing, the changelog). The Versions tab is fully readable.
- **On a slug collision the organization's own skill wins.** That is a safety property, not a preference: a grant is additive and must never change what an agent already resolves. Creating your own skill under a platform skill's slug is how you override it, and the catalogue then renders one row for that slug, marked as overriding.

### Revoking

Revoking a grant **stops the skill being served**, not merely listed. The runtime checks visibility on every use - when building the prompt, when reading a skill, and when *executing* a skill's script - with the organization resolved from the agent's own workspace, and it fails closed.

The agents' `instance_skills` rows deliberately survive a revoke, so a re-grant restores every agent's configuration exactly. That is why the assignment alone is never treated as authority.

### The two boundaries, together

Visibility is an **intersection**, evaluated on every use:

| The organization | The agent's workspace | The agent |
|---|---|---|
| owns it, or was granted it | has it assigned | uses it |
| owns it, or was granted it | has not | never sees it - it stays out of the prompt, and reading or running it is refused |
| does not hold it | (irrelevant) | never sees it |

The order matters for the failure you will actually meet: a workspace row surviving an organization-level revoke does **not** bring the skill back, because the organization half is checked too. Assign the workspace from [Workspaces → Skills](https://docs.polyant.ai/admin-panel/workspaces#what-a-workspace-may-draw-on); grant the organization from this page or from the platform catalogue.
