Learn how to extend your agent with specialized capabilities loaded at runtime with Agent Skills.
In this guide, you will learn how to extend your agent with Agent Skills, a lightweight, open format for adding specialized knowledge and workflows that load at runtime from markdown files.
At its core, a skill is a folder containing a SKILL.md file with metadata and instructions that tell an agent how to perform a specific task.
Every skill starts with a SKILL.md file containing YAML frontmatter and Markdown instructions:
---name: pdf-processingdescription: Extract text and tables from PDF files, fill forms, merge documents.---# PDF Processing## When to use this skillUse this skill when the user needs to work with PDF files...## How to extract text1. Use pdfplumber for text extraction...## How to fill forms...
The frontmatter requires:
name: A short identifier
description: Instructions for when to use this skill
The Markdown body contains the actual skill content with no restrictions on structure or content.
Access to a skill source to discover skills and load their content. This can be a filesystem, bundled static assets, an API, or a remote registry.
A load skill tool that reads the SKILL.md content into context
Command execution (optional) if skills bundle scripts (e.g. a full sandbox environment)
The loadSkill tool is a standard AI SDK tool, so you can implement its
execute function with any data source. A filesystem is only required when
your implementation reads skills from one. If a skill includes references,
assets, or scripts, give the agent tools that can access or run those resources.
This guide uses a generic sandbox abstraction for flexibility across
environments. If you're building for Node.js, you can use fs/promises and
child_process directly instead. You can also replace this abstraction with
bundled asset imports or network requests when your agent does not need a
filesystem.
Create a generic sandbox interface that provides a consistent way to interact with the filesystem. This abstraction lets you implement it differently depending on your environment (Node.js fs, a containerized sandbox, cloud storage, etc.):
Include discovered skills in the system prompt so the agent knows what's available:
function buildSkillsPrompt(skills: SkillMetadata[]): string { const skillsList = skills .map(s => `- ${s.name}: ${s.description}`) .join('\n'); return `## SkillsUse the \`loadSkill\` tool to load a skill when the user's requestwould benefit from specialized instructions.Available skills:${skillsList}`;}
The agent sees only names and descriptions. Full instructions stay out of the context window until loaded.
// Create sandbox (your filesystem/execution abstraction)const sandbox = createSandbox({ workingDirectory: process.cwd() });// Discover skills at startupconst skills = await discoverSkills(sandbox, [ '.agents/skills', '~/.config/agent/skills',]);// Run the agentconst result = await agent.run({ prompt: userMessage, options: { sandbox, skills },});
When a user asks something that matches a skill description, the agent calls loadSkill. The full instructions load into context, and the agent follows them using bash and readFile to access bundled resources.
Skills can reference files relative to their directory. The agent uses existing tools to access them:
Skill directory: /path/to/.agents/skills/my-skill# My Skill InstructionsRead the configuration template:templates/config.jsonRun the setup script:bash scripts/setup.sh
The agent sees the skill directory path in the tool result and prepends it when accessing templates/config.json or scripts/setup.sh. No special resource loading mechanism is needed—the agent uses the same tools it uses for everything else.