Skip to content

Python: skill name validation improvements#4530

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/port-validation-improvements-to-python
Draft

Python: skill name validation improvements#4530
Copilot wants to merge 3 commits intomainfrom
copilot/port-validation-improvements-to-python

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

  • Update VALID_NAME_RE to reject consecutive hyphens
  • Update error message in _validate_skill_metadata to mention consecutive hyphens (split to stay within 120-char line limit)
  • In _read_and_parse_skill_file, enforce frontmatter name matches parent directory name
  • Add tests: consecutive hyphens rejected
  • Add tests: directory name mismatch rejected
  • Fix E501 lint error (line too long)
Original prompt

Create a PR in microsoft/agent-framework that ports the validation improvements from .NET PR #4526 to the Python agent skills implementation.

Context

Required behavior changes (Python)

  1. Skill name validation must reject consecutive hyphens
  • Update VALID_NAME_RE from the current pattern that allows consecutive hyphens to a pattern that disallows them (equivalent to .NET regex: ^[a-z0-9]([a-z0-9]*-[a-z0-9])*[a-z0-9]*$).
  • Update the corresponding validation error message in _validate_skill_metadata to mention that consecutive hyphens are not allowed.
  1. File-based skills: enforce that the name: from SKILL.md frontmatter matches the parent directory name
  • Implement this check in the file-based skill loading path after frontmatter extraction (best location: _read_and_parse_skill_file(skill_dir_path)), because it has access to the skill directory path.
  • On mismatch: log an error similar to .NET (include SKILL.md path, frontmatter name, directory name) and exclude the skill (return None).
  • For code-defined skills (created in Python code), do not apply directory matching.
  1. Tests
  • Add/extend Python unit tests to cover:
    • invalid skill names with consecutive hyphens (e.g. consecutive--hyphens) are rejected.
    • directory name mismatch (folder wrong-dir-name containing SKILL.md with frontmatter name: actual-skill-name) is rejected.
  • Keep tests consistent with existing repo testing patterns.

Notes

  • Ensure behavior remains case-sensitive for directory name match (align with .NET’s ordinal comparison).
  • Keep existing behavior for other invalid names (leading/trailing hyphen, spaces, etc.).
  • Run/adjust formatting/linting if the repo enforces it.

Files likely to change

  • python/packages/core/agent_framework/_skills.py
  • Python test file(s) that cover skills discovery/validation (discover via repo search).

Acceptance criteria

  • Python skill discovery rejects consecutive-hyphen names.
  • Python skill discovery rejects SKILL.md whose name: does not match the containing directory.
  • New/updated unit tests pass.

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…e hyphens and enforce directory name match

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Python agent skills validation for skill names Port .NET skill name validation improvements to Python: reject consecutive hyphens and enforce directory/name match Mar 6, 2026
@SergeyMenshykh SergeyMenshykh changed the title Port .NET skill name validation improvements to Python: reject consecutive hyphens and enforce directory/name match Python: skill name validation improvements Mar 6, 2026
@SergeyMenshykh
Copy link
Member

@copilot fix the failed check:

FAILED: lint in packages/core
Poe => ruff check
E501 Line too long (137 > 120)
--> agent_framework/_skills.py:735:121
|
733 | …
734 | …': Must be {MAX_NAME_LENGTH} characters or fewer, "
735 | …, and must not start or end with a hyphen or contain consecutive
hyphens."
|
^^^^^^^^^^^^^^^^^
736 | …
|

Found 1 error.

…ll_metadata

Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 6, 2026

@copilot fix the failed check:

FAILED: lint in packages/core
...

Fixed in 73bb51b — split the long string literal across two lines to stay within the 120-character limit.

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