Skip to content

.NET: Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync#6766

Open
feiyun0112 wants to merge 1 commit into
microsoft:mainfrom
feiyun0112:issues/6710
Open

.NET: Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync#6766
feiyun0112 wants to merge 1 commit into
microsoft:mainfrom
feiyun0112:issues/6710

Conversation

@feiyun0112

Copy link
Copy Markdown

fix #6710

Copilot AI review requested due to automatic review settings June 26, 2026 13:24
@moonbox3 moonbox3 added the .NET Usage: [Issues, PRs], Target: .Net label Jun 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the .NET Agent Skills pipeline so AgentSkillsSource.GetSkillsAsync receives an invocation context (AgentSkillsSourceContext) that exposes the invoking AIAgent, enabling context-aware skill discovery (e.g., per-agent filtering) and addressing #6710.

Changes:

  • Introduces AgentSkillsSourceContext and adds it as a required parameter to AgentSkillsSource.GetSkillsAsync.
  • Threads the context through AgentSkillsProvider, built-in skill sources, decorators, and MCP skill loaders.
  • Updates unit tests (and adds new tests) to validate context creation and propagation.

Reviewed changes

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

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSource.cs Breaking API update: GetSkillsAsync now requires an AgentSkillsSourceContext.
dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSourceContext.cs Adds the new context type that carries the invoking AIAgent.
dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProvider.cs Creates/passes AgentSkillsSourceContext into the configured skills source pipeline.
dotnet/src/Microsoft.Agents.AI/Skills/AgentInMemorySkillsSource.cs Updates in-memory source to accept the new context parameter.
dotnet/src/Microsoft.Agents.AI/Skills/File/AgentFileSkillsSource.cs Updates file-based source to accept the new context parameter.
dotnet/src/Microsoft.Agents.AI/Skills/AggregatingAgentSkillsSource.cs Updates aggregator to propagate context through child sources.
dotnet/src/Microsoft.Agents.AI/Skills/Decorators/DelegatingAgentSkillsSource.cs Updates delegating decorator to propagate context to the inner source.
dotnet/src/Microsoft.Agents.AI/Skills/Decorators/FilteringAgentSkillsSource.cs Updates filtering decorator to propagate context to the inner source.
dotnet/src/Microsoft.Agents.AI/Skills/Decorators/DeduplicatingAgentSkillsSource.cs Updates deduping decorator to propagate context to the inner source.
dotnet/src/Microsoft.Agents.AI.Mcp/Skills/AgentMcpSkillsSource.cs Updates MCP source to accept context and pass it through to core discovery/loader pipeline.
dotnet/src/Microsoft.Agents.AI.Mcp/Skills/Loaders/IMcpSkillEntryLoader.cs Extends MCP loader interface to accept the skills source context.
dotnet/src/Microsoft.Agents.AI.Mcp/Skills/Loaders/SkillMdEntryLoader.cs Updates skill-md loader signature to accept the new context parameter.
dotnet/src/Microsoft.Agents.AI.Mcp/Skills/Loaders/ArchiveEntryLoader.cs Updates archive loader signature and forwards context into the file-based skills source.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsSourceContextTests.cs New tests covering AgentSkillsSourceContext construction and propagation through provider/decorators.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/TestSkillTypes.cs Updates test skill source to accept/capture the new context parameter.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/FilteringAgentSkillsSourceTests.cs Updates filtering tests to pass a context to GetSkillsAsync.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/DeduplicatingAgentSkillsSourceTests.cs Updates deduping tests (and a fake source) to use the new signature/context.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentInMemorySkillsSourceTests.cs Updates in-memory source tests to pass a context to GetSkillsAsync.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/FileAgentSkillLoaderTests.cs Updates file loader tests to pass a context to GetSkillsAsync.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentFileSkillsSourceScriptTests.cs Updates file script discovery/execution tests to pass a context to GetSkillsAsync.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderTests.cs Updates provider tests and helper sources for the new signature/context.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentClassSkillTests.cs Updates class-skill tests to pass a context when invoking skills sources.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/TestAIAgent.cs Adds a minimal AIAgent implementation for MCP unit tests that now require context construction.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/Skills/AgentMcpSkillsSourceTests.cs Updates MCP skills source tests to pass a context to GetSkillsAsync.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/Skills/AgentMcpSkillsSourceArchiveTests.cs Updates MCP archive tests to pass a context to GetSkillsAsync.
Comments suppressed due to low confidence (1)

dotnet/src/Microsoft.Agents.AI.Mcp/Skills/AgentMcpSkillsSource.cs:86

  • AgentMcpSkillsSource.GetSkillsAsync returns _cachedSkills without considering the context parameter. If caching is enabled (RefreshInterval set) and skill discovery ever becomes context-dependent (as the new API enables), callers with different contexts/agents can receive a cached result computed for a different context.
    public override async Task<IList<AgentSkill>> GetSkillsAsync(AgentSkillsSourceContext context, CancellationToken cancellationToken = default)
    {
        if (this.TryGetCachedSkills() is { } cached)
        {
            return cached;
        }

Comment on lines +21 to +24
/// <param name="context">The context for the current invocation, exposing the invoking <see cref="AIAgent"/>.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A collection of skills from this source.</returns>
public abstract Task<IList<AgentSkill>> GetSkillsAsync(CancellationToken cancellationToken = default);
public abstract Task<IList<AgentSkill>> GetSkillsAsync(AgentSkillsSourceContext context, CancellationToken cancellationToken = default);
Comment on lines 233 to 237
private async Task<AIContext> CreateContextAsync(InvokingContext context, CancellationToken cancellationToken)
{
var skills = await this._source.GetSkillsAsync(cancellationToken).ConfigureAwait(false);
var skillsContext = new AgentSkillsSourceContext(context.Agent);
var skills = await this._source.GetSkillsAsync(skillsContext, cancellationToken).ConfigureAwait(false);
if (skills is not { Count: > 0 })
Comment on lines 99 to 103
{
// The refresh owner uses CancellationToken.None so that a single caller's cancellation
// does not abort the shared refresh for all concurrent waiters.
var skills = await this.GetCoreSkillsAsync(CancellationToken.None).ConfigureAwait(false);
var skills = await this.GetCoreSkillsAsync(context, CancellationToken.None).ConfigureAwait(false);

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

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync

3 participants