diff --git a/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProvider.cs b/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProvider.cs index 70d7939227..b7e8670cca 100644 --- a/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. using System; using System.Collections.Generic; @@ -162,7 +162,7 @@ public AgentSkillsProvider(AgentSkillsSource source, AgentSkillsProviderOptions? this._options = options; this._logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger(); - if (options?.SkillsInstructionPrompt is string prompt) + if ((options?.IncludeSkillInstructions ?? true) && options?.SkillsInstructionPrompt is string prompt) { ValidatePromptTemplate(prompt, nameof(options)); } @@ -260,6 +260,11 @@ private IList BuildTools(IList skills, bool hasScripts, private string? BuildSkillsInstructions(IList skills, bool includeScriptInstructions, bool includeResourceInstructions) { + if (this._options?.IncludeSkillInstructions == false) + { + return null; + } + string promptTemplate = this._options?.SkillsInstructionPrompt ?? DefaultSkillsInstructionPrompt; var sb = new StringBuilder(); diff --git a/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderBuilder.cs b/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderBuilder.cs index 8e52cc522e..e6c966496f 100644 --- a/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderBuilder.cs +++ b/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. using System; using System.Collections.Generic; @@ -139,6 +139,17 @@ public AgentSkillsProviderBuilder UseScriptApproval(bool enabled = true) return this; } + /// + /// Enables or disables including skill instructions in the system prompt. + /// + /// Whether to include skill instructions. Defaults to . + /// This builder instance for chaining. + public AgentSkillsProviderBuilder IncludeSkillInstructions(bool enabled = true) + { + this.GetOrCreateOptions().IncludeSkillInstructions = enabled; + return this; + } + /// /// Sets the runner for file-based skill scripts. /// diff --git a/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderOptions.cs b/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderOptions.cs index 2f89ebfda6..bed487aacb 100644 --- a/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderOptions.cs +++ b/dotnet/src/Microsoft.Agents.AI/Skills/AgentSkillsProviderOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. using System.Diagnostics.CodeAnalysis; using Microsoft.Shared.DiagnosticIds; @@ -34,4 +34,12 @@ public sealed class AgentSkillsProviderOptions /// Set to to rebuild tools and instructions on every invocation. /// public bool DisableCaching { get; set; } + + /// + /// Gets or sets a value indicating whether skill instructions should be included in the system prompt. + /// When (the default), skill names and descriptions are added + /// to the system prompt to guide the model on when to use specific skills. + /// Set to to skip including these instructions in the prompt. + /// + public bool IncludeSkillInstructions { get; set; } = true; } diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderBuilderTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderBuilderTests.cs index 85335256a7..c042eccc17 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderBuilderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderBuilderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. using System; using System.Collections.Generic; @@ -182,6 +182,23 @@ public void Build_UseOptions_ConfiguresOptions() Assert.NotNull(provider); } + [Fact] + public void Build_IncludeSkillInstructions_ConfiguresOptions() + { + // Arrange + var source = new TestAgentSkillsSource( + new TestAgentSkill("test", "Test", "Instructions.")); + + // Act + var provider = new AgentSkillsProviderBuilder() + .UseSource(source) + .IncludeSkillInstructions(false) + .Build(); + + // Assert + Assert.NotNull(provider); + } + [Fact] public async Task Build_WithMultipleCustomSources_AggregatesAllAsync() { diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderTests.cs index 87e98b3da3..994775e1d4 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentSkillsProviderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. using System; using System.Collections.Generic; @@ -851,6 +851,42 @@ public async Task Constructor_InlineSkills_DeduplicatesAsync() Assert.Contains("First instructions.", content!.ToString()!); } + [Fact] + public async Task InvokingAsync_IncludeSkillInstructionsFalse_ReturnsNullInstructionsAsync() + { + // Arrange + this.CreateSkill("skip-skill", "Skip test", "Body."); + var options = new AgentSkillsProviderOptions { IncludeSkillInstructions = false }; + var provider = new AgentSkillsProvider(new AgentFileSkillsSource(this._testRoot, s_noOpExecutor), options); + var inputContext = new AIContext { Instructions = "Base instructions" }; + var invokingContext = new AIContextProvider.InvokingContext(this._agent, session: null, inputContext); + + // Act + var result = await provider.InvokingAsync(invokingContext, CancellationToken.None); + + // Assert + Assert.Equal("Base instructions", result.Instructions); // Should not have changed + Assert.NotNull(result.Tools); + Assert.Contains(result.Tools!, t => t.Name == "load_skill"); + } + + [Fact] + public void Constructor_IncludeSkillInstructionsFalse_SkipsPromptValidation() + { + // Arrange — invalid prompt (missing placeholders) + var options = new AgentSkillsProviderOptions + { + IncludeSkillInstructions = false, + SkillsInstructionPrompt = "Invalid prompt without placeholders" + }; + + // Act — should not throw + var provider = new AgentSkillsProvider(new AgentFileSkillsSource(this._testRoot, s_noOpExecutor), options); + + // Assert + Assert.NotNull(provider); + } + /// /// A test skill source that counts how many times is called. ///