Skip to content

Python: Add SkillFrontmatter class#5730

Open
andresliszt wants to merge 4 commits intomicrosoft:mainfrom
andresliszt:gh-issue-5710
Open

Python: Add SkillFrontmatter class#5730
andresliszt wants to merge 4 commits intomicrosoft:mainfrom
andresliszt:gh-issue-5710

Conversation

@andresliszt
Copy link
Copy Markdown

@andresliszt andresliszt commented May 9, 2026

Motivation and Context

This PR supports #5710

Description

Creates the class SkillFrontmatter and use it in the Skill abstract class (and its child). I took as reference the dotnet implementation (SkillFrontmatter). I'm also using yaml to parse correctly the frontmatter section.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings May 9, 2026 22:25
@moonbox3 moonbox3 added the python label May 9, 2026
@github-actions github-actions Bot changed the title Add SkillFrontmatter class Python: Add SkillFrontmatter class May 9, 2026
def description(self) -> str:
"""Human-readable description, delegated from :attr:`frontmatter`."""
return self.frontmatter.description

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I exposed these properties for compatibility, not sure if they are needed though.

YAML_KV_RE = re.compile(
r"^\s*(\w+)\s*:\s*(?:[\"'](.+?)[\"']|(.+?))\s*$",
re.MULTILINE,
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using yaml, this is not needed.

Copy link
Copy Markdown
Author

@andresliszt andresliszt May 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naive question, I realzied that pyyaml is not a core dependency, however, I've seen pyyaml in other subpackages, should we parse the yaml manually here or add pyyaml as dependencies in core?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements an experimental SkillFrontmatter model for Python skills, aligning the Python Skill metadata surface area with the agentskills.io spec (and the existing .NET implementation). It updates skill discovery/parsing to return validated frontmatter instead of a (name, description) tuple, and refactors Skill/InlineSkill/FileSkill/ClassSkill to store and expose that frontmatter.

Changes:

  • Introduces SkillFrontmatter with validation (name/description/compatibility) and optional spec fields (license/allowed_tools/metadata).
  • Updates FileSkillsSource parsing to use YAML parsing for frontmatter and returns (frontmatter, content).
  • Refactors skill constructors and updates the test suite and public exports accordingly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
python/packages/core/agent_framework/_skills.py Adds SkillFrontmatter, refactors Skill to store frontmatter, switches file frontmatter parsing to YAML.
python/packages/core/agent_framework/init.py Exports SkillFrontmatter from the package API.
python/packages/core/tests/core/test_skills.py Updates tests for the new frontmatter-based APIs and adds SkillFrontmatter validation tests.
Comments suppressed due to low confidence (1)

python/packages/core/agent_framework/_skills.py:2550

  • _extract_frontmatter now returns SkillFrontmatter | None, but the docstring still says it returns a (name, description) tuple. Please update the Returns section to match the new return type (and include any behavior changes, e.g., optional fields parsing).
        """Extract and validate YAML frontmatter from a SKILL.md file.

        Parses the ``---``-delimited frontmatter block for ``name`` and
        ``description`` fields.

        Args:
            content: Raw text content of the SKILL.md file.
            skill_file_path: Path to the file (used in diagnostic messages only).

        Returns:
            A ``(name, description)`` tuple on success, or ``None`` if the
            frontmatter is missing, malformed, or fails validation.
        """

Comment on lines +58 to +59
import yaml

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I will parse without this library.

skill = InlineSkill(
name="db-skill",
description="Database operations",
SkillFrontmatter(name="db-skill", description="Database operations")
Comment on lines +2568 to +2576
# Normalize!
parsed = {k.lower(): v for k, v in raw_data.items()}

name: str | None = parsed.get("name")
description: str | None = parsed.get("description")
compatibility: str | None = parsed.get("compatibility")
allowed_tools_raw: str | None = parsed.get("allowed_tools")
allowed_tools = [t for t in allowed_tools_raw.split() if t] if allowed_tools_raw else []

)

return None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This validation happens in the SkillFrontmatter class added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants