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

# Skills as code

> Publish, roll back and pin skill versions from the API, and keep skills in your own Git repository as Skill resources a management cluster applies.

The Komodor Agentic Operation Platform (KAOP) versions every skill it holds, so you can script
publishing, rolling back and pinning instead of clicking through the console. With a management
cluster, you can also keep each skill as a `SKILL.md` folder in your own Git repository, review
changes in pull requests, and let KAOP follow what is merged.

## What can be managed this way

The calls and resources below apply to skills created in KAOP: from the console, the API, chat, or
a `Skill` resource. A skill that ships inside an agent's container image is reported by the agent
when it starts and changes only when you rebuild the image. To manage one in KAOP, claim it first;
see [Claim a skill from an agent image](#claim-a-skill-from-an-agent-image).

| Limit | Value |
| - | - |
| `SKILL.md` content | 128 KB |
| Supporting files per skill | 64 |
| Size of one supporting file | 256 KB |
| Supporting file type | Text only |

## Versions

Every change to a skill's content publishes a new version, numbered 1, 2, 3 and so on.

* A version holds the whole skill: the `SKILL.md` body and every supporting file.
* A version is never changed or deleted. To change a skill, publish a new version.
* Changing a skill's name, description, tags or labels does not create a version.
* Each publish is recorded in the [audit log](https://docs.komodor.com/security-and-governance/controls/audit-log.md) as
  `skill.publish`, with the version number and the person or API key that made it.

In the console, the save button on a skill whose content you changed reads **Publish as v*N***, and
**Version history** lists every version.

| Call | What it does |
| - | - |
| `POST /api/v1/skills` | Create a skill. Sending `content` publishes version 1. |
| `PATCH /api/v1/skills/{id}` | Change the name, description, tags or labels. No new version. |
| `POST /api/v1/skills/{id}/versions` | Publish a new version from `content` and `resources`, the full list of supporting files. |
| `PUT /api/v1/skills/{id}/files/{path}` | Add or replace one supporting file. Publishes a new version. |
| `DELETE /api/v1/skills/{id}/files/{path}` | Remove one supporting file. Publishes a new version. |
| `GET /api/v1/skills/{id}/versions` | List versions. |
| `GET /api/v1/skills/{id}/versions/{version}` | Read one version, with its content and files. |
| `DELETE /api/v1/skills/{id}` | Delete the skill. |

To publish a new version with two supporting files:

```bash theme={null}
curl -s -X POST "$AGENTOPS_URL/api/v1/skills/$SKILL_ID/versions" \
  -H "Authorization: Bearer $AGENTOPS_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<'EOF'
{
  "content": "---\nname: splunk-search\ndescription: Search Splunk around an incident.\n---\n\n# Splunk search\n...",
  "resources": [
    {"path": "references/indexes.md", "content": "# Indexes\n..."},
    {"path": "scripts/query.sh", "content": "#!/bin/sh\n...", "executable": true}
  ]
}
EOF
```

Leave out `content` or `resources` and the new version keeps that part from the latest one. Send
`"resources": []` to remove every supporting file.

## Roll back

A rollback publishes a **new** version with the content and files of an older one. No version is
deleted or changed: with v7 as the latest, rolling back to v5 publishes v8 with the content of v5.

* In the console, open the version in **Version history**, review its diff against the current
  version, and choose **Roll back to v*N***.
* From the API, call `POST /api/v1/skills/{id}/versions/{version}/rollback`.

A rollback is recorded as `skill.publish`, with the version it was taken from.

## Pin an agent to a version

Each attachment of a skill to an agent either tracks the **latest** version or is **pinned** to one
version.

* **Latest**: the agent gets each version you publish, rollbacks included.
* **Pinned**: the agent stays on that version until you change the pin.

Pin an agent to try a new version on one agent before the rest get it, or to hold a critical agent
on a known version. A change reaches the agent before its next run, with no redeploy or restart, and
a run already in progress keeps the version it started with.

In the console, choose **Latest** or a version on the agent's **Skills and tools** card, or manage
every agent from the skill's **Currently attached** list, where a change applies at once.

From the agent's side:

| Call | What it does |
| - | - |
| `POST /api/v1/agents/{agent}/skills` | Attach. Body: `{"skill_id": "...", "pin_version": 5}`. Leave out `pin_version` to track latest. |
| `PATCH /api/v1/agents/{agent}/skills/{skill_id}` | Change the pin. Body: `{"pin_version": 6}`, or `{"pin_version": null}` for latest. |
| `DELETE /api/v1/agents/{agent}/skills/{skill_id}` | Detach. |

From the skill's side, set every attachment in one call. The list is the full set: an agent left out
is detached, and an empty list detaches every agent. `agent` takes the Agent ID or the `agt_…` id.

```bash theme={null}
curl -s -X PUT "$AGENTOPS_URL/api/v1/skills/$SKILL_ID/agent-bindings" \
  -H "Authorization: Bearer $AGENTOPS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"bindings": [{"agent": "splunk-investigator"}, {"agent": "incident-commander", "pin_version": 6}]}'
```

Attaching, detaching and changing a pin are recorded as `agent.skill_attach`, `agent.skill_detach`
and `agent.skill_repin`.

## Keep skills in Git

You can keep skills in your own Git repository and have KAOP follow it, through a management
cluster:

1. koperator runs its config module on a cluster you own, bound to your account. See
   [Management cluster config](https://docs.komodor.com/security-and-governance/identity-and-access/configuration-clusters.md).
2. A GitOps tool such as Argo CD or Flux applies `Skill` resources from your repository into the
   namespace the config module watches.
3. The config module creates or updates each skill in KAOP. A change to `content` or `resources`
   publishes a new version, and an unchanged resource publishes nothing.
4. On every resync, five minutes by default, it puts back any change made outside Git.

How declarations map to KAOP, status conditions and deletion are covered in
[Declaring resources](https://docs.komodor.com/security-and-governance/identity-and-access/declaring-resources.md).

### The `Skill` resource

```yaml theme={null}
apiVersion: agentops.komodor.io/v1alpha1
kind: Skill
metadata:
  name: splunk-search
  namespace: agentops               # the namespace the config module watches
spec:
  name: splunk-search
  description: Search Splunk for errors around an incident.
  tags: [splunk, incidents]
  content: |
    ---
    name: splunk-search
    description: Search Splunk for errors around an incident.
    ---

    # Splunk search

    1. Read references/indexes.md to pick the index.
    2. Run scripts/query.sh with the service name.
  resources:
    - path: references/indexes.md
      content: |
        # Indexes
        ...
    - path: scripts/query.sh
      executable: true
      content: |
        #!/bin/sh
        ...
  agentBindings:
    - agent: splunk-investigator    # tracks the latest version
    - agent: incident-commander
      pinVersion: 6                 # stays on version 6
  deletionPolicy: delete
```

| Field | What it does |
| - | - |
| `name` | The skill's name in KAOP, `metadata.name` by default. Changing it points the resource at a different skill and leaves the old one in place. |
| `content` | The `SKILL.md` body. A change publishes a new version. |
| `resources` | The whole set of supporting files, each with `path`, `content` and, for a script, `executable: true`. A change publishes a new version, and an empty list removes every file. |
| `agentBindings` | The whole set of agents the skill is attached to, each an `agent` and an optional `pinVersion`. Leave out `pinVersion` to track latest. An agent removed from the list is detached. |
| `description`, `tags`, `labels` | Skill metadata. No new version. |
| `deletionPolicy` | `delete`, the default, deletes the skill in KAOP with the resource. `orphan` leaves it in KAOP and stops managing it. |

A field you leave out stays as it is in KAOP. The result is on the resource's `Synced` condition,
with KAOP's own message when it refuses a change:

```bash theme={null}
kubectl get skills -n agentops
kubectl describe skill splunk-search -n agentops
```

All content is inline, so one Kubernetes object holds the whole skill, within Kubernetes' limit of
about 1.5 MB per object.

### Keep `SKILL.md` folders instead of YAML

To keep each skill as a folder with a real `SKILL.md`, a small Helm chart can read the folders and
build the `Skill` resources. Argo CD and Flux both render Helm charts from Git.

```
sre-skills/                      # your Git repository
└── kaop-skills/                 # a Helm chart
    ├── Chart.yaml
    ├── values.yaml              # which skills to apply, and their agent bindings
    ├── skills/
    │   ├── splunk-search/
    │   │   ├── SKILL.md
    │   │   ├── references/indexes.md
    │   │   └── scripts/query.sh
    │   └── pagerduty-triage/
    │       └── SKILL.md
    └── templates/
        └── skills.yaml
```

`values.yaml`:

```yaml theme={null}
skills:
  splunk-search:
    agentBindings:
      - agent: splunk-investigator
      - agent: incident-commander
        pinVersion: 6
  pagerduty-triage:
    agentBindings:
      - agent: incident-commander
```

`templates/skills.yaml`:

```yaml theme={null}
{{- range $name, $skill := .Values.skills }}
{{- $dir := printf "skills/%s/" $name }}
{{- $resources := list }}
{{- range $path, $bytes := $.Files.Glob (printf "%s**" $dir) }}
{{- $rel := trimPrefix $dir $path }}
{{- if ne $rel "SKILL.md" }}
{{- $resources = append $resources (dict "path" $rel "content" (toString $bytes) "executable" (hasPrefix "scripts/" $rel)) }}
{{- end }}
{{- end }}
---
apiVersion: agentops.komodor.io/v1alpha1
kind: Skill
metadata:
  name: {{ $name }}
spec:
  name: {{ $name }}
  content: |
{{ $.Files.Get (printf "%sSKILL.md" $dir) | indent 4 }}
  resources: {{ toYaml $resources | nindent 4 }}
  agentBindings: {{ toYaml ($skill.agentBindings | default list) | nindent 4 }}
{{- end }}
```

The template marks every file under `scripts/` as executable. Run
`helm template kaop-skills ./kaop-skills` to see the resources before you commit.

Point your GitOps tool at the chart, in the config module's namespace. With Argo CD:

```yaml theme={null}
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: kaop-skills
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/<your-org>/sre-skills.git
    targetRevision: main
    path: kaop-skills
  destination:
    server: https://kubernetes.default.svc
    namespace: agentops
  syncPolicy:
    automated:
      prune: true
```

With Flux, use a `GitRepository` for the repository and a `HelmRelease` whose chart points at
`./kaop-skills` in it, with `targetNamespace` set to the config module's namespace.

### A change, end to end

1. A change to `skills/splunk-search/SKILL.md` is reviewed in a pull request and merged.
2. Argo CD or Flux applies the changed `Skill` resource.
3. The config module publishes a new version in KAOP, for example v8.
4. Agents that track latest use v8 from their next run. Agents pinned to an older version stay on it.

To roll back from Git, revert the commit: the config module publishes the old content as a new
version, such as v9. To hold one agent back while you investigate, set its `pinVersion` in
`values.yaml`.

### Editing a Git-managed skill in the console

A skill declared this way carries the **Managed by cluster** badge. Make changes in Git. Whether a
console or API edit is refused, or saved and later put back, depends on your account's ownership
enforcement; see
[the Managed by cluster badge](https://docs.komodor.com/security-and-governance/identity-and-access/configuration-clusters.md#understand-the-managed-by-cluster-badge).
Attachments and pins changed in the console or with the agent calls above are saved either way, and
the config module puts back what Git says at the next change to `agentBindings` in Git.

## Claim a skill from an agent image

A skill that ships in an agent's container image is reported by the agent when it starts. To version and edit it in KAOP, claim it. Claiming makes a copy at version 1 that you can edit,
version, pin and keep in Git like any other skill.

* In the console, open **Skills**, choose the skill, and choose **Claim as authored**.
* From the API:

  ```bash theme={null}
  curl -s -X POST "$AGENTOPS_URL/api/v1/skills/$DISCOVERED_SKILL_ID/claim" \
    -H "Authorization: Bearer $AGENTOPS_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"source_agent_id": "<agent id>"}'
  ```

  `GET /api/v1/skills?kind=discovered&agent_id=<agent id>` lists the skills an agent reports.

The copy is not attached to any agent until you attach it. Skills of Komodor catalog agents cannot
be claimed. A claim is recorded as `skill.claim`.

## Permissions

| To do this | You need |
| - | - |
| Read skills and versions | `skill.read` |
| Create a skill | `skill.create` |
| Publish, roll back or edit | `skill.update` on the skill |
| Claim a skill from an agent image | `skill.update`, and `agent.skill.attach` on the agent that reports it |
| Delete a skill | `skill.delete` on the skill |
| Attach, detach or change a pin | `agent.skill.attach` on the agent, and `skill.update` on the skill when you call from the skill's side |

## Next steps

> [card] [Skills](https://docs.komodor.com/manage-your-agents/build/skills.md)
>
> What a skill is, how it is approved, and how an agent finds it.

> [card] [Declaring resources](https://docs.komodor.com/security-and-governance/identity-and-access/declaring-resources.md)
>
> Every kind a management cluster can declare, and how status and deletion work.


## Related topics

- [Skills](https://docs.komodor.com/manage-your-agents/build/skills.md)
- [Code Review](https://docs.komodor.com/manage-your-agents/build/catalog/code-review.md)
- [Build a custom agent image](https://docs.komodor.com/manage-your-agents/build/custom-agent-image.md)
- [What's new](https://docs.komodor.com/reference/changelog.md)
- [Credentials & secrets](https://docs.komodor.com/security-and-governance/identity-and-access/credentials-secrets.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.