skills#
Utilities for reading, writing and inspecting Agent Skill files.
A skill is a directory that contains, at minimum, a SKILL.md file made up
of YAML frontmatter followed by a Markdown body. In addition to SKILL.md a
skill may bundle supporting resources, conventionally grouped under
scripts/, references/ and assets/ (any other files/directories are
allowed too).
The format follows the Agent Skills specification: https://agentskills.io/specification
Design notes#
Resource files (everything besides
SKILL.md) are discovered and tracked as paths relative to the skill root, but their contents are not loaded eagerly. This mirrors the spec’s progressive-disclosure model and avoids pulling large reference files into memory. UseSkill.list_resources()andSkill.read_resource()to access them on demand.The skill is keyed off its directory (not the
SKILL.mdfile directly), because the spec requiresnameto match the parent directory name.
Functions
|
Filter skills by their |
|
Load every skill found directly under |
Classes
|
An Agent Skill loaded from (or destined for) a directory on disk. |
|
Structured representation of the |
|
A collection of skills discovered under one or more root directories. |
Exceptions
Raised when a skill cannot be parsed, validated or written. |
- exception kernelfoundry.algorithm.utils.skills.SkillError[source]#
Raised when a skill cannot be parsed, validated or written.
- class kernelfoundry.algorithm.utils.skills.SkillFrontmatter(name: str, description: str, license: str | None = None, compatibility: str | None = None, metadata: ~typing.Dict[str, ~typing.Any] = <factory>, allowed_tools: str | None = None, extra: ~typing.Dict[str, ~typing.Any] = <factory>)[source]#
Structured representation of the
SKILL.mdYAML frontmatter.Only
nameanddescriptionare required by the specification. The remaining fields are optional and default to empty/None.extracaptures any non-standard frontmatter keys so they survive a load/save round-trip.- to_dict() Dict[str, Any][source]#
Render the frontmatter back to an ordered mapping for YAML output.
- class kernelfoundry.algorithm.utils.skills.Skill(frontmatter: ~kernelfoundry.algorithm.utils.skills.SkillFrontmatter, body: str = '', root: ~pathlib.Path | None = None, resources: ~typing.List[~pathlib.Path] = <factory>)[source]#
An Agent Skill loaded from (or destined for) a directory on disk.
- frontmatter#
Parsed
SKILL.mdfrontmatter.
- root#
Directory the skill was loaded from, if any.
- Type:
pathlib.Path | None
- resources#
Resource file paths relative to
root, excludingSKILL.md. Discovered lazily on load; contents are not read.- Type:
List[pathlib.Path]
- frontmatter: SkillFrontmatter#
- get_metadata(key: str, default: Any | None = None) Any[source]#
Return a single value from the frontmatter
metadatamapping.
- classmethod parse(text: str) Skill[source]#
Parse the raw text of a
SKILL.mdfile into frontmatter + body.
- classmethod load(path: str | Path, validate: bool = True, discover_resources: bool = True) Skill[source]#
Load a skill from a directory or directly from a
SKILL.mdfile.- Parameters:
path – Either the skill directory or the
SKILL.mdfile inside it.validate – Validate frontmatter against the spec after loading.
discover_resources – Scan the skill directory for bundled resource files (everything besides
SKILL.md).
- Returns:
The loaded
Skill.
- list_resources(subdir: str | None = None) List[Path][source]#
List tracked resource paths, optionally filtered to a subdirectory.
- Parameters:
subdir – e.g.
"scripts","references"or"assets".
- read_resource(relative: str | Path, binary: bool = False)[source]#
Read a bundled resource file on demand.
- Parameters:
relative – Path relative to the skill root (e.g.
scripts/run.py).binary – Read bytes instead of text.
- save(path: str | Path, validate: bool = True, copy_resources: bool = True) Path[source]#
Write the skill to
path(a directory) and return the skill root.- Parameters:
path – Target skill directory. Created if it does not exist.
validate – Validate frontmatter before writing.
copy_resources – Copy tracked resource files from the original
rootinto the target directory. Ignored when the target is the same as the source.
- Returns:
The skill root directory that was written.
- kernelfoundry.algorithm.utils.skills.load_skills(directory: str | Path, validate: bool = True) List[Skill][source]#
Load every skill found directly under
directory.A subdirectory is treated as a skill if it contains a
SKILL.mdfile.
- kernelfoundry.algorithm.utils.skills.filter_skills(skills: Iterable[Skill], languages_include: Iterable[str] | None = None, languages_exclude: Iterable[str] | None = None, tags_include: Iterable[str] | None = None, tags_exclude: Iterable[str] | None = None) List[Skill][source]#
Filter skills by their
languagesandtagsmetadata.For each key (
languages,tags) the include/exclude lists are applied independently and a skill must satisfy all provided constraints:*_include: keep the skill only if it has at least one of these values for the key. An empty/Noneinclude list imposes no constraint.*_exclude: drop the skill if it has any of these values for the key.
- Parameters:
skills – Skills to filter.
languages_include – Keep skills whose
metadata['languages']contains any of these values.languages_exclude – Drop skills whose
metadata['languages']contains any of these values.tags_include – Keep skills whose
metadata['tags']contains any of these values.tags_exclude – Drop skills whose
metadata['tags']contains any of these values.
- Returns:
The list of skills that pass every constraint.
- class kernelfoundry.algorithm.utils.skills.SkillLibrary(skills: Iterable[Skill] | None = None)[source]#
A collection of skills discovered under one or more root directories.
Skills are found by recursively scanning for
SKILL.mdfiles, so nested layouts such asskills/opencl/opencl-gemm/SKILL.mdare supported.- classmethod load(root: str | Path, validate: bool = True) SkillLibrary[source]#
Recursively load every skill under
rootinto a library.
- filter(languages_include: Iterable[str] | None = None, languages_exclude: Iterable[str] | None = None, tags_include: Iterable[str] | None = None, tags_exclude: Iterable[str] | None = None) List[Skill][source]#
Filter the library’s skills by
languagesandtagsmetadata.See
filter_skills()for the include/exclude semantics.