Agent Skills
The @cf-agents/skills package allows your agent to “learn” new capabilities at runtime by discovering and syncing code from GitHub repositories.
Features
Section titled “Features”- GitHub Discovery: Automatically find folders containing
SKILL.mdmarkers. - Recursive Syncing: Downloads all source files from a skill’s directory directly to Cloudflare R2.
- Embedded Search: Automatically indexes skill descriptions in Vectorize using Workers AI for instant retrieval.
Architecture: Why Progressive Disclosure?
Section titled “Architecture: Why Progressive Disclosure?”The @cf-agents/skills package implements a Two-Tier Discovery model designed for high-precision agents:
-
Tier 1: Global Manifest (Awareness): We maintain a lightweight
manifest.jsonin R2. This gives the agent a complete “catalog” of installed skills (names + short summaries) in the system prompt. Unlike pure vector search, the agent never has to “guess” if it has a capability. -
Tier 2: On-Demand Loading (Precision): When the agent identifies a relevant skill, it calls
loadSkillto retrieve the fullSKILL.mdinstructions. This ensures the environment stays lean, saving tokens and improving accuracy by avoiding context “noise.”
Comparison
Section titled “Comparison”| Feature | Pure Vector Search | Progressive Disclosure |
|---|---|---|
| Awareness | Blind (requires query) | Conscious (sees catalog) |
| Token Cost | Lower (search only) | Minimal (metadata only) |
| Logic Depth | Variable | High (loads full manual) |
| Scale | Unlimited | Optimized (10-100+ skills) |
Installation
Section titled “Installation”npm install @cf-agents/skillsCloudflare Requirements
Section titled “Cloudflare Requirements”To use dynamic skills, your Worker requires the following Cloudflare bindings:
- R2 Bucket: To store the downloaded skill files.
- Vectorize Index: To index and search skill descriptions.
- Workers AI: To generate embeddings during the installation process.
Configure wrangler.jsonc
Section titled “Configure wrangler.jsonc”{ "r2_buckets": [ { "binding": "FILES", "bucket_name": "your-skills-storage" } ], "vectorize": [ { "binding": "VECTOR_INDEX", "index_name": "your-skills-index" } ], "ai": { "binding": "AI" }}1. Initialize Tools
Section titled “1. Initialize Tools”Initialize the skills tools with your Cloudflare environment bindings.
import { createSkillsTools } from "@cf-agents/skills";
export default { async fetch(request, env) { const skillsTools = createSkillsTools({ AI: env.AI, FILES: env.FILES, VECTOR_INDEX: env.VECTOR_INDEX, githubToken: env.GITHUB_TOKEN // Optional for private repos });
// Provide these tools to your agent... }}2. Available Tools
Section titled “2. Available Tools”Once added to your agent’s toolset, the LLM can call:
addSkill({ url }): Pass a GitHub URL (e.g.,https://github.com/owner/repo) or shorthand (owner/repo). The agent will scan forSKILL.md, download the folder contents, and update the global manifest.loadSkill({ skillName }): Fetches the full content of a skill’sSKILL.mdfile. Use this when the agent needs specific instructions for a capability it already knows about.searchSkills({ query? }): Performs a vector search over installed skills to find relevant documentation or logic.deleteSkill({ skillName }): Removes a skill’s files from R2 and deletes its entry from the manifest and index.
Creating Your Own Skill
Section titled “Creating Your Own Skill”A skill is defined by a directory in a GitHub repository that contains a SKILL.md file.
- Create a folder in your repo (e.g.,
my-custom-skill/). - Add a
SKILL.mdfile describing what the skill does. - Place any logic, prompt snippets, or configuration inside that same folder.
When addSkill is called on that repository, the agent will discover your folder and sync everything inside it.