Skills API Reference¶
Auto-generated API documentation for the skills module.
skills
¶
Agent Skills runtime — zero dependencies, stdlib only, Python 3.10+.
Part of zerodep: https://github.com/Oaklight/zerodep Copyright (c) 2026 Peng Ding. MIT License.
Parse, discover, manage, and select Agent Skills per the agentskills.io
specification. A skill is a folder with a SKILL.md file containing
YAML frontmatter (properties) and Markdown body (instructions). This module
provides:
- Parsing and validation of
SKILL.mdfiles. - Directory discovery of skills.
- A registry for managing multiple skills.
- Pluggable query-based skill selection (pre-filter to save tokens).
- System-prompt generation (catalog XML and activation XML).
Basic usage::
from skills import Skill, SkillRegistry
# Parse a single skill
skill = Skill.load("path/to/my-skill")
print(skill.name, skill.description)
# Discover and register skills
registry = SkillRegistry()
registry.discover("~/.agents/skills", ".agents/skills")
# Pre-select relevant skills for a query, then generate catalog
matches = registry.select("convert this PDF to markdown", top_k=5)
catalog = to_catalog([m.skill for m in matches])
# Generate full activation prompt for a skill
prompt = matches[0].skill.to_prompt()
Requires Python 3.10+.
SkillError
¶
ParseError
¶
Bases: SkillError
Raised when SKILL.md parsing fails.
ValidationError
¶
Bases: SkillError
Raised when a skill fails spec validation.
SkillProperties
dataclass
¶
SKILL.md frontmatter metadata per the Agent Skills spec.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Skill identifier — kebab-case, max 64 chars. |
description |
str
|
What the skill does and when to use it, max 1024 chars. |
license |
str | None
|
Optional license string (e.g. |
compatibility |
str | None
|
Optional compatibility notes, max 500 chars. |
allowed_tools |
str | None
|
Optional tool patterns the skill requires (experimental). |
metadata |
dict[str, str]
|
Arbitrary key-value pairs for client-specific properties. |
Source code in skills/skills.py
to_dict()
¶
Return a spec-conformant dictionary.
Only includes optional fields when they have values. The
allowed_tools key is emitted as allowed-tools to match the
YAML frontmatter convention.
Source code in skills/skills.py
from_dict(d)
classmethod
¶
Create SkillProperties from a spec-conformant dictionary.
Accepts both allowed_tools and allowed-tools key forms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
dict[str, Any]
|
Dictionary with at least |
required |
Returns:
| Type | Description |
|---|---|
SkillProperties
|
A |
Raises:
| Type | Description |
|---|---|
KeyError
|
If required fields are missing. |
Source code in skills/skills.py
Skill
¶
A parsed Agent Skill.
A skill consists of frontmatter properties (name, description, …),
Markdown instructions (the body of SKILL.md), and optional
resource directories (scripts/, references/, assets/).
Use the :meth:load and :meth:loads factory methods to create
instances.
Source code in skills/skills.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
path
property
¶
Skill directory path, or None if parsed from text.
properties
property
¶
Frontmatter metadata.
instructions
property
¶
Markdown body (agent instructions).
name
property
¶
Skill name (kebab-case identifier).
description
property
¶
One-line description of the skill.
scripts
property
¶
Executable scripts in the scripts/ directory.
references
property
¶
Reference documents in the references/ directory.
assets
property
¶
Asset files in the assets/ directory.
load(path)
classmethod
¶
Load a skill from a directory containing SKILL.md.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the skill directory (or directly to a |
required |
Returns:
| Type | Description |
|---|---|
Skill
|
A parsed |
Raises:
| Type | Description |
|---|---|
ParseError
|
If |
Source code in skills/skills.py
loads(text)
classmethod
¶
Parse a skill from SKILL.md text content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Full content of a |
required |
Returns:
| Type | Description |
|---|---|
Skill
|
A parsed |
Raises:
| Type | Description |
|---|---|
ParseError
|
If the text cannot be parsed. |
Source code in skills/skills.py
from_dict(d)
classmethod
¶
Create a Skill from a dictionary.
The dictionary should contain at least name, description,
and instructions keys. Optional keys: license,
compatibility, allowed-tools/allowed_tools,
metadata, path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
dict[str, Any]
|
Skill dictionary (e.g. from :meth: |
required |
Returns:
| Type | Description |
|---|---|
Skill
|
A |
Source code in skills/skills.py
to_dict()
¶
Return a dictionary with properties and instructions.
to_markdown()
¶
Serialize the skill back to SKILL.md format.
Generates a valid SKILL.md string with YAML frontmatter and
the Markdown instruction body. Round-trip safe::
original = Skill.loads(text)
rebuilt = Skill.loads(original.to_markdown())
assert original.name == rebuilt.name
Returns:
| Type | Description |
|---|---|
str
|
A complete |
Source code in skills/skills.py
describe()
¶
to_prompt(*, inline_resources=False, max_inline_bytes=64 * 1024)
¶
Generate the full activation prompt (Level 2 progressive disclosure).
Returns XML-wrapped skill content suitable for injection into an agent's system prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inline_resources
|
bool
|
If |
False
|
max_inline_bytes
|
int
|
Maximum file size (bytes) to inline. Files larger than this are listed by name only. Defaults to 64 KiB. |
64 * 1024
|
Source code in skills/skills.py
SelectionResult
dataclass
¶
Result of skill selection.
Attributes:
| Name | Type | Description |
|---|---|---|
skill |
Skill
|
The matched skill. |
score |
float
|
Relevance score (higher is better, scale depends on selector). |
Source code in skills/skills.py
Selector
¶
Bases: Protocol
Protocol for skill selection strategies.
Implement this protocol to create custom selectors (e.g. embedding-based,
reranker, or lightweight-LLM selectors). Any object with a matching
select method can be passed to :meth:SkillRegistry.select.
Source code in skills/skills.py
KeywordSelector
¶
Keyword overlap selector using token intersection.
Scores skills by the proportion of query tokens that appear in the skill's name and description. No external dependencies.
Source code in skills/skills.py
select(query, skills, top_k)
¶
Select skills by keyword overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query string. |
required |
skills
|
list[Skill]
|
Candidate skills to rank. |
required |
top_k
|
int
|
Maximum number of results. |
required |
Returns:
| Type | Description |
|---|---|
list[SelectionResult]
|
Top-k skills sorted by descending relevance score. |
Source code in skills/skills.py
BM25Selector
¶
BM25-based selector using the sibling search module.
Indexes skills by their name, description, and instructions, then ranks them using BM25 scoring.
Raises:
| Type | Description |
|---|---|
ImportError
|
If the sibling |
Source code in skills/skills.py
select(query, skills, top_k)
¶
Select skills using BM25 ranking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query string. |
required |
skills
|
list[Skill]
|
Candidate skills to rank. |
required |
top_k
|
int
|
Maximum number of results. |
required |
Returns:
| Type | Description |
|---|---|
list[SelectionResult]
|
Top-k skills sorted by descending BM25 score. |
Source code in skills/skills.py
SkillRegistry
¶
Registry for discovering, managing, and selecting skills.
Example::
registry = SkillRegistry()
registry.discover("~/.agents/skills", ".agents/skills")
# Pre-filter and generate catalog
matches = registry.select("convert PDF", top_k=5)
catalog = registry.to_catalog([m.skill for m in matches])
Source code in skills/skills.py
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | |
register(skill, *, override=False)
¶
Register a skill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skill
|
Skill
|
The skill to register. |
required |
override
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a skill with the same name is already registered
and override is |
Source code in skills/skills.py
unregister(name)
¶
Remove a skill by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Skill name to remove. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the skill is not registered. |
Source code in skills/skills.py
get(name)
¶
Get a skill by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Skill name. |
required |
Returns:
| Type | Description |
|---|---|
Skill
|
The registered skill. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the skill is not registered. |
Source code in skills/skills.py
list()
¶
discover(*paths, recursive=False, override=False)
¶
Scan directories for skills and register them.
Each path is scanned for subdirectories containing a SKILL.md
file. Discovered skills are automatically registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*paths
|
str | Path
|
Directories to scan. |
()
|
recursive
|
bool
|
If |
False
|
override
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
list[Skill]
|
List of newly discovered and registered skills. |
Source code in skills/skills.py
select(query, *, top_k=5, min_score=0.0, available_tools=None, selector=None)
¶
Pre-filter skills by relevance to a query.
This is a harness-side pre-selection to reduce the number of skills injected into the system prompt (saving tokens). The LLM then makes the final activation decision from the filtered catalog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query or task description. |
required |
top_k
|
int
|
Maximum number of skills to return. |
5
|
min_score
|
float
|
Minimum relevance score. Results below this
threshold are discarded before applying |
0.0
|
available_tools
|
Iterable[str] | None
|
If provided, only skills whose
|
None
|
selector
|
Selector | None
|
Selection strategy. Defaults to
:class: |
None
|
Returns:
| Type | Description |
|---|---|
list[SelectionResult]
|
Top-k skills sorted by descending relevance, all scoring |
list[SelectionResult]
|
at or above min_score. |
Source code in skills/skills.py
to_catalog(skills=None)
¶
Generate <available_skills> XML for a system prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skills
|
Iterable[Skill] | None
|
Subset of skills to include. If |
None
|
Returns:
| Type | Description |
|---|---|
str
|
XML string listing skill names, descriptions, and locations. |
Source code in skills/skills.py
validate(path)
¶
Validate a skill directory per the Agent Skills spec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a skill directory. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of problems found (empty means valid). |
Example::
problems = validate("my-skill")
if problems:
for p in problems:
print(f" - {p}")
Source code in skills/skills.py
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 | |
to_catalog(skills)
¶
Generate <available_skills> XML for a system prompt.
This is the Level-1 progressive disclosure format — skill names, descriptions, and locations suitable for an agent's catalog view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skills
|
Iterable[Skill]
|
Skills to include. |
required |
Returns:
| Type | Description |
|---|---|
str
|
XML string. |
Source code in skills/skills.py
compose(*skills)
¶
Compose multiple skills into a combined prompt.
Concatenates the activation prompts of all given skills, suitable for injecting into a system prompt when multiple skills are active simultaneously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*skills
|
Skill
|
Skills to compose. |
()
|
Returns:
| Type | Description |
|---|---|
str
|
Combined prompt string. |
Source code in skills/skills.py
load(path)
¶
Load a skill from a directory or SKILL.md file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the skill directory or file. |
required |
Returns:
| Type | Description |
|---|---|
Skill
|
A parsed |
loads(text)
¶
Parse a skill from SKILL.md text content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Full content of a |
required |
Returns:
| Type | Description |
|---|---|
Skill
|
A parsed |
discover(*paths, recursive=False)
¶
Discover skills in directories (convenience wrapper).
Creates a temporary registry, discovers skills, and returns them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*paths
|
str | Path
|
Directories to scan. |
()
|
recursive
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
list[Skill]
|
List of discovered skills. |
Source code in skills/skills.py
filter_compatible(skills, available_tools)
¶
Filter skills by tool compatibility.
A skill passes if it has no allowed_tools requirement, or if
every tool base name in its allowed_tools string is present in
available_tools.
Tool patterns like Bash(git:*) are matched by their base name
(bash). Matching is case-insensitive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skills
|
Iterable[Skill]
|
Skills to filter. |
required |
available_tools
|
Iterable[str]
|
Tool names available in the current environment
(e.g. |
required |
Returns:
| Type | Description |
|---|---|
list[Skill]
|
Skills whose tool requirements are satisfied. |
Example::
compatible = filter_compatible(
registry.list(),
available_tools=["Bash", "Read", "Write", "Glob"],
)