Skip to main content

How to Give a Microsoft Agent Framework Agent a Skill from a SKILL.md File in C#

· 13 min read
Jagdish Kumawat
Founder @ Dewiride

A skill is a set of instructions for one kind of task, kept in a SKILL.md file, that an agent loads only when a request needs it. This guide gives a Microsoft Agent Framework agent a haiku skill from a SKILL.md file, and the run shows the agent loading the skill and following its rules.

Syntax​

A skill is a folder with a SKILL.md file in it:

skills/<skill-name>/SKILL.md
---
name: <skill-name>
description: <what the skill does and when to use it>
---

<instructions>

An AgentSkillsProvider finds the skills in a folder and gives them to an agent:

Syntax
AgentSkillsProvider <provider> = new(
<skillsFolder>,
options: new AgentSkillsProviderOptions { DisableLoadSkillApproval = <noApproval> });

AIAgent <agent> = <projectClient>.AsAIAgent(new ChatClientAgentOptions
{
ChatOptions = new ChatOptions { ModelId = "<deployment>", Instructions = "<agentInstructions>" },
AIContextProviders = [<provider>],
});
PartWhat it is
<skill-name>The skill's name. Microsoft's Agent Skills guide sets the rules: at most 64 characters, Lowercase letters, numbers, and hyphens only, no hyphen at the start or end and no two in a row, and the name Must match the parent directory name.
<what the skill does and when to use it>The description: What the skill does and when to use it. At most 1,024 characters. The agent decides from it whether a request needs the skill.
<instructions>The Markdown after the front matter: the steps the agent follows once it loads the skill. The guide's advice: Keep SKILL.md under 500 lines and move detailed reference material to separate files.
<skillsFolder>The folder that holds the skill folders. This constructor, in Agent Framework's reference, discovers file-based skills from a single directory.
<noApproval>true lets the agent load a skill without asking first. DisableLoadSkillApproval's reference: When false (the default), the tool requires approval before invocation.
AIContextProvidersThe agent's context providers, which add context to every run. Its reference: Gets or sets the list of AIContextProvider instances to use for providing additional context for each agent run.
<provider>, <agent>Your names for the provider and the agent.
<projectClient>An AIProjectClient for your Microsoft Foundry project.
<deployment>The name of your model deployment.
<agentInstructions>The agent's own instructions.

The front matter between the two --- lines is YAML, and its field names are lowercase. The guide warns: Invalid YAML, duplicate recognized fields, incorrect field casing, or a collection where a scalar field is expected prevent the skill from loading.

How the agent uses a skill: the guide calls it progressive disclosure, and the provider does it in steps. First, Skill names and descriptions are injected into the system prompt at the start of each run, so the agent knows what skills are available. Then, When a task matches a skill's domain, the agent calls the load_skill tool to retrieve the full SKILL.md body with detailed instructions. The instructions cost tokens only in the runs that need them. Skills can also carry resources and scripts, which the agent reads and runs with two more tools; the skill here has neither.

Approval: All tools exposed by AgentSkillsProvider (load_skill, read_skill_resource, run_skill_script) require approval by default. DisableLoadSkillApproval = true lets the agent call load_skill without asking, which suits a skill you wrote yourself: loading it only reads its SKILL.md file.

The Example​

A console app called HaikuWriter has one skill, haiku, in skills/haiku/SKILL.md. Its agent, PoemWriter, is told only that it writes short poems in plain text. The skill adds four rules for haiku: three lines of 5, 7 and 5 syllables, one moment in nature in the present tense, a title in capital letters, and the season in brackets after the poem. The app asks for a haiku about rain on a window, prints the tools the agent called, and then prints the answer.

The model is billed per token. gpt-5.6-luna on a Global Standard deployment costs $0.20 per million input tokens and $1.20 per million output tokens, and the run below made 2 requests to the model with 852 input and 143 output tokens in all: $0.00034.

Prerequisites​

  • The .NET 10 SDK.
  • A Microsoft Foundry project with a deployed chat model, and the Foundry User role on it.
  • The Azure CLI, signed in with az login.

Step 1: Create a Console App​

Terminal
dotnet new console -n HaikuWriter
cd HaikuWriter
dotnet add package Microsoft.Agents.AI.Foundry --version 1.28.0-preview.261106.1
dotnet add package Azure.Identity --version 1.21.0
  • dotnet new console -n HaikuWriter creates a console app in a new HaikuWriter folder, and cd moves into it.
  • Microsoft.Agents.AI.Foundry is Agent Framework's package for Microsoft Foundry. Version 1.28.0-preview.261106.1 is a preview release. It brings in Agent Framework itself, Microsoft.Agents.AI 1.28.0, which is generally available.
  • Azure.Identity lets the app sign in to Foundry with your Azure CLI account.

Step 2: Write the Skill​

Create a folder called skills in the HaikuWriter folder, a folder called haiku inside it, and a file called SKILL.md in that one:

skills/haiku/SKILL.md
---
name: haiku
description: Writes haiku poems. Use when someone asks for a haiku.
---

# Haiku

When someone asks for a haiku:

1. Write three lines of 5, 7 and 5 syllables.
2. Write about one moment in nature, in the present tense.
3. Put a title above the poem, in capital letters.
4. After the poem, add the season it belongs to in brackets, such as [Season: spring].
  • name: haiku matches the folder's name, haiku, as the format requires.
  • description says what the skill does and when to use it. The agent sees this line in every run.
  • The body, from # Haiku down, is what load_skill returns when the agent asks for the skill.

Step 3: Copy the Skills Folder to the Build Output​

The app will look for the skills folder in the folder it runs from, so the build has to copy it there. Open HaikuWriter.csproj and add the second ItemGroup:

HaikuWriter.csproj
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.21.0" />
<PackageReference Include="Microsoft.Agents.AI.Foundry" Version="1.28.0-preview.261106.1" />
</ItemGroup>

<ItemGroup>
<None Update="skills/**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>

The first ItemGroup holds the two packages that dotnet add package added. The second copies every file in skills and its subfolders to the build output; How to Copy a Folder to the Build Output in a .NET C# Project explains this line and what happens without it.

Step 4: Give the Agent the Skill​

Replace everything in Program.cs with the skills provider:

Program.cs (the skills)
using System.Text.Json;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;

// The skills in the skills folder next to the app. Loading a skill only reads its SKILL.md file,
// so the agent may do it without asking.
AgentSkillsProvider skills = new(
Path.Combine(AppContext.BaseDirectory, "skills"),
options: new AgentSkillsProviderOptions { DisableLoadSkillApproval = true });
  • Path.Combine(AppContext.BaseDirectory, "skills") is the skills folder in the build output, where Step 3 copies it.
  • new AgentSkillsProvider(...) finds every skill folder in there with a SKILL.md file: here, only haiku. Its reference describes the second parameter, a script runner, as Required only when skills contain scripts. This skill has none, so the code leaves it out.
  • DisableLoadSkillApproval = true lets the agent load a skill without asking you first.

Add the agent below it:

Program.cs (the agent)
AIAgent agent = new AIProjectClient(
new Uri("https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp"),
new AzureCliCredential())
.AsAIAgent(new ChatClientAgentOptions
{
Name = "PoemWriter",
ChatOptions = new ChatOptions
{
ModelId = "gpt-5.6-luna",
Instructions = "You write short poems. Answer in plain text, without Markdown.",
},
AIContextProviders = [skills],
});
  • new AIProjectClient(...) connects to the Foundry project at that endpoint, and AzureCliCredential signs in with the account you used for az login, so there's no key in the code. Use your own project endpoint and model deployment.
  • AsAIAgent(new ChatClientAgentOptions { ... }) creates the agent. Its reference: Creates a non-versioned ChatClientAgent backed by the project's Responses API using the specified options.
  • ModelId is the model deployment, and Instructions are the agent's own instructions. They say nothing about titles or seasons.
  • AIContextProviders = [skills] adds the skills provider to the agent, so every run gets the skill list and the load_skill tool. How to Add Instructions to Every Agent Run with an AIContextProvider in C# shows how a context provider works.

Step 5: Ask for a Haiku​

Add the question and the lines that print what came back:

Program.cs (the run)
AgentResponse response = await agent.RunAsync("Write a haiku about rain on a window.");

// The tools the agent called while it answered.
foreach (FunctionCallContent call in response.Messages.SelectMany(message => message.Contents).OfType<FunctionCallContent>())
{
Console.WriteLine($"Tool call: {call.Name} {JsonSerializer.Serialize(call.Arguments)}");
}

Console.WriteLine();
Console.WriteLine(response.Text);
  • agent.RunAsync(...) sends the request and returns the agent's response.
  • response.Messages holds every message of the run, including the tool calls. SelectMany gathers the parts of all the messages, and OfType<FunctionCallContent>() keeps the tool calls.
  • JsonSerializer.Serialize(call.Arguments) prints the arguments the agent passed, as JSON.
  • response.Text is the agent's answer.

Step 6: Run It​

Terminal
dotnet run
Output
Tool call: load_skill {"skillName":"haiku"}

RAIN ON GLASS

Rain taps the window
Silver rivers softly run
Night listens within

[Season: spring]

macOS-style terminal window titled Terminal — HaikuWriter showing dotnet run printing Tool call: load_skill with skillName haiku, then a haiku titled RAIN ON GLASS in capital letters, three lines about rain on a window, and Season: spring in brackets

The agent called load_skill with "skillName":"haiku": it matched the request to the skill's description and asked for the full instructions. The run made two requests to the model, one that ended in the load_skill call and one that wrote the poem with the skill's instructions in hand.

The answer follows every rule in the file, and the agent's own instructions asked for none of them:

  • RAIN ON GLASS is the title in capital letters (rule 3).
  • The three lines have 5, 7 and 5 syllables, about one moment in nature, in the present tense: taps, run, listens (rules 1 and 2).
  • [Season: spring] is the season in brackets, in the form the file showed (rule 4).

Clean Up​

The agent works on Foundry's Responses API, and Foundry stores the responses a run creates, so the run left its two responses in the project. Microsoft's Responses API guide: By default, response data is retained for 30 days. How to Delete a Stored Response in Microsoft Foundry with the Azure CLI deletes one sooner by its ID, and How to Keep Microsoft Foundry from Storing an Agent's Conversations in C# shows an agent that stores nothing.

The Complete File​

Program.cs
using System.Text.Json;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;

// The skills in the skills folder next to the app. Loading a skill only reads its SKILL.md file,
// so the agent may do it without asking.
AgentSkillsProvider skills = new(
Path.Combine(AppContext.BaseDirectory, "skills"),
options: new AgentSkillsProviderOptions { DisableLoadSkillApproval = true });

AIAgent agent = new AIProjectClient(
new Uri("https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp"),
new AzureCliCredential())
.AsAIAgent(new ChatClientAgentOptions
{
Name = "PoemWriter",
ChatOptions = new ChatOptions
{
ModelId = "gpt-5.6-luna",
Instructions = "You write short poems. Answer in plain text, without Markdown.",
},
AIContextProviders = [skills],
});

AgentResponse response = await agent.RunAsync("Write a haiku about rain on a window.");

// The tools the agent called while it answered.
foreach (FunctionCallContent call in response.Messages.SelectMany(message => message.Contents).OfType<FunctionCallContent>())
{
Console.WriteLine($"Tool call: {call.Name} {JsonSerializer.Serialize(call.Arguments)}");
}

Console.WriteLine();
Console.WriteLine(response.Text);

macOS-style code window titled Program.cs — HaikuWriter showing an AgentSkillsProvider for the skills folder next to the app with DisableLoadSkillApproval set to true, a PoemWriter agent on the Foundry project with the provider in AIContextProviders, and a run that prints each tool call and then the answer

Common Mistakes​

MistakeWhat happensDo this instead
Giving the folder a different name from the skill's nameThe file breaks a rule of the format: the name must match its folderKeep them the same, such as skills/haiku and name: haiku
Writing Name: or Description: with a capital letterMicrosoft's guide: incorrect field casing prevents the skill from loadingWrite the field names in lowercase
Leaving out the None item in the project fileThe skills folder isn't copied to the build output, where AppContext.BaseDirectory pointsAdd <None Update="skills/**" CopyToOutputDirectory="PreserveNewest" />
Leaving DisableLoadSkillApproval out and handling no approvalsload_skill needs approval by default, so the agent pauses with an approval request instead of loading the skillSet it to true for skills you trust, or answer the approval requests

FAQ​

Does the agent read every skill's instructions in every run?​

No. Every run carries each skill's name and description, and the guide puts that at about 100 tokens per skill. The instructions come only through load_skill, in the runs that need them.

Can one folder hold several skills?​

Yes. Each skill is its own folder with its own SKILL.md, all inside the folder you give the provider. The guide: each subdirectory containing a SKILL.md is automatically discovered as a skill, and The provider searches up to two levels deep.

Should I turn off approval for every skill?​

Only for skills you trust. Agent Framework's reference warns that a skill's content is injected into the agent's context as-is, without validation or sanitization, so a compromised or adversarial source can attempt indirect prompt injection.

Conclusion​

A SKILL.md file with a name, a description and its instructions, a skills folder copied to the build output, and an AgentSkillsProvider in the agent's AIContextProviders give an agent a skill. In the run, the agent saw only the skill's description until it called load_skill, and then wrote a haiku with a capital-letter title and [Season: spring]: rules that only the skill gave it.

Additional Resources​