Skip to main content

Overview

SkillsManager implements Agent Skills: SKILL.md files on disk, discovered and folded into an agent’s system prompt. It supports the tiered loading model — name/description metadata kept in memory for context-aware activation (Tier 1), and a skill’s full body pulled on demand (Tier 2). Every Agent builds one automatically as agent.skills. It is also usable standalone.

Import

Design

The manager never mutates the agent. It returns prompt text and the caller decides what to do with it, which keeps prompt mutation in one visible place and makes the class testable on its own:

Constructor

str
Directory containing skill folders, each holding a SKILL.md file with YAML frontmatter. None disables skills entirely.
float
default:"0.3"
Minimum task/skill similarity for a skill to be selected during dynamic loading.

Attributes

Optional[str]
The configured skills directory.
List[Dict[str, str]]
Metadata for the skills loaded so far.
bool
Read-only. True when a directory is configured and exists on disk.

Skill format

Each skill is a folder containing a SKILL.md with YAML frontmatter:
SKILL.md
Malformed skills are skipped, never fatal — a file with no frontmatter, unterminated frontmatter, invalid YAML, or one that cannot be read is logged and passed over. A skill with no name in its frontmatter falls back to its folder name.

Methods

prompt_for_task

Build the skills prompt section. The task argument selects the loading strategy:
str
When provided, only skills whose description is similar to the task are loaded (dynamic). When None, every skill is loaded (static).
Returns the formatted prompt section, or "" when nothing loaded. Populates metadata as a side effect.
Uses DynamicSkillsLoader, which scores each skill’s description against the task by cosine similarity and keeps those above similarity_threshold. The loader is built lazily on first use and reused afterwards.

load_metadata

Tier 1 loading — scan a directory and return one dict per skill with name, description, path, and content. Defaults to the configured directory. Returns [] when the directory is missing. Entries are returned in sorted order for determinism.
load_metadata() returns metadata without assigning it to self.metadata. Only prompt_for_task() populates that attribute — and load_full_skill() reads from it. Calling load_metadata() alone and then load_full_skill() will always return None.

build_prompt

Render skill metadata as a prompt section. Returns "" for an empty list. The # Available Skills header is emitted exactly once, followed by each skill’s name, description, and body.

load_full_skill

Tier 2 loading — the complete markdown below the frontmatter for one skill, found by name in metadata. Returns None when the skill is unknown or the file has since become unreadable.

set_skills_dir

Point the manager at a different directory, discarding cached metadata and the dynamic loader.

Agent integration

Skills load at run() time, not construction, so an agent’s recorded system prompt at init does not yet include them.

Standalone use

Agent Skills

Guide to authoring and using skills

Agent

The class that owns the manager