Skills in Your Agent
Leila has turned her monthly report procedure into a skill: a folder skills/report/ with a SKILL.md inside, a name and description at the top and twelve numbered steps below. Claude Code picks it up when she asks for "the March report". mini doesn't, of course. Now that mini can load an instruction file, she wonders whether she could just do the same thing again: read every SKILL.md and add them all to the system prompt.
Leila Loading the instruction file was five lines. Can't I load the skills the same way?
Omid You could. How long are they, all together?
Leila Seven skills, maybe 30,000 tokens. Oh. That's the reason skills exist: they're the things too long to carry in every request.
Omid So what does mini put in the system prompt?
Leila Only the part the model needs to decide: each skill's name and its description. A line each.
Omid And when a task matches one of those lines?
Leila Then the model needs the rest. It could read the file itself with read_file, if it knows the path.
Omid It could. What's the difference if we give it a tool called load_skill instead?
Leila It asks for a skill by name, so it can't get a path wrong. It's clearer in the trace: "load_skill report" says what happened. And it doesn't need permission like an ordinary file, because it can only read skills.
Omid One more question. When load_skill returns the twelve steps, where in the request do they end up?
Leila It's a tool, so... in a tool result. At the end of the messages, after everything else.
Omid Which means?
Leila The start of the request doesn't change. The cache survives. Loading a skill costs the skill's tokens, and nothing more.
The three parts of a SKILL.md
A skill file has a header between two lines of ---, and a body below it. mini needs three things from it: the name and description from the header, and the body.
read_skill reads one file:
def read_skill(path):
text = path.read_text()
_, header, body = text.split("---", 2)
fields = dict(line.split(":", 1) for line in header.strip().splitlines() if ":" in line)
return fields["name"].strip(), fields["description"].strip(), body.strip()Line by line: split("---", 2) cuts the text at the first two ---, giving what's before the header (nothing), the header, and the body. The 2 matters: a --- further down the body is left alone. The header is turned into a dictionary by splitting each key: value line at its first colon, so a description that contains a colon keeps it. Then the three parts come back, with spaces trimmed.
This is a deliberately small reader, not a full YAML parser. It expects a one-line description: and it fails loudly (KeyError) if a file has no name or description. The exercise after this lesson makes it more forgiving.
The index
skill_index builds the lines that go into the system prompt:
def skill_index():
skills = sorted((ROOT / "skills").glob("*/SKILL.md"))
if not skills:
return ""
lines = [f"- {name}: {description}" for name, description, _ in map(read_skill, skills)]
return "\n\nSkills you can load with load_skill when a task matches:\n" + "\n".join(lines)glob("*/SKILL.md") finds every skill folder's file. sorted matters more than it looks: without it, the order could differ between runs, and a different order is a different system prompt, which would break the cache for no reason. Each skill becomes one line, - name: description, under a heading that tells the model what the list is for and which tool to use. If there are no skills, nothing is added.
As you saw in the last lesson, the index is added to the system prompt once, when mini starts, after the project's instructions.
The tool
def load_skill(name):
for path in (ROOT / "skills").glob("*/SKILL.md"):
if read_skill(path)[0] == name:
return read_skill(path)[2]
return f"no skill called {name}"
TOOLS["load_skill"] = (load_skill, "Load the full instructions of a skill from the skills list.",
{"name": "the skill's name"})It looks for the skill with that name and returns its body. An unknown name isn't an error that stops mini; it's a short message the model can read and correct, like any tool result. The last lines register it in TOOLS exactly like the file tools from Describing a Tool: a function, a description and one input. And load_skill is in mini's ALLOW set, so it never stops to ask permission: reading a skill can't change anything.
A skill, step by step
Here's what happens when Leila asks mini for the March report:
- Session start: the system prompt holds mini's instructions, the project's AGENTS.md and seven one-line skill descriptions.
- Turn 1: the model reads the request, sees that "report: Writes the monthly sales report from the template. Use when asked for the monthly report." matches, and asks for
load_skillwithname: report. - mini runs it, and the twelve steps come back as a tool result, at the end of the messages.
- Turn 2 onwards: the model follows the steps, using the file tools as usual. The steps stay in the conversation for the rest of the session, like anything else it has read.
This is the progressive disclosure behind agent skills, now as code you can read: about 25 lines in all.
One thing mini leaves out: a skill folder can also hold extra files (a template, a reference sheet, a script). mini doesn't need anything new for them. The steps say "copy templates/report.md" or "run check_report.py", and the model uses read_file and run_command as it would for any other file.
Try it
Make a folder with
skills/haiku/SKILL.md: a header withname: haikuanddescription: Writes a haiku about a file's contents. Use when asked for a poem about a file., and a body with three steps. Run mini there and ask "write a poem about AGENTS.md". Watch for theload_skillcall before anything else. Then ask something unrelated and check that it doesn't load the skill. No key? Runprint(skill_index())from mini's folder.
Using it well
- Only descriptions go in the system prompt. The bodies arrive later, as tool results, so a skill costs a line until it's used.
- Sort what you load. A fixed order keeps the system prompt identical between runs, and the cache with it.
- Load by name, not by path. A
load_skilltool is harder to get wrong than a path, shows up clearly in a trace, and can be allowed without asking. - Make broken skills loud. A skill without a description is silently never used. Check the files when mini starts, and say which one is wrong.
Words to know
- skill index - the list of skill names and descriptions a harness puts in the system prompt, so the model knows what it can load
- load_skill - mini's tool that returns a skill's full instructions by name, as a tool result at the end of the conversation
- header - the part of a SKILL.md between the two lines of
---, holding its name and description
Big idea
In code, a skill system is a list and a tool. The list of names and descriptions goes in the system prompt, where it stays cached; the instructions come back through a tool only when a task needs them, at the end of the conversation, where they cost only their own tokens.