Skip to main content

Overview

SkillsManager implements Agent Skills: SKILL.md files on disk, discovered and rendered into a prompt section the agent sends to the model. 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 the class testable on its own:
Agent.call_llm then sends that section with every LLM call: as a leading system message when the call carries messages, otherwise in front of the task string. The tool-summary call gets it too. agent.system_prompt never changes, so repeated runs do not stack copies of the skills.

Constructor

Union[str, List[str]]
A directory, or a list of directories, containing skill folders. Each folder holds a SKILL.md file with YAML frontmatter. Directories are read in order. When two directories hold a skill with the same name, the later directory wins and a warning is logged. None disables skills entirely.
float
default:"0.3"
Minimum task/skill similarity for a skill to be selected during dynamic loading.

Attributes

Optional[Union[str, List[str]]]
The configured skills directory or directories.
float
The threshold passed to the dynamic loader.
List[Dict[str, str]]
Metadata for the skills loaded so far.
bool
Read-only. True when at least one configured directory 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 at or above similarity_threshold. The loader is built lazily on first use and reused afterwards, so it reads the skill directories once. Call set_skills_dir() to make it re-read them.

load_metadata

Tier 1 loading — scan one or more directories and return one dict per skill with name, description, path, and content. Defaults to the configured directories. A missing directory is logged and contributes nothing, so the result is [] when none exist. Within a directory, skill folders are read in sorted order. Across directories, a later skill replaces an earlier one with the same name.
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 or list of directories, discarding cached metadata and the dynamic loader.

Agent integration

Skills are selected at run() time, not construction. Each run(task) calls handle_skills(task) when skills_dir is set, so the selection follows the current task and replaces the previous one. agent.system_prompt never includes the skills.

Several directories

Pass a list to combine skill sets, for example your own skills and a shared team folder:
If both folders define code-review, the one in ./my_skills is used and a warning names the overridden file.

Standalone use

Agent Skills

Guide to authoring and using skills

Agent

The class that owns the manager