• AI
  • agents
  • documentation

Agent Skills: load expertise only when a task needs it

A beginner-friendly guide to the Agent Skills format: what a skill is, the three loading levels, how to build a small SKILL.md step by step, the naming rules, validation, and how to test activation.

Imagine a new colleague joins your team. On day one you hand them a binder with every procedure the team has: how to release, how to review security, how to change the database. Nobody expects them to read all of it before answering a simple question. They read the table of contents, and they open a chapter only when a task needs it.

An AI coding agent has the same problem. An agent here means an AI assistant that can read files, run commands, and take several steps on its own to finish a task. Everything it “knows” about your project for the current request has to fit into its context, the text the model reads before it answers. Context is measured in tokens, small chunks of text (roughly parts of words). Context is limited, and filling it with procedures that do not matter right now wastes space and can distract the model.

Agent Skills are a format for that binder. A skill packages one specialist procedure so the agent can load it only when a task calls for it. The key design idea is progressive disclosure: show the agent a short description first, and give it the detailed instructions only after it decides the skill is relevant. Agent Skills specification Genkit Go guide

This article explains how the format works and then builds a small skill for database migrations, step by step.

Why not put everything in one instruction file?

Many agents read a project instruction file on every request. That file is the right place for rules that apply almost everywhere, such as “run the tests before you finish”.

A procedure you need once a month is different. If it sits in the always-loaded file, you pay for it in every request, including the ones about fixing a typo. Moving it into a skill keeps the everyday context small. The procedure is still there when it is needed.

What goes into a skill

A skill is a directory. The only required file is SKILL.md. It has two parts:

  • Frontmatter: a short block at the top, written in YAML (a simple key: value text format) between two --- lines. It holds the skill’s name and description.
  • Body: the Markdown text below the frontmatter. This is the actual procedure the agent follows.

The spec also suggests three optional directories next to SKILL.md:

  • scripts/ for code the agent can run.
  • references/ for longer documentation the agent can read when needed.
  • assets/ for static files such as templates or data files.

The three loading levels

The specification’s progressive disclosure section describes three levels, each with a different budget:

Level What is loaded When Suggested size
1. Metadata name and description At startup, for every installed skill About 100 tokens
2. Instructions The full SKILL.md body When the skill is activated Under 5,000 tokens recommended
3. Resources Files in scripts/, references/, assets/ Only when a step needs them As needed

Here is why each level matters:

  • Level 1 is paid on every request, for every skill you install. So the description must be short and precise.
  • Level 2 is paid every time the skill activates. So the spec recommends keeping SKILL.md under 500 lines and moving detailed material into separate files.
  • Level 3 is paid only when a step actually opens the file. This is where long reference material belongs.

The spec adds two rules for those files. Reference them with relative paths from the skill root, such as references/locking.md. And keep references one level deep: SKILL.md may link to references/locking.md, but locking.md should not send the agent down a further chain of files.

Build a small migration skill

A database migration is a script that changes the structure of a database, for example adding a column to a table. Migrations are a good fit for a skill. You need them occasionally, they have a clear procedure, and mistakes on large tables can be expensive.

The skills/ folder below is an example location. Where your agent looks for skills depends on the agent, so check its documentation for the right path.

Step 1: Create the directory layout

Run this in your project’s root folder, in a terminal:

mkdir -p skills/db-migration/references skills/db-migration/assets
touch skills/db-migration/SKILL.md \
  skills/db-migration/references/locking.md \
  skills/db-migration/assets/migration-template.sql

mkdir -p creates the folders, including any missing parents. touch creates the three empty files. You should end up with this tree:

skills/
└── db-migration/
    ├── SKILL.md
    ├── references/
    │   └── locking.md
    └── assets/
        └── migration-template.sql

Step 2: Write SKILL.md

Open skills/db-migration/SKILL.md in your editor and add:

---
name: db-migration
description: Prepare and review a database schema migration. Use when a task adds, drops, or alters tables, columns, or indexes, or backfills existing rows.
---

1. Read the schema and the migration conventions in this repository.
2. Write a forward migration from assets/migration-template.sql and, where the project supports it, a rollback.
3. If the migration touches a large or busy table, read [locking and backfill guidance](references/locking.md) before choosing an approach.
4. Show the generated diff and list the checks the author should run.

Notice what the description does. The first sentence says what the skill does. The second says when to use it, with words people actually type: “tables”, “columns”, “indexes”, “backfills”. A backfill means filling a new column with values for rows that already exist.

Step 3 of the body uses a relative Markdown link. The agent opens locking.md only when the migration touches a large or busy table.

Step 3: Fill in the supporting files

Put your team’s own notes on table locks and batched backfills into references/locking.md. Put the migration file format your project uses into assets/migration-template.sql. The skill does not need these to be long. It needs them to be accurate for your database.

The benefit shows up in everyday use. A migration that adds a column to a small lookup table never loads locking.md. A backfill on a large table does.

Step 4: Check the frontmatter rules

According to the spec, name must:

  • be 1–64 characters long;
  • use only lowercase letters, digits, and hyphens;
  • not start or end with a hyphen;
  • not contain two hyphens in a row (--);
  • match the name of its parent directory.

So db-migration must live in a directory called db-migration. description is required and can be at most 1,024 characters.

If you want a quick local check before using a proper validator, this small shell script tests the name format and the directory match. Save it as check.sh in the project root and run sh check.sh:

dir=skills/db-migration
name=$(sed -n 's/^name: *//p' "$dir/SKILL.md" | head -n 1)
echo "$name" | grep -Eq '^[a-z0-9]+(-[a-z0-9]+)*$' && [ ${#name} -le 64 ] && echo "name format ok: $name" || echo "bad name format: $name"
[ "$name" = "$(basename "$dir")" ] && echo "matches directory" || echo "does not match directory"

I ran it with macOS’s /bin/sh (GNU bash 3.2.57). With the frontmatter above it printed:

name format ok: db-migration
matches directory

After changing the name to DB--Migration, it printed:

bad name format: DB--Migration
does not match directory

This only covers name. It is a convenience, not a replacement for the validator in the next section.

Optional fields

The spec also defines optional fields: license, compatibility (environment requirements, such as needing git or network access), and metadata (extra key-value pairs). There is also allowed-tools, a space-separated list of tools the skill may use without asking. The spec marks allowed-tools as experimental and says support may vary between agent implementations. Do not rely on it as your only control.

Know the boundary

A skill is guidance and packaged material. It is not a permission system. Writing “never drop a table” in SKILL.md asks the model to behave. It does not stop it.

If a skill includes a script that can change data or run shell commands, read that code and check its inputs, as you would with any script in your repository. If you need to block certain actions no matter what the instructions say, enforce that outside the skill. Two options are hooks that check tool calls before they run and running the agent in an isolated sandbox or Git worktree.

Validate and test activation

There are two separate questions. Is the skill well-formed? And does the agent pick it at the right time?

Step 1: Validate the structure

The spec points to the skills-ref reference library for checking frontmatter and naming rules. Once it is installed, run this from the project root:

skills-ref validate ./skills/db-migration

The project installs it from source into a Python virtual environment. It also describes the library as intended for demonstration, not production use. I did not run it for this article, so I cannot show its output. Treat it as a structural check, not proof that the skill behaves well.

Step 2: Test with one prompt that should activate the skill

In the agent you actually use, try:

Add a non-null region column to the orders table and backfill it from customers.region.

Expected result: the agent loads db-migration and follows its steps. Because this is a backfill on an existing table, it should also open references/locking.md before proposing the migration.

Step 3: Test with one prompt that should not activate it

Fix the typo in the README installation section.

Expected result: db-migration is not loaded at all.

Step 4: Read the result and adjust

How you see which skill loaded depends on the host agent. Some print the skill name. Others only show that SKILL.md was read.

  • If the README prompt triggers the skill, the description is too broad. Make the “when to use” part more specific.
  • If the migration prompt does not trigger it, add the words people actually use, such as “column”, “index”, or “backfill”.
  • Also check that the agent asks for missing details instead of inventing a schema or deployment assumptions.

Common mistakes

  • A vague description. “Helps with databases” gives the agent nothing to match against. Say what the skill does and when to use it.
  • A name that does not match the folder. name: db_migration in a db-migration folder breaks two rules: underscores are not allowed, and the names differ.
  • Putting everything in SKILL.md. The whole body loads on every activation. Move long material to references/.
  • Chains of references. If locking.md links to another file that links to a third, the agent has to follow the chain. Keep references one level deep.
  • Treating instructions as security. A skill’s text cannot stop a command. Use hooks, sandboxes, or normal permissions for that.
  • Testing only the happy path. A skill that activates too often wastes context just like an oversized instruction file. Always test a prompt that should not trigger it.

Conclusion

Use skills for specialized procedures that matter only on some requests. Keep the description short because it is loaded every time. Keep SKILL.md focused because it is loaded on every activation. Push long references into files one level away. Then validate the frontmatter, test one prompt that should activate the skill and one that should not, and review any executable material yourself.

Written by Duy Pham Independent developer. I build the apps on this site and write about how they work.

More about me