Skip to content

.NET: Fix FileAgentSkillsProvider custom SkillsInstructionPrompt silently dropping skills#4388

Merged
SergeyMenshykh merged 1 commit intomicrosoft:mainfrom
SergeyMenshykh:fix-for-4344
Mar 2, 2026
Merged

.NET: Fix FileAgentSkillsProvider custom SkillsInstructionPrompt silently dropping skills#4388
SergeyMenshykh merged 1 commit intomicrosoft:mainfrom
SergeyMenshykh:fix-for-4344

Conversation

@SergeyMenshykh
Copy link
Member

Fix

Fixes #4344

Problem

When providing a custom SkillsInstructionPrompt via FileAgentSkillsProviderOptions, the template validation in BuildSkillsInstructionPrompt prematurely rendered the template with an empty string and assigned the result back to promptTemplate:

promptTemplate = string.Format(optionsInstructions, string.Empty);

This replaced the {0} placeholder, so when the actual skills XML was later passed to string.Format(promptTemplate, sb.ToString()), it was silently discarded. The LLM never saw any skills in its system instructions.

Fix

The validation now discards the rendered result and preserves the original template:

_ = string.Format(optionsInstructions, string.Empty); // validate only
promptTemplate = optionsInstructions;                  // keep {0} intact

Test improvement

Strengthened the InvokingCoreAsync_CustomPromptTemplate_UsesCustomTemplateAsync test to verify that skill name and description actually appear in the rendered output, not just the template prefix.

Copilot AI review requested due to automatic review settings March 2, 2026 14:54
@github-actions github-actions bot changed the title Fix FileAgentSkillsProvider custom SkillsInstructionPrompt silently dropping skills .NET: Fix FileAgentSkillsProvider custom SkillsInstructionPrompt silently dropping skills Mar 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug in the .NET FileAgentSkillsProvider where supplying a custom SkillsInstructionPrompt could cause the generated skills list to be silently omitted from the final instructions presented to the LLM.

Changes:

  • Preserve the original custom prompt template after validation so the {0} placeholder remains available for later skills insertion.
  • Strengthen the unit test to assert that skill name and description appear in the rendered instructions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
dotnet/src/Microsoft.Agents.AI/Skills/FileAgentSkillsProvider.cs Fixes template validation so it no longer overwrites the {0} placeholder, preventing skills from being dropped.
dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/FileAgentSkillsProviderTests.cs Improves coverage by asserting rendered output includes skill name/description when using a custom template.
Comments suppressed due to low confidence (1)

dotnet/src/Microsoft.Agents.AI/Skills/FileAgentSkillsProvider.cs:183

  • The validation here doesn’t actually enforce that the custom prompt contains a {0} placeholder. string.Format("no placeholder", arg) succeeds and silently ignores the argument, which would still result in the generated skills list being dropped later in string.Format(promptTemplate, ...)—contradicting both the exception message and FileAgentSkillsProviderOptions docs. Consider explicitly verifying the placeholder is used (e.g., format with a unique sentinel and ensure it appears in the output, or check for an unescaped {0 format item) and throw an ArgumentException when it’s missing.
                _ = string.Format(optionsInstructions, string.Empty);
                promptTemplate = optionsInstructions;
            }
            catch (FormatException ex)
            {
                throw new ArgumentException(
                    "The provided SkillsInstructionPrompt is not a valid format string. It must contain a '{0}' placeholder and escape any literal '{' or '}' by doubling them ('{{' or '}}').",

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

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: FileAgentSkillsProvider custom SkillsInstructionPrompt silently drops all skills

5 participants