Roger Oriol

Github RSS X Email

Build a Basic AI Agent From Scratch: Skills


7 minute read · Artificial Intelligence

Previous parts of Build a Basic AI Agent From Scratch:

You can find and clone this code in this blog series' GitHub repo, in the agent-skills/ directory.

In the previous part we gave our harness specialist agents. We could switch to a different agent or delegate part of a task to a sub-agent with its own context.

But suppose we just want our general agent to write release notes in a consistent format. Setting up a new agent or tool for this purpose is overkill. Instead, we only need to define a short set of instructions that the agent can look up when it's time to write the notes. We call this a skill.

What Is a Skill?

A skill is a set of instructions that gives an agent useful information about how to perform a task. Those instructions are similar to the instructions we already give the agent in the system prompt. Unlike the system prompt, a skill's full instructions need not always be loaded into the model's context. Skills often describe tasks that the agent only occasionally needs to perform, so keeping all their instructions in context might be wasteful.

In our harness, when the skill tool is available to an agent, the model sees a list of skill names and descriptions in the tool schema. It can then ask to load a skill's full instructions into its context when it needs them. A good description is important: if the model doesn't understand what a skill is for, it might not load it when needed. Our harness reads the full instructions into a registry at startup but only sends them to the model on request; other skill systems may discover and load instructions differently.

Defining and Discovering Skills

Each skill will live in a directory with a SKILL.md file. Let's add a personal skill that turns meeting notes into decisions and action items:

~/.agent-harness/skills/
  meeting-summary/
    SKILL.md
---
name: meeting-summary
description: Summarize meeting notes into decisions and action items.
---

Separate decisions from open questions. For each action item, list the owner
and due date if provided. Otherwise, mark them as unspecified.

This new file looks very similar to the SOUL.md files from the previous chapter, and we reuse their frontmatter parser.

At startup, discover_skills() loads bundled skills first, then skills under ~/.agent-harness/skills/, and finally project skills if we pass --skills-dir. If we have skill collisions by name, a later valid definition with the same name wins. That lets a project substitute its own specific instructions for a skill, without changing the default instructions.

The loader checks that the name is a lowercase slug matching the directory, the description is one printable line, and the instructions aren't empty. It also caps the catalog at 32 skills and each file at 16 KiB. Skills are read into a registry at startup, so to update a skill after an edit, we have to restart the agent.

Loading a Skill

The registry builds one tool schema, load_skill. Its description contains the catalog, and the name argument is an enum of registered names. The model doesn't need to know where the skill lives, the tool just loads it. The lookup is just a dictionary read:

def load(self, name: str) -> str:
    skill = self._skills.get(name)
    if skill is None:
        return f"Unknown skill '{name}'. Use a name from the skill catalog."
    return f"Skill: {skill.name}\n\n{skill.instructions}"

Suppose we ask, “Use the test-plan skill to draft a test plan for this change.” The model sees that test-plan matches and can call load_skill with {"name": "test-plan"}. The harness validates the call, looks up the Markdown in the registry, and returns it in a <skill_content> block. The next model request contains that tool result, so the agent can use the workflow to answer the original question.

The skills tool has to be in the active agent's registry to use skills. If an agent has an explicit tool allowlist, that list must contain load_skill. Sub-agents share the startup catalog, but get the tool only if their own allowlist permits it. A CLI --tools list that omits load_skill disables it for both the main agent and its children.

Security Considerations

While loading a skill is a read-only action, a loaded skill can lead the model to propose a harmful write or shell command, or disclose information it can access. Tool calls still go through the same checks as any other call: for example, a release-notes skill can't grant additional permissions to publish a release. But a malicious skill is another prompt-injection surface and can try to misuse the agent's existing permissions. Install only workflows you trust and review a project's skills before opting in.

Another possible security pitfall would be to put secrets in skills. Know that the skill's content will be loaded into the model's context and, once loaded, the instructions will end up in saved session transcripts.

Let's Test It!

From the harness repository, list the installed skills without starting Docker or calling the model:

uv run agent-skills/agent.py --list-skills

The bundled catalog contains decision-record, release-notes, and test-plan. If you created meeting-summary, it should appear as a user skill. To include a trusted project catalog, use --skills-dir .skills with the same <name>/SKILL.md layout.

Now start the harness and ask it for a test plan:

$ uv run agent-skills/agent.py
You: \skills
You: Use the test-plan skill to draft a test plan for session renaming.
     Renaming must preserve the session ID and transcript. Blank titles
     must be rejected. Don't edit any files or run the tests.

Look for a load_skill call in the tool trace. The resulting plan should check that a valid title persists, that the session ID and transcript stay the same, and that a blank title is rejected without changing the existing title.

What You've Built

We can now add optional instructions without always loading them into the model's context. When the skill tool is available, the model sees skill names and descriptions until it asks for the full instructions. We need to know when to use skills and when to use agents and subagents: use a skill to change how the current agent approaches an occasional task. Create an agent or subagent when a task calls for a dedicated agent or is best delegated outside the main agent's context.

What's next?

In the next chapter, we will add an MCP client to our agent harness. MCP stands for Model Context Protocol. It lets clients discover and use tools, resources and prompts provided by MCP servers, which can run locally or remotely. With a suitable server, credentials and client support, our agent could connect to applications such as calendars, email and messaging services. This can incredibly improve our agent's possibilities and usefulness.