.NET: Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync#6766
Open
feiyun0112 wants to merge 1 commit into
Open
.NET: Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync#6766feiyun0112 wants to merge 1 commit into
feiyun0112 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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
AgentSkillsSourceContextand adds it as a required parameter toAgentSkillsSource.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.GetSkillsAsyncreturns_cachedSkillswithout considering thecontextparameter. If caching is enabled (RefreshIntervalset) 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); | ||
|
|
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.
fix #6710