.NET: Support reflection for discovery of resources and scripts in class-based skills#5183
Merged
SergeyMenshykh merged 5 commits intomicrosoft:mainfrom Apr 10, 2026
Conversation
4 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Adds attribute-based reflection discovery for resources and scripts in class-based .NET skills, enabling a more declarative model while keeping existing override-based patterns available.
Changes:
- Introduces
[AgentSkillResource]and[AgentSkillScript]attributes for declarative discovery. - Updates
AgentClassSkillto a CRTP generic (AgentClassSkill<TSelf>) and implements reflection-based discovery + caching. - Updates unit tests and samples to use the new generic base class and attribute-based approach (including DI scenarios).
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentClassSkill.cs | Converts to AgentClassSkill<TSelf>, adds reflection discovery + caching, and adds SerializerOptions support. |
| dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentSkillResourceAttribute.cs | Adds attribute for marking properties/methods as discoverable resources. |
| dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentSkillScriptAttribute.cs | Adds attribute for marking methods as discoverable scripts. |
| dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentInlineSkillResource.cs | Adds MethodInfo-based constructor for reflected resource members. |
| dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentInlineSkillScript.cs | Adds MethodInfo-based constructor for reflected script members. |
| dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderBuilder.cs | Updates docs to reference AgentClassSkill{TSelf}. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentClassSkillTests.cs | Expands coverage for reflection discovery, caching, DI, and serializer options behavior. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderTests.cs | Adjusts tests to accommodate AgentClassSkill<TSelf> and mixed AgentSkill collections. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillResourceAttributeTests.cs | Adds unit tests for AgentSkillResourceAttribute constructors. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillScriptAttributeTests.cs | Adds unit tests for AgentSkillScriptAttribute constructors. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentInlineSkillResourceTests.cs | Adds tests for MethodInfo-based resource behavior. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentInlineSkillScriptTests.cs | Adds tests for MethodInfo-based script behavior and schema. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step03_ClassBasedSkills/Program.cs | Updates class-based sample to attribute discovery + CRTP base class. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step03_ClassBasedSkills/README.md | Updates documentation to describe attribute discovery usage. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step03_ClassBasedSkills/Agent_Step03_ClassBasedSkills.csproj | Adds IDE warning suppression for attribute-only private members. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step04_MixedSkills/Program.cs | Updates mixed-skills sample to attribute discovery + CRTP base class. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step04_MixedSkills/Agent_Step04_MixedSkills.csproj | Adds IDE warning suppression for attribute-only private members. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step05_SkillsWithDI/Program.cs | Updates DI sample to attribute discovery for resource/script methods. |
| dotnet/samples/02-agents/AgentSkills/Agent_Step05_SkillsWithDI/Agent_Step05_SkillsWithDI.csproj | Adds IDE warning suppression for attribute-only private members. |
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentClassSkillTests.cs
Show resolved
Hide resolved
Add discovery-time validation in AgentClassSkill.DiscoverResources() to fail fast when [AgentSkillResource] is applied to members with incompatible signatures: - Reject indexer properties (getter has parameters) - Reject methods with parameters other than IServiceProvider or CancellationToken Throws InvalidOperationException with actionable error messages instead of allowing silent runtime failures when ReadAsync invokes the AIFunction with no named arguments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
westey-m
approved these changes
Apr 9, 2026
rogerbarreto
reviewed
Apr 9, 2026
...les/02-agents/AgentSkills/Agent_Step03_ClassBasedSkills/Agent_Step03_ClassBasedSkills.csproj
Show resolved
Hide resolved
rogerbarreto
reviewed
Apr 9, 2026
dotnet/samples/02-agents/AgentSkills/Agent_Step05_SkillsWithDI/Program.cs
Show resolved
Hide resolved
rogerbarreto
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for using reflection to discover resources and scripts in class-based skills, enabling a more declarative approach via attributes.
Changes
AgentSkillResourceAttributeandAgentSkillScriptAttributefor declarative resource/script discoveryAgentClassSkillto discover resources and scripts via reflection