Building Agent Skills
1. Understanding the Agent Skills Concept
| Aspect | Description | Details |
|---|---|---|
| Definition | Core Idea | An Agent Skill is a modular, reusable component that enables AI agents to perform specific tasks or functions within a larger system. These skills can be composed, orchestrated, and refined to build complex AI workflows. |
| Components | Key Elements |
|
| Types | Common Variants |
|
Example: Skill Interface Definition
interface AgentSkill {
name: string;
description: string;
inputSchema: object;
outputSchema: object;
execute(context: any): Promise<any>;
}
Key Characteristics
- Modularity: Skills are designed to be reusable across different AI systems or workflows.
- Interoperability: Standardized interfaces allow skills to be composed and orchestrated.
- Extensibility: New skills can be added to enhance agent capabilities without modifying existing code.
- Context Awareness: Skills can leverage context from previous steps or external data sources.
2. Creating SKILL.md Files
SKILL.md files are documentation artifacts that define the capabilities, constraints, and usage patterns of AI agents in a structured format. These files help ensure consistency across agent behavior and provide clear guidelines for developers.
| Field | Description | Example |
|---|---|---|
| name | The name of the skill | Code Review Assistant |
| description | A brief overview of what the skill does | Reviews code for best practices and potential bugs |
| capabilities | List of specific actions the skill can perform | Identify security vulnerabilities, suggest refactoring |
| limitations | Known constraints or failure cases | Cannot understand context beyond current file |
| examples | Usage examples or expected inputs/outputs | Input: JavaScript code snippet; Output: List of issues |
Example: SKILL.md Template
# Code Review Assistant
## Description
Reviews code for best practices and potential bugs.
## Capabilities
- Identify security vulnerabilities
- Suggest refactoring improvements
- Detect common anti-patterns
## Limitations
- Cannot understand context beyond current file
- Does not handle complex multi-file logic
## Examples
### Input:
```javascript
if (userInput === 'admin') {
grantAccess();
}
```
### Output:
- Security Risk: Hardcoded admin credentials
- Recommendation: Use environment variables or config files
3. Defining Skill Metadata and Descriptions
| Field | Description | Example |
|---|---|---|
| name | Unique identifier for the skill | "codeReview" |
| description | Human-readable explanation of the skill's purpose | "Reviews code for best practices and potential bugs" |
| version | Current version of the skill (semver) | "1.2.0" |
| author | Creator or maintainer of the skill | "Jane Smith" |
| tags | Array of keywords for categorization | ["review", "best-practices", "bug-detection"] |
| requires | Dependencies or prerequisites for skill execution | ["eslint", "typescript"] |
Example: Skill Metadata Configuration
{
"name": "codeReview",
"description": "Reviews code for best practices and potential bugs",
"version": "1.2.0",
"author": "Jane Smith",
"tags": ["review", "best-practices", "bug-detection"],
"requires": ["eslint", "typescript"]
}
Note: Metadata should be concise but descriptive to help agents understand when and how to use the skill.
4. Structuring Skill Instructions
| Element | Description | Best Practice |
|---|---|---|
| Goal Definition | Clear statement of what the skill should achieve | Use SMART criteria (Specific, Measurable, Achievable, Relevant, Time-bound) |
| Context Setup | Information needed for the skill to understand its environment | Include relevant data, constraints, and external dependencies |
| Action Steps | Sequential steps or decision points in skill execution | Break complex actions into atomic, testable units |
| Success Criteria | Mechanisms to validate skill completion or performance | Define measurable outcomes and thresholds for success |
Example: Goal Definition
# Skill: Code Review Assistant
## Goal:
Automatically analyze pull requests for common code quality issues and security vulnerabilities.
Example: Context Setup
{
"context": {
"repoName": "frontend-app",
"branch": "feature/new-ui",
"pullRequestUrl": "https://github.com/org/repo/pull/123",
"language": "JavaScript",
"framework": "React"
}
}
Example: Action Steps
1. Parse the diff to identify modified files
2. Analyze each file for syntax errors or style violations
3. Check for security issues in code patterns (e.g., hardcoded secrets)
4. Generate a report with findings and suggestions
Example: Success Criteria
{
"successCriteria": {
"maxIssuesFound": 5,
"accuracyThreshold": 0.95,
"responseTimeMs": 3000
}
}
5. Referencing External Files from Skills
| File Type | Reference Method | Notes |
|---|---|---|
| JavaScript/TypeScript | require('./path/to/file') or import from './path/to/file' |
Supports CommonJS and ES modules. Relative paths required. |
| JSON | require('./data.json') |
Direct import of JSON files supported in Node.js. |
| Text/Config | fs.readFileSync('./config.txt', 'utf8') |
Use Node.js fs module for reading text files. |
| Images | import img from './assets/image.png' |
Supported via bundlers like Webpack or Vite. |
Example: Importing a JSON Configuration File
const config = require('./config.json');
console.log(config.apiKey); // "abc123"
Note: When using external files in AI agent skills, ensure file paths are relative to the skill’s root directory or use absolute paths for clarity.
6. Triggering Skills Automatically
| Skill | Trigger Type | Configuration | Notes |
|---|---|---|---|
| Code Completion | onSave |
{ "trigger": "onSave", "context": "file" } |
Triggers when a file is saved in the editor |
| Code Review | onPush |
{ "trigger": "onPush", "context": "commit" } |
Automatically reviews code changes on git push |
| Bug Detection | onError |
{ "trigger": "onError", "context": "runtime" } |
Triggers when runtime errors occur |
Example: Auto-triggered Code Review
{
"skills": [
{
"name": "Code Review",
"trigger": "onPush",
"config": {
"repository": "my-project",
"branch": "main"
}
}
]
}
Note: Triggers can be customized with
context and conditions to refine when skills activate.
7. Scoping Skills to Specific Domains
| Skill | Domain | Description | Usage |
|---|---|---|---|
| Natural Language Processing | Text Analysis | Processes and understands human language | Used in chatbots, sentiment analysis |
| Code Generation | Software Development | Writes code based on natural language prompts | Assists developers in writing functions, classes |
| Data Visualization | Data Science | Transforms datasets into visual formats | Helps in exploratory data analysis and reporting |
| Image Recognition | Computer Vision | Identifies and classifies objects in images | Used in autonomous vehicles, medical imaging |
| Recommendation Systems | E-commerce, Media | Suggests items or content based on user behavior | Power platforms like Netflix, Amazon |
Example: Domain-Specific Skill Configuration
const agent = new AIAssistant({
skills: [
{
name: 'Code Generation',
domain: 'Software Development',
enabled: true,
parameters: {
language: 'JavaScript',
framework: 'React'
}
},
{
name: 'Data Visualization',
domain: 'Data Science',
enabled: true,
parameters: {
chartType: 'bar',
dataFormat: 'JSON'
}
}
]
});
Note: Scoping skills to specific domains ensures that the AI assistant operates within defined boundaries, enhancing accuracy and relevance for targeted use cases.
8. Packaging and Sharing Skills
| Field | Description | Example |
|---|---|---|
| name | Name of the skill package | "code-assistant" |
| version | Version of the skill (semantic versioning) | "1.0.0" |
| description | Short description of the skill's purpose | "Assists in writing clean JavaScript code" |
| main | Entry point for the skill module | "dist/index.js" |
| keywords | Keywords for searchability | ["ai", "javascript", "coding"] |
| author | Author or organization name | "Acme Corp" |
| license | License type (e.g., MIT, Apache-2.0) | "MIT" |
Example: Package.json for an AI Skill
{
"name": "ai-code-assistant",
"version": "1.2.0",
"description": "An AI skill that helps developers write better code by suggesting improvements and refactoring options.",
"main": "dist/index.js",
"keywords": ["ai", "code", "refactor", "assistant"],
"author": "Acme Corp",
"license": "MIT"
}
Note: The
main field should point to a built version of your skill, not source files.
Best Practices for Packaging AI Skills
- Use semantic versioning to track changes in skill behavior or API.
- Include a README.md with usage instructions and examples.
- Ensure the skill is self-contained or clearly lists dependencies.
- Use a consistent naming convention to make skills discoverable.
Package Formats for AI Skills
- NPM Package: Standard Node.js package format, ideal for JavaScript/TypeScript skills.
- ZIP Archive: Simple distribution format, useful for cross-platform sharing.
- Container Image: Docker image format, best for skills requiring specific runtime environments.
9. Debugging Skill Invocation
| Aspect | Description | Tools/Methods |
|---|---|---|
| Skill Invocation Logs | Logs generated when a skill is invoked, capturing input parameters and execution flow. | console.log, logger.info |
| Error Tracing | Tracing errors from skill invocation to root cause in the agent's logic or external API. | Stack traces, error reporters |
| Input Validation | Verifying that skill inputs match expected formats and constraints. | Schema validation libraries (e.g., Joi, Zod) |
| Execution Flow | Tracking the sequence of skill invocations to identify bottlenecks or missteps. | Tracing tools (e.g., OpenTelemetry), custom flow logs |
Example: Logging Skill Invocation
const skillLogger = (skillName, input, output) => {
console.log(`[Skill] ${skillName} invoked with input:`, input);
console.log(`[Skill] ${skillName} returned output:`, output);
};
// Usage in agent logic
const result = await invokeSkill('fetchUserData', { userId: 123 });
skillLogger('fetchUserData', { userId: 123 }, result);
Note: Use structured logging to capture skill invocation data for easier analysis and debugging.
Warning: Avoid logging sensitive data in skill invocation logs to prevent security vulnerabilities.