Skip to content

.NET: Improve skills validation: reject consecutive hyphens and name-directory mismatches#4524

Closed
SergeyMenshykh wants to merge 1 commit intomicrosoft:mainfrom
SergeyMenshykh:skills-validation
Closed

.NET: Improve skills validation: reject consecutive hyphens and name-directory mismatches#4524
SergeyMenshykh wants to merge 1 commit intomicrosoft:mainfrom
SergeyMenshykh:skills-validation

Conversation

@SergeyMenshykh
Copy link
Member

Changes

  • Name regex: Updated to also reject consecutive hyphens (e.g., my--skill)
  • Name-directory mismatch validation: Added check that the skill name in frontmatter matches its parent directory name
  • Logging: Added LogNameDirectoryMismatch for clear diagnostics when names don't match
  • Error message: Updated to mention the consecutive hyphens restriction

Testing

All 484 unit tests pass, including FileAgentSkillLoaderTests. Full solution builds with 0 warnings/errors.

…ory mismatches

- Update name regex to reject consecutive hyphens (e.g., 'my--skill')
- Add validation that skill name matches its parent directory name
- Add LogNameDirectoryMismatch log message for diagnostic clarity
- Update error message to mention consecutive hyphens restriction

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 6, 2026 13:16
@github-actions github-actions bot changed the title Improve skills validation: reject consecutive hyphens and name-directory mismatches .NET: Improve skills validation: reject consecutive hyphens and name-directory mismatches Mar 6, 2026
@SergeyMenshykh SergeyMenshykh self-assigned this Mar 6, 2026
@SergeyMenshykh SergeyMenshykh moved this to In Review in Agent Framework Mar 6, 2026
@github-project-automation github-project-automation bot moved this from In Review to Done in Agent Framework Mar 6, 2026
Copy link
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 makes two improvements:

  1. Skills validation enhancements in FileAgentSkillLoader: the name regex now also rejects consecutive hyphens (e.g. my--skill), and a new check enforces that the skill's frontmatter name matches its parent directory name.
  2. Hosting lifetime API (unmentioned in the PR description): adds a ServiceLifetime lifetime parameter to every AddAIAgent, AddWorkflow, AddAsAIAgent, WithAITool(factory), and WithSessionStore(factory) overload; adds a Lifetime property to the public IHostedAgentBuilder interface; and introduces an AddKeyedService<T> internal helper. A ValidateToolLifetime guard prevents captive-dependency registrations for tools.

Changes:

  • Regex update to reject consecutive hyphens and new name-directory mismatch check in FileAgentSkillLoader
  • ServiceLifetime parameter added to all hosting registration overloads in Hosting source files
  • Corresponding tests added and existing tests updated for both skills validation and lifetime API

Reviewed changes

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

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI/Skills/FileAgentSkillLoader.cs Updated name regex and added name-directory mismatch validation and log message
dotnet/src/Microsoft.Agents.AI.Hosting/IHostedAgentBuilder.cs Added Lifetime property to the public interface
dotnet/src/Microsoft.Agents.AI.Hosting/HostedAgentBuilder.cs Implements the new Lifetime property
dotnet/src/Microsoft.Agents.AI.Hosting/AgentHostingServiceCollectionExtensions.cs Adds lifetime param to all AddAIAgent overloads; adds AddKeyedService<T> helper
dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderAgentExtensions.cs Adds lifetime param to host-builder AddAIAgent overloads
dotnet/src/Microsoft.Agents.AI.Hosting/HostApplicationBuilderWorkflowExtensions.cs Adds lifetime param to AddWorkflow
dotnet/src/Microsoft.Agents.AI.Hosting/HostedAgentBuilderExtensions.cs Adds lifetime to WithAITool(factory) and WithSessionStore(factory); adds ValidateToolLifetime
dotnet/src/Microsoft.Agents.AI.Hosting/HostedWorkflowBuilderExtensions.cs Adds lifetime to AddAsAIAgent overloads
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/FileAgentSkillLoaderTests.cs Adds test for consecutive hyphens, name-directory mismatch; updates duplicate-name test
dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/AgentHostingServiceCollectionExtensionsTests.cs Tests for scoped/transient lifetime registration and default lifetime
dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/HostApplicationBuilderAgentExtensionsTests.cs Tests for scoped/transient/lifetime-overload via host builder
dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/HostApplicationBuilderWorkflowExtensionsTests.cs Tests for workflow scoped/transient and AddAsAIAgent lifetime
dotnet/tests/Microsoft.Agents.AI.Hosting.UnitTests/HostedAgentBuilderToolsExtensionsTests.cs Tests for tool lifetime defaults, overrides, captive dependency guards

Comment on lines +22 to +25
/// <summary>
/// Gets the DI service lifetime used for the agent registration.
/// </summary>
ServiceLifetime Lifetime { get; }
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The PR title and description focus exclusively on "improving skills validation" (consecutive hyphens, name-directory mismatch). However, the bulk of the changes — adding a ServiceLifetime parameter to every AddAIAgent, AddWorkflow, AddAsAIAgent, WithAITool, and WithSessionStore overload, plus adding the Lifetime property to the public IHostedAgentBuilder interface — are not mentioned in the PR description at all. These are substantial API changes that affect the public surface of the library and deserve their own description, including any breaking-change implications for consumers who implement IHostedAgentBuilder.

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +25
/// <summary>
/// Gets the DI service lifetime used for the agent registration.
/// </summary>
ServiceLifetime Lifetime { get; }
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

Adding Lifetime to the public IHostedAgentBuilder interface is a breaking change. Any external code that implements this interface (e.g. for testing or custom agent builders) will fail to compile until it adds the new property. While the only known implementation in this repository is HostedAgentBuilder (internal), the interface is public and consumers may implement it. Consider whether this should have a default interface member implementation (e.g. ServiceLifetime Lifetime => ServiceLifetime.Singleton;) to preserve source compatibility for existing implementors, or whether a new IHostedAgentBuilderV2 interface is more appropriate. This is especially relevant given the library targets multi-frameworks (net8/net9/net10 + netstandard2.0/net472) — note that default interface members are not supported on netstandard2.0/net472.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants