Skip to content

.NET: Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync#6797

Merged
SergeyMenshykh merged 3 commits into
microsoft:mainfrom
SergeyMenshykh:sergeymenshykh-add-agent-skills-source-context
Jun 30, 2026
Merged

.NET: Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync#6797
SergeyMenshykh merged 3 commits into
microsoft:mainfrom
SergeyMenshykh:sergeymenshykh-add-agent-skills-source-context

Conversation

@SergeyMenshykh

@SergeyMenshykh SergeyMenshykh commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an AgentSkillsSourceContext (carrying Agent and optional Session) to AgentSkillsSource.GetSkillsAsync, so skill sources, filters, and caching can make context-aware decisions. The context is built by AgentSkillsProvider from the InvokingContext and flows through all sources and decorators.

Changes

  • AgentSkillsSourceContext exposes Agent and Session, supplied from the invoking context.
  • FilteringAgentSkillsSource predicate now receives an AgentSkillFilterContext bundling the skill and the source context.
  • CachingAgentSkillsSource supports per-key cache isolation via CachingAgentSkillsSourceOptions.CacheIsolationKeySelector; a null selector keeps the existing shared-cache behavior.

Closes: #6710

Pass agent/session context through the skills retrieval pipeline so
sources, filters, and caching can make context-aware decisions.

- AgentSkillsSourceContext (Agent, Session) is built by AgentSkillsProvider
  from the InvokingContext and flows through all sources and decorators.
- FilteringAgentSkillsSource predicate now receives an AgentSkillFilterContext
  bundling the skill and the source context.
- CachingAgentSkillsSource supports per-key isolation via
  CachingAgentSkillsSourceOptions.CacheIsolationKeySelector; a null selector
  preserves the shared-cache behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 29, 2026 13:03
@moonbox3 moonbox3 added the .NET Usage: [Issues, PRs], Target: .Net label Jun 29, 2026
@github-actions github-actions Bot changed the title Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync .NET: Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync Jun 29, 2026
@SergeyMenshykh SergeyMenshykh self-assigned this Jun 29, 2026
@SergeyMenshykh SergeyMenshykh moved this to In Review in Agent Framework Jun 29, 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 evolves the .NET “Agent Skills” pipeline to be context-aware by threading an AgentSkillsSourceContext (agent + optional session) through AgentSkillsSource.GetSkillsAsync, enabling downstream decorators (filtering/caching) and sources (including MCP) to make invocation-specific decisions.

Changes:

  • Add AgentSkillsSourceContext and update all AgentSkillsSource.GetSkillsAsync implementations/callers to accept it.
  • Update filtering to pass an AgentSkillFilterContext into the predicate so filters can consider both the skill and the source context.
  • Extend caching to support per-key cache isolation via CachingAgentSkillsSourceOptions.CacheIsolationKeySelector, and update unit tests accordingly.

Reviewed changes

Copilot reviewed 32 out of 32 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 Updates the core skills source abstraction to require a source context.
dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSourceContext.cs Introduces the new context object (agent + optional session).
dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProvider.cs Constructs and passes the source context from the invoking context.
dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderBuilder.cs Updates filter signature and adds caching options configuration.
dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillFilterContext.cs Adds the filter predicate context wrapper (skill + source context).
dotnet/src/Microsoft.Agents.AI/Skills/AggregatingAgentSkillsSource.cs Threads the source context through aggregated sources.
dotnet/src/Microsoft.Agents.AI/Skills/AgentInMemorySkillsSource.cs Updates in-memory source signature to accept the context.
dotnet/src/Microsoft.Agents.AI/Skills/File/AgentFileSkillsSource.cs Updates file-based source signature to accept the context.
dotnet/src/Microsoft.Agents.AI/Skills/Decorators/DelegatingAgentSkillsSource.cs Updates delegating decorator base to forward the context.
dotnet/src/Microsoft.Agents.AI/Skills/Decorators/FilteringAgentSkillsSource.cs Updates filtering decorator to build/pass AgentSkillFilterContext.
dotnet/src/Microsoft.Agents.AI/Skills/Decorators/DeduplicatingAgentSkillsSource.cs Updates dedup decorator to pass context through to inner source.
dotnet/src/Microsoft.Agents.AI/Skills/Decorators/CachingAgentSkillsSource.cs Implements per-isolation-key caching using a concurrent dictionary.
dotnet/src/Microsoft.Agents.AI/Skills/Decorators/CachingAgentSkillsSourceOptions.cs Adds options type for cache isolation key selection.
dotnet/src/Microsoft.Agents.AI/Microsoft.Agents.AI.csproj Adds InternalsVisibleTo for MCP unit tests (to use internal context ctor).
dotnet/src/Microsoft.Agents.AI.Mcp/Skills/AgentMcpSkillsSource.cs Updates MCP skills source signature and flows context into loaders.
dotnet/src/Microsoft.Agents.AI.Mcp/Skills/Loaders/IMcpSkillEntryLoader.cs Updates loader interface to accept AgentSkillsSourceContext.
dotnet/src/Microsoft.Agents.AI.Mcp/Skills/Loaders/SkillMdEntryLoader.cs Updates loader signature to accept context.
dotnet/src/Microsoft.Agents.AI.Mcp/Skills/Loaders/ArchiveEntryLoader.cs Updates loader signature; passes context into extracted file source discovery.
dotnet/tests/Microsoft.Agents.AI.UnitTests/TestAgentSkillsSourceContextFactory.cs Adds a test-only helper for constructing a skills source context.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/TestSkillTypes.cs Updates test source overrides to match the new signature.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/FilteringAgentSkillsSourceTests.cs Updates/extends tests for filter predicate context plumbing.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/DeduplicatingAgentSkillsSourceTests.cs Updates tests for new signature.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/CachingAgentSkillsSourceTests.cs Updates and adds tests for cache isolation keys.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderTests.cs Adds coverage ensuring agent/session flow into the source context.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderBuilderTests.cs Adds tests for caching options and updates filter signature usage.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentInMemorySkillsSourceTests.cs Updates tests for new signature.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/FileAgentSkillLoaderTests.cs Updates file loader tests to pass a context.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentFileSkillsSourceScriptTests.cs Updates script discovery/execution tests to pass a context.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentClassSkillTests.cs Updates class-skill tests to pass a context.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/TestAgentSkillsSourceContextFactory.cs Adds a MCP-test-specific context factory (custom agent type).
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/Skills/AgentMcpSkillsSourceTests.cs Updates MCP source tests for new signature.
dotnet/tests/Microsoft.Agents.AI.Mcp.UnitTests/Skills/AgentMcpSkillsSourceArchiveTests.cs Updates MCP archive tests for new signature.

Comment thread dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSourceContext.cs
Comment thread dotnet/src/Microsoft.Agents.AI/Skills/Decorators/CachingAgentSkillsSource.cs Outdated

@github-actions github-actions Bot 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.

Automated Code Review

Reviewers: 5 | Confidence: 89%

✓ Correctness

No actionable issues found in this dimension.

✓ Security Reliability

The PR cleanly threads AgentSkillsSourceContext through the skills pipeline. The main reliability concern is that the new CachingAgentSkillsSource uses a ConcurrentDictionary that grows without bound when CacheIsolationKeySelector produces many distinct keys (e.g., per-session), creating a potential memory leak in long-running services. The concurrency patterns are otherwise correct, and input validation is properly applied to the new context types.

✓ Test Coverage

The PR has solid test coverage for its core new behaviors: CachingAgentSkillsSource isolation keys are tested with same-key, different-key, and null-key scenarios; FilteringAgentSkillsSource has a dedicated test verifying context is passed to predicates; and AgentSkillsProviderBuilder has an integration test for cache isolation per agent. All existing tests are appropriately updated to pass the new context parameter. The only notable gap is that all test factory helpers use session: null, meaning no test exercises context-aware decisions based on a non-null Session value, though this is a minor concern given the Session property is simply a pass-through.

✓ Failure Modes

No actionable issues found in this dimension.

✗ Design Approach

That closes off direct use of AgentSkillsSource outside friend assemblies, which undercuts the extensibility this PR is trying to add.

Flagged Issues

  • AgentSkillsSource.GetSkillsAsync now requires AgentSkillsSourceContext (dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSource.cs:24), but AgentSkillsSourceContext's only constructor is internal (dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSourceContext.cs:21). External consumers can still derive or receive an AgentSkillsSource, but they can no longer call its public API directly or write non-friend tests for it.

Automated review by SergeyMenshykh's agents

@github-actions

Copy link
Copy Markdown
Contributor

Flagged issue

AgentSkillsSource.GetSkillsAsync now requires AgentSkillsSourceContext (dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSource.cs:24), but AgentSkillsSourceContext's only constructor is internal (dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSourceContext.cs:21). External consumers can still derive or receive an AgentSkillsSource, but they can no longer call its public API directly or write non-friend tests for it.


Source: automated DevFlow PR review

- Make the AgentSkillsSourceContext constructor public so external callers
  can invoke AgentSkillsSource.GetSkillsAsync directly; drop the
  Mcp.UnitTests InternalsVisibleTo entry it required.
- Use a dedicated sentinel cache key for the shared bucket so an isolation
  selector returning an empty string gets its own bucket.
- Document cache-key cardinality guidance and baseline the experimental
  API breaking changes in CompatibilitySuppressions.xml.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread dotnet/src/Microsoft.Agents.AI/Skills/Decorators/FilteringAgentSkillsSource.cs Outdated
Replace the AgentSkillFilterContext bundle with a
Func<AgentSkill, AgentSkillsSourceContext, bool> predicate in
FilteringAgentSkillsSource and AgentSkillsProviderBuilder.UseFilter, and
update the tests accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsSourceContext.cs
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Jun 30, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 30, 2026
@SergeyMenshykh SergeyMenshykh merged commit 09fbccf into microsoft:main Jun 30, 2026
27 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework Jun 30, 2026
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

Status: Done

Development

Successfully merging this pull request may close these issues.

.NET: Add AgentSkillsSourceContext to AgentSkillsSource.GetSkillsAsync

6 participants