Why this topic matters
Agent Skills are folders of instructions that an agent can load when a task needs specialized knowledge. A skill is a directory with a SKILL.md file: a short YAML header with a name and a description, followed by a markdown body with the instructions. The idea is simple, but the integration question is not. When your agent starts a session, how does the model learn that a skill exists, and how does the full instruction set reach its context only when it is needed?
The Agent Skills integration guide answers this with a core principle called progressive disclosure. Instead of loading every skill upfront, the agent works in three tiers. The first tier is a catalog of names and descriptions, which costs roughly 50 to 100 tokens per skill and is loaded at session start. The second tier is the full SKILL.md body, loaded only when a skill is activated and recommended to stay under about 5,000 tokens. The third tier is supporting resources such as scripts or reference files, loaded only when the instructions point to them.
This article focuses on one part of that lifecycle: activation. The guide describes two ways to deliver a skill's content to the model. One relies on the model reading the file directly with its file-read tool. The other is a tool-based approach, where the agent exposes a dedicated function, usually called activate_skill, that returns the skill content. The tool-based approach is the one you need when the model cannot read files, and it is useful even when it can. In this article I walk through why you would choose it, how the pieces fit together, and how to implement it in Java with Spring AI.
The two activation paths
The file-read path is the simplest. The catalog tells the model where each SKILL.md lives, and when a task matches a description, the model calls its normal file-read tool on that path. No special infrastructure is needed. The model receives the raw file, frontmatter included, as a tool result.
The file-read path has three limitations that matter in real systems:
- It assumes the model has file access. A cloud-hosted agent, a sandboxed agent, or a chat product with no filesystem will not have it.
- It gives you no control over what is returned. The whole file goes into context, including the frontmatter, and you cannot easily add metadata such as the list of bundled resources.
- It leaves no place to enforce permissions, ask for consent, or record that a skill was used.
A dedicated activation tool solves all three. You register a function, the model calls it with a skill name, and your code decides what to return. The guide lists the advantages: control over the returned content, structured wrapping so the harness can identify skill content later, a listing of bundled resources without reading them, permission checks, and analytics.
The tool-based path is therefore not a different skill format. It is a different delivery mechanism for the same SKILL.md files. Skills authored for one client should work in another, and the activation tool is the adapter.
Step 1: Discover skills at session start
Before any activation can happen, the agent must find the skills. The guide recommends scanning at least two scopes. A project scope lives under the working directory, for skills that belong to a repository. A user scope lives under the home directory, for skills available across projects. Within each scope, the guide suggests scanning both a client-specific directory such as .claude/skills/ and the cross-client .agents/skills/ convention, so that skills installed by other compliant tools are visible.
Discovery looks for subdirectories that contain a file named exactly SKILL.md. It should skip folders such as .git and node_modules, and it should bound the search depth and the number of directories so that a large tree does not stall the session. When two skills share a name, the common rule is that project-level skills override user-level ones, and a warning should be logged so the user knows a skill was shadowed.
There is also a trust question. Project-level skills come from the repository being worked on, which may be untrusted, so the guide suggests loading them only after the user has marked the folder as trusted. This matters because a skill is, in effect, a set of instructions injected into the model's context.
Step 2: Parse the frontmatter leniently
Each discovered file is split into two parts: the YAML block between the opening and closing --- delimiters, and the body that follows. The guide recommends a lenient approach. A name that does not match its directory produces a warning but the skill still loads. A missing or empty description is the one case that causes the skill to be skipped, because the description is what makes disclosure possible. The guide also mentions a common compatibility problem: unquoted values containing colons, such as description: "Use this skill when: the user asks about PDFs, are invalid YAML that some parsers accept anyway. A good implementation retries with the value quoted."
For each skill you need three fields: the name, the description, and the absolute location of the file. The base directory, which is the parent of location, is derived when needed so that relative references such as scripts/evaluate.py can be resolved.
Step 3: Disclose the catalog to the model
The catalog is the first tier of progressive disclosure. It lists each skill's name and description, and optionally its location, inside whatever structured format fits your stack. The guide shows an XML example, but a bulleted list works too.
Where you place the catalog matters for the tool-based path. You can put it in the system prompt, or embed it in the description of the activation tool itself. The tool-embedding option keeps the system prompt clean and couples discovery with activation, which is why it pairs well with a dedicated tool.
The guide also provides a short behavioral instruction block. For the tool-based path, it tells the model that when a task matches a skill's description, it should call the activation tool with that skill's name before proceeding. The instruction is deliberately brief, because the skill content itself carries the detailed guidance once loaded.
Two rules keep the catalog honest. First, filtered skills must be hidden entirely, not listed and then blocked. A skill the user has disabled, or one that a permission policy denies, should never appear, because otherwise the model wastes turns trying to use it. Second, when no skills exist, the catalog and the tool should be omitted, not rendered as an empty block that confuses the model.
Step 4: Activate with a dedicated tool
Activation is the second tier. In the tool-based path, the model calls the tool, the harness looks up the skill, and the instructions come back as the tool result.
The guide offers a few design choices for that result. You can return the full file or only the body, with the frontmatter stripped. Most dedicated implementations strip it, because name and description were already captured during discovery. You can also wrap the content in identifying tags, which helps the model separate skill instructions from the rest of the conversation and lets the harness find the content again during context management. A typical wrapper includes the skill directory and a list of bundled files, without reading them.
The guide makes one point that is easy to miss. The tool should list supporting files but should not read them eagerly. The model loads a specific script or reference only when the instructions reference it, using its normal file-read capability. For large directories, the listing should be capped and marked as possibly incomplete.
There are two tips worth taking seriously. If you register a tool whose name parameter is an enum of valid skill names, the model cannot invent a skill that does not exist. And if no skills are available, do not register the tool at all. An activation tool with no valid options is noise.
Users should be able to activate skills directly as well, with a slash command or mention syntax such as /skill-name. In that case the harness intercepts the input, performs the lookup, and injects the content, so the model does not have to take an activation action.
A Java implementation with Spring AI
The following implementation follows the guide's structure. It scans two folders, builds a catalog, and exposes an activate_skill tool through Spring AI's @Tool annotation. The example assumes Spring Boot 3.4 or later with a chat model starter, such as spring-ai-starter-model-openai. The API shown here is Spring AI's annotation-based tool calling.
First, the skill record and the registry that discovers skills:
public record SkillDefinition(String name, String description, Path location) { public Path baseDirectory() { return location.getParent(); } } @Component public class SkillRegistry { private static final int MAX_DEPTH = 5; private static final int MAX_DIRECTORIES = 2000; private final Map<String, SkillDefinition> skills = new LinkedHashMap<>(); public SkillRegistry( @Value("${skills.project-dir:.agents/skills}") Path projectDir, @Value("${skills.user-dir:${user.home}/.agents/skills}") Path userDir) throws IOException { // Scan user scope first, then project scope, so project skills override user skills. scan(userDir); scan(projectDir); } private void scan(Path root) throws IOException { if (!Files.isDirectory(root)) { return; } try (Stream<Path> paths = Files.walk(root, MAX_DEPTH)) { paths.filter(p -> p.getFileName().toString().equals("SKILL.md")) .limit(MAX_DIRECTORIES) .forEach(this::register); } } private void register(Path file) { try { SkillFrontmatter fm = SkillFrontmatter.parse(Files.readString(file)); if (fm.description() == null || fm.description().isBlank()) { log.warn("Skipping skill without description: "{}\", file);" return; } if (skills.containsKey(fm.name())) { log.warn("Skill '{}' at {} shadows an earlier definition", fm.name(), file); } skills.put(fm.name(), new SkillDefinition(fm.name(), fm.description(), file)); } catch (IOException | IllegalArgumentException ex) { log.warn("Skipping unreadable skill {}: {}", file, ex.getMessage()); } } public Collection<SkillDefinition> all() { return Collections.unmodifiableCollection(skills.values()); } public Optional<SkillDefinition> find(String name) { return Optional.ofNullable(skills.get(name)); } } The frontmatter parser splits the file on the delimiters and reads the two fields the registry needs. A production parser would use SnakeYAML and apply the quoting fallback from the guide, but a small line-based parser shows the shape clearly:
public record SkillFrontmatter(String name, String description, String body) { public static SkillFrontmatter parse(String content) { if (!content.startsWith("---")) { throw new IllegalArgumentException("Missing frontmatter"); } int end = content.indexOf("\n---", 3); if (end < 0) { throw new IllegalArgumentException("Unclosed frontmatter"); } String header = content.substring(3, end); String body = content.substring(end + 4).strip(); String name = null; String description = null; for (String line : header.split("\n")) { int colon = line.indexOf(':'); if (colon < 0) continue; String key = line.substring(0, colon).strip(); String value = stripQuotes(line.substring(colon + 1).strip()); if (key.equals("name")) name = value; if (key.equals("description")) description = value; } if (name == null) { throw new IllegalArgumentException("Missing name"); } return new SkillFrontmatter(name, description, body); } private static String stripQuotes(String value) { if (value.length() >= 2 && (value.startsWith("\"") || value.startsWith("'"))) { return value.substring(1, value.length() - 1); } return value; } } Now the activation tool. It returns the body wrapped in the structured tags the guide recommends, and it lists bundled files without reading them:
@Component public class SkillActivationTools { private final SkillRegistry registry; public SkillActivationTools(SkillRegistry registry) { this.registry = registry; } @Tool(description = "Load the full instructions of an agent skill. " + "Call this before performing a task that matches a skill's description.") public String activateSkill( @ToolParam(description = "The exact name of the skill to activate") String name) { SkillDefinition skill = registry.find(name) .orElseThrow(() -> new IllegalArgumentException("Unknown skill: " + name)); try { String body = SkillFrontmatter.parse(Files.readString(skill.location())).body(); return """ <skill_content name="%s"> %s Skill directory: %s Relative paths in this skill are relative to the skill directory. <skill_resources> %s </skill_resources> </skill_content> """.formatted( skill.name(), body, skill.baseDirectory(), listResources(skill.baseDirectory())); } catch (IOException ex) { throw new UncheckedIOException(ex); } } private String listResources(Path base) throws IOException { // List, do not read: the model loads specific files on demand. try (Stream<Path> files = Files.walk(base, 3)) { return files.filter(Files::isRegularFile) .filter(p -> !p.getFileName().toString().equals("SKILL.md")) .limit(50) .map(p -> " <file>" + base.relativize(p) + "</file>") .collect(Collectors.joining("\n")); } } } Note that @ToolParam and the name argument are the only inputs the model controls. The tool resolves the name against the registry, which means the model cannot read an arbitrary file. The tool reads only files the registry discovered. That is a security property worth keeping: the activation tool is a lookup, not a file reader.
Finally, the catalog and the tool are wired into a ChatClient. The catalog goes into the system prompt, and the tool is registered as a default tool:
@Configuration public class AgentConfig { @Bean ChatClient agentChatClient(ChatClient.Builder builder, SkillRegistry registry, SkillActivationTools activationTools) { String catalog = registry.all().stream() .map(s -> "- %s: %s".formatted(s.name(), s.description())) .collect(Collectors.joining("\n")); String system = """ You are a helpful engineering assistant. The following skills provide specialized instructions for specific tasks. When a task matches a skill's description, call activateSkill with the skill's name to load its full instructions before proceeding. Available skills: %s """.formatted(catalog); return builder .defaultSystem(system) .defaultTools(activationTools) .build(); } } Two details in this wiring deserve attention. The catalog is built once at startup, which matches the guide's tier-1 behavior. And when the registry is empty, the wiring should skip both the catalog and the tool, as the guide advises. The version above omits that branch for brevity, but a production version should add it.
Context management
Once a skill is activated, its instructions sit in the conversation. Two problems follow. If the agent prunes or summarizes older messages to fit the context window, the skill can silently disappear, and the model keeps working without its instructions. The guide's answer is to protect skill content from pruning, either by flagging activation results or by recognizing the structured tags during compaction. The tags in the example above make that recognition straightforward.
The second problem is repetition. If the model activates the same skill twice, the instructions appear twice and waste tokens. A simple fix is to track activated skill names for the session and return a short acknowledgment instead of the full body on repeat calls.
The guide also mentions subagent delegation as an advanced option. Instead of injecting the skill into the main conversation, a separate session runs the skill and returns only a summary. This is useful for complex workflows that would otherwise flood the main context.
Security and trust
Three points deserve emphasis. The first is that a skill is untrusted instruction text. Project-level skills in a freshly cloned repository can steer the model, so loading them should depend on a trust decision by the user. The second is that the activation tool should resolve names against a known registry and never accept a path from the model. The example above does this by construction. The third is that bundled scripts are a separate permission question. If your agent can execute scripts from a skill directory, each execution needs the same scrutiny as any other tool call. The guide recommends allowlisting skill directories for reads so that the model does not trigger a permission prompt for every reference, but reads and executions are not the same risk.
When to choose each path
Use the file-read path when the model has a filesystem, the skills are local, and you have no need for permissions, analytics, or structured wrapping. It is the least code and the most portable across clients.
Use the tool-based path when the model cannot read files, when skills come from a remote registry or a database, when you need to enforce permissions or record activations, or when you want to shape the returned content. In a Spring application, it is the natural choice, because the registry, the permission checks, and the logging already live in your code.
Many agents support both. The guide notes that a dedicated tool is optional but useful even when the model can read files, which is a reasonable default if you are building a platform rather than a single script.
Key takeaways
- Progressive disclosure keeps the base context small: names and descriptions at startup, full instructions on activation, and resources on demand.
- The tool-based path is a delivery mechanism for the same
SKILL.mdfiles, useful when the model has no file access or when you need control over what is returned. - Discover skills in project and user scopes, let project skills override user skills, and gate project skills on trust.
- Parse leniently, but skip any skill without a description, since the description drives disclosure.
- Make the activation tool a registry lookup, not a file reader. The model should choose a skill name, not a path.
- List bundled resources without reading them, and load them only when the instructions reference them.
- Protect skill content from context pruning, and avoid re-injecting a skill that is already in context.
The guide is short, but it describes a complete lifecycle. If you are adding skills support to a Java agent, the tool-based path with Spring AI gives you that lifecycle in a few hundred lines, and the design decisions it forces, such as lookup over file access and tiered loading, are the ones that keep an agent predictable as the number of skills grows.
Sources
- Agent Skills, "How to add skills support to your agent": https://agentskills.io/integrate-skills#integration-approaches
- Agent Skills specification: https://agentskills.io/specification.md


