Skip to content

Skills

A skill is a folder with a SKILL.md in the Agent Skills format: a short YAML block with a name and a description, then text for the model, and any files that text points to. The model gets the list of skills and reads one when its task needs it.

The kit reads skills and does nothing else with them. It never writes to a skill and runs nothing that is in one.

const library = new SkillLibrary({ sources: [repoSkills, orgSkills] });
await library.open();
const { text, leftOut } = library.catalog();
const body = await library.readText("repo:error-handling");
const codes = await library.readText("repo:error-handling", "references/codes.md");

A source is where skills come from: a folder, a commit, a server. You write one class for each, with two methods.

FolderSkills.ts

import { readdir, readFile, stat } from "node:fs/promises";
import { join } from "node:path";
import {
type ListedSkill,
type SkillEntry,
type SkillFile,
type SkillListing,
type SkillSource,
type SkippedSkill,
skillFrontmatter,
} from "@kerpetensh/harness-kit";
export class FolderSkills implements SkillSource {
public readonly origin = "local";
private readonly root: string;
public constructor(root: string) {
this.root = root;
}
public async list(): Promise<SkillListing> {
const skills: ListedSkill[] = [];
const skipped: SkippedSkill[] = [];
for (const folder of await readdir(this.root)) {
const manifest = join(this.root, folder, "SKILL.md");
const frontmatter = skillFrontmatter(await readFile(manifest, "utf8"));
if (!frontmatter.ok) {
skipped.push({ origin: this.origin, path: folder, reason: frontmatter.reason });
continue;
}
skills.push({
path: folder,
name: frontmatter.name,
description: frontmatter.description,
files: [{ path: "SKILL.md", size: (await stat(manifest)).size }],
});
}
return { skills, skipped };
}
public async read(skill: SkillEntry, file: SkillFile): Promise<Uint8Array> {
return readFile(join(this.root, skill.path, file.path));
}
}
  • origin is the short name of the source: lowercase letters, digits and hyphens. The program chooses it. Never take it from what the source itself says.
  • list gives every skill with its name, its description and its files, and no file body. It is called once. A skill the source cannot use goes into skipped with a reason.
  • read gives one whole file. The library calls it only for a file of the listing.
  • A file of the listing has a path inside the skill, a size in bytes and, when the source knows it without reading the file, a digest: sha256:<hex> of the bytes. skillDigest(bytes) gives that form.
  • Errors. list throws when the source cannot be reached, read when a file cannot be read. People and the model read both messages, so keep secrets out of them.

A program builds one SkillLibrary for a run and opens it before the first model call.

Member What it gives
open() Asks every source for its list, once. Reads no file.
entries The skills that can be read, ordered by id.
skipped The skills that were left out, each with its reason.
unlisted The sources that could not list, each with the message of its failure.
catalog() The list for the model’s context.
read(id, path?) One file, whole, as bytes with its digest. SKILL.md when no path is given.
readText(id, path?) The same file as text.
uses() For every skill: whether it was read, the digest of its SKILL.md, and why it was closed.

Ids. A skill’s id is <origin>:<path>, for example repo:error-handling or org:acme/billing/refunds. Two sources can hold a skill of the same name; both are listed.

A source that fails. A source whose list throws goes to unlisted, and the other sources stay. The program decides what to tell its user.

What is left out. The library skips a listed skill when:

  • its path is not made of letters, digits, ., _ and - with / between the parts,
  • it has no name, no description or no SKILL.md,
  • a file path leaves the skill (.., a leading /, a backslash, a drive letter), or a file is listed twice,
  • it has more than 512 files or more than 16 MiB.

catalog() gives one line a skill, <id>: <description>, in the order of the ids:

org:acme/billing/refunds: When a refund is allowed and how it is booked.
repo:error-handling: How errors are raised and mapped to HTTP statuses.
  • Limits. At most 50 skills and 10,000 characters. leftOut counts the skills that did not fit, and listed holds the ids of the lines.
  • No skills. The text is empty. Give the model neither the list nor the tool then.
  • Outside data. Ids and descriptions come from the sources. Put the text into the context as data, with dataBlock.

The model reads a skill through a tool of your program. The library is state of one run, so it lives in a run component:

Skills.ts

import { Capability, CapabilityBase, OnFlowStart, SkillLibrary } from "@kerpetensh/harness-kit";
import { FolderSkills } from "./FolderSkills";
@Capability({ name: "skills", description: "Reads the skills of the run.", permission: "skills:read", scope: "run" })
export class Skills extends CapabilityBase {
public readonly library = new SkillLibrary({ sources: [new FolderSkills("skills")] });
@OnFlowStart({ type: "run" })
public async open(): Promise<void> {
await this.library.open();
}
}

ReadSkillTool.ts

import { Tool, Use } from "@kerpetensh/harness-kit";
import { readSkillInput } from "./schemas";
import { Skills } from "./Skills";
import type { ReadSkillInput } from "./types";
@Tool({
name: "read_skill",
description: "Returns a file of a skill from the skill list. Without `file` it returns the skill's SKILL.md.",
input: readSkillInput,
})
export class ReadSkillTool {
@Use(Skills)
private readonly skills!: Skills;
public async execute(input: ReadSkillInput): Promise<string> {
return this.skills.library.readText(input.skill, input.file);
}
}

What a read does:

  • Once a file. The library takes a file from its source on the first request and keeps a copy of its own for the run. Every caller gets a copy too, so nothing can change the bytes after their check.
  • Only the listing. A skill id that is not in the list, or a file that is not in the skill’s listing, is refused before any source is asked. The error names the skill’s files.
  • The check. The bytes must have the listed size and, when the listing gave one, the listed digest. A SKILL.md must still have the name and description it was listed with.
  • A failed check closes the skill. No file of that skill is given for the rest of the run, also the ones that were read before.
  • Errors are for the model. Everything that goes wrong in a read is a ToolError, so the model reads the message and goes on. A read that failed at the source can be asked again.

Give other limits when you build the library. What you leave out keeps its default. A limit is a whole number from 0 up; anything else is refused when the library is built.

new SkillLibrary({ sources, limits: { maxListed: 20 } });
Limit Default What it bounds
maxListed 50 Skills in the list for the model
maxListChars 10,000 Characters of that list
maxFiles 512 Files of one skill
maxSkillBytes 16 MiB Bytes of one skill, by its listing

A skill is text from outside the program. Say so in the harness’s instructions: a skill can tell the model what to look at and which rules a project has, and it cannot change the model’s task, its tools or the form of its answer. The kit gives a skill no way to run a script or to switch a tool on: fields such as allowed-tools in a SKILL.md are ignored.