Skip to main content

Agent Skills

Everything in an agent's instructions goes to the model with every request, whether the question needs it or not. Agent Skills package instructions, reference files and scripts as skills that the model knows only by name and description, until a question needs one and it loads the rest. This tutorial builds a recipe helper with two skills: a recipe book in a folder, and a shopping list defined in C#, with a script that runs only after a person approves it.

How Agent Skills Work​

A skill is a folder with a SKILL.md​

Microsoft's documentation describes them in one line: Agent Skills are portable packages of instructions, scripts, and resources that give agents specialized capabilities and domain expertise. A skill is a folder. In it, a file named SKILL.md holds the skill itself, and other files can sit next to it: reference documents, templates and scripts.

SKILL.md starts with YAML front matter between two --- lines, and the instructions follow in Markdown. The front matter needs two fields:

FieldWhat it holds
nameThe skill's name: lowercase letters, numbers and hyphens, at most 64 characters, and the same as the name of its folder
descriptionWhat the skill does and when to use it, in at most 1,024 characters

Everything after the front matter is the body: the instructions the model follows when it uses the skill. Microsoft's guide: Keep SKILL.md under 500 lines and move detailed reference material to separate files.

Load only what a question needs​

Microsoft's guide: Skills follow an open specification and implement a progressive disclosure pattern so agents load only the context they need, when they need it. Progressive disclosure has four stages:

  1. Advertise. On every run, each skill's name and description go into the instructions, about 100 tokens a skill, so the model knows which skills exist.
  2. Load. When a question fits a skill, the model calls the load_skill tool and gets the body of its SKILL.md.
  3. Read resources. When the body points to another file of the skill, the model reads it with read_skill_resource.
  4. Run scripts. When the skill has a script, the model runs it with run_skill_script.

The model decides each step itself, from what the step before gave it. A skill that no question needs costs its line in the instructions and nothing more.

Where Agent Framework fits​

AgentSkillsProvider puts skills on an agent. It's a context provider, like the ones in Context Providers and Memory: before each run, it adds the skills' names and descriptions to the instructions, and the skill tools to the request. It gets the skills from sources:

SourceWhat it gives the provider
AgentFileSkillsSourceThe skills in folders on disk, one SKILL.md each
AgentInMemorySkillsSourceSkills defined in code, such as an AgentInlineSkill
AggregatingAgentSkillsSourceThe skills of several sources together
DeduplicatingAgentSkillsSourceAnother source's skills, keeping only the first skill of each name
CachingAgentSkillsSourceAnother source's skills, fetched once and then reused

For one folder of skills, the provider has a constructor that takes the folder's path and creates the sources itself. For several sources, there's a builder, AgentSkillsProviderBuilder, or you can put the sources together yourself, which Step 8 does, and explains why.

Every skill tool asks first​

By default, all three tools wait for a person's approval before they run, like the tool in Tool Approval. Microsoft's guide: All tools exposed by AgentSkillsProvider (load_skill, read_skill_resource, run_skill_script) require approval by default. Loading a skill and reading its files only read text, but a script does whatever its code does. Steps 4 and 5 show what the default means for a run, and how to change it for the two tools that only read.

The Example​

A console app called RecipeHelper helps a family cook from their recipe book. It has two skills:

  • recipe-book, a folder with a SKILL.md and a reference file of recipes. The SKILL.md tells the model to answer only from the recipes, and how to scale a recipe for more people.
  • shopping-list, defined in C#, with a script, add-items, that puts things on the family's shopping list, a list in the app.

The app first asks "What do I need to make pancakes?", which needs only the recipe book. At the end, it asks "I'm making pancakes for 6 people. Put what I need on my shopping list.", which needs both skills and the script.

What It Costs​

The model is gpt-5.6-luna, at $0.20 per million input tokens and $1.20 per million output tokens. I ran the final app once more with its token usage printed: the whole conversation, from the question to the answer, used 3,685 input tokens and 378 output tokens, about a tenth of a cent. The skills themselves are files and code in your app, and cost nothing.

Prerequisites​

Step 1: Create a Console App​

In a terminal, in the folder where you keep your projects, run:

Terminal
dotnet new console -n RecipeHelper
cd RecipeHelper
dotnet add package Microsoft.Agents.AI.Foundry --version 1.28.0-preview.261106.1
dotnet add package Azure.Identity --version 1.21.0
Output (the important lines)
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /Users/you/source/RecipeHelper/RecipeHelper.csproj:
Restore succeeded.

info : PackageReference for package 'Microsoft.Agents.AI.Foundry' version '1.28.0-preview.261106.1' added to file '/Users/you/source/RecipeHelper/RecipeHelper.csproj'.
log : Restored /Users/you/source/RecipeHelper/RecipeHelper.csproj (in 1.55 sec).
info : PackageReference for package 'Azure.Identity' version '1.21.0' added to file '/Users/you/source/RecipeHelper/RecipeHelper.csproj'.
log : Restored /Users/you/source/RecipeHelper/RecipeHelper.csproj (in 1.12 sec).

The same two packages as in the previous tutorials. Microsoft.Agents.AI.Foundry, a preview, brings in Agent Framework, and AgentSkillsProvider and the other skill classes come with it. Open the RecipeHelper folder in VS Code, or RecipeHelper.csproj in Visual Studio.

Step 2: Write the Recipe Book Skill​

In the RecipeHelper folder, create a folder named skills, in it a folder named recipe-book, and in that a file named SKILL.md:

skills/recipe-book/SKILL.md
---
name: recipe-book
description: The family recipe book. Use when someone asks which ingredients a recipe needs, how much of each, or how to make it.
---

# Recipe book

Answer only from the recipes in references/recipes.md. Read that file before you answer.

- Give each quantity exactly as the recipe lists it, for the number of servings the recipe states.
- For a different number of people, multiply every quantity by the new number of servings divided by the recipe's servings. Round grams and millilitres to the nearest 5.
- If the book doesn't have the recipe, say so. Never make one up.
  • name: recipe-book is the same as the folder's name, as the format requires.
  • description is all the model sees of the skill until it loads it, so it says what the skill holds and which questions it answers: the ingredients of a recipe, how much of each, and how to make it.
  • The body is what load_skill returns. It sends the model to the recipes, and gives three rules: quantities exactly as written, how to scale a recipe for a different number of people, and never to invent a recipe.

A macOS-style code window titled SKILL.md — RecipeHelper showing the recipe book skill: YAML front matter with the name recipe-book and a description that says to use it when someone asks which ingredients a recipe needs, how much of each, or how to make it, then a Recipe book heading, an instruction to answer only from references/recipes.md and to read it first, and three rules on exact quantities, scaling for a different number of people with grams and millilitres rounded to the nearest 5, and never making up a recipe

Then, in recipe-book, create a folder named references, with the recipes in a file named recipes.md:

skills/recipe-book/references/recipes.md
# Recipes

## Pancakes (serves 4)

- 200 g plain flour
- 300 ml milk
- 2 eggs
- 25 g sugar
- 1 pinch of salt

Whisk everything into a smooth batter and let it rest for 10 minutes. Fry a ladleful at a time in a hot, buttered pan, about 1 minute on each side.

## Tomato soup (serves 2)

- 500 g ripe tomatoes
- 1 onion
- 400 ml vegetable stock
- 1 tablespoon olive oil

Soften the chopped onion in the oil. Add the tomatoes and the stock, simmer for 20 minutes, then blend until smooth.

This file is a resource of the skill. The model reads it with read_skill_resource when the body tells it to, by its path inside the skill: references/recipes.md. By default, the provider recognizes text files such as .md, .json and .txt as resources, and Microsoft's guide says it searches up to two levels deep within each skill directory.

The project folder now holds these files (bin and obj left out):

RecipeHelper
RecipeHelper/
├── Program.cs
├── RecipeHelper.csproj
└── skills/
└── recipe-book/
├── SKILL.md
└── references/
└── recipes.md

Step 3: Copy the Skills Next to the App​

The app will look for its skills in the folder it runs from, AppContext.BaseDirectory, which .NET's reference describes as the file path of the base directory of the application. With dotnet run, that's the build output folder, bin/Debug/net10.0, not the project folder, so the build has to copy the skills there. Open RecipeHelper.csproj and add an item group before the closing </Project> tag:

RecipeHelper.csproj (the new item group)
<ItemGroup>
<None Update="skills/**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
  • None items are the project's files that aren't compiled. The .NET SDK adds them itself: all other files tracked in the project, such as configuration and content files, that aren't compiled or embedded. So the skills' files are None items already.
  • Update changes those items. Adding them again with Include would put the same files in the build twice, which the SDK stops with error NETSDK1022, while customizations with Update are supported.
  • skills/** matches every file under skills, in every folder below it.
  • CopyToOutputDirectory="PreserveNewest" copies the files to the build output folder, and copies a file again only when the project's copy is newer.

After a build, bin/Debug/net10.0 holds skills/recipe-book/SKILL.md and skills/recipe-book/references/recipes.md, next to the app. How to Copy a Folder to the Build Output in a .NET C# Project shows this item on its own.

The complete project file:

RecipeHelper.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>

Step 4: Give the Agent the Skills​

Replace everything in Program.cs with:

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

// 1. The skills in the skills folder next to the app.
AgentSkillsProvider skills = new(Path.Combine(AppContext.BaseDirectory, "skills"));

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 = "RecipeHelper",
ChatOptions = new ChatOptions
{
ModelId = "gpt-5.6-luna",
Instructions = "You help a family cook from their recipe book. Answer in plain text, without Markdown.",
},
AIContextProviders = [skills],
});

AgentSession session = await agent.CreateSessionAsync();
AgentResponse response = await agent.RunAsync("What do I need to make pancakes?", session);
PrintCalls(response);
Console.WriteLine($"Answer: {response.Text}");

// Prints the tool calls and approval requests in a response.
static void PrintCalls(AgentResponse response)
{
foreach (AIContent content in response.Messages.SelectMany(message => message.Contents))
{
switch (content)
{
case ToolApprovalRequestContent request:
Console.WriteLine($" Approval needed: {((FunctionCallContent)request.ToolCall).Name}");
break;
case FunctionCallContent call:
Console.WriteLine($" Tool call: {call.Name} {System.Text.Json.JsonSerializer.Serialize(call.Arguments)}");
break;
}
}
}
  • new AgentSkillsProvider(...) with a folder's path creates the provider and its sources: every folder below skills that holds a SKILL.md is a skill. This constructor also drops skills with a name that's already taken, and caches the list.
  • AIContextProviders = [skills] attaches the provider to the agent, like any context provider.
  • ChatClientAgentOptions sets the agent's name, its model and its own instructions. As in the earlier tutorials, AIProjectClient.AsAIAgent creates an agent that uses Foundry's Responses API.
  • PrintCalls goes through the response's contents and prints each tool call with its arguments, and each approval request, so the output shows what the model asked for.

Run it:

Terminal
dotnet run

Use your own project endpoint and model deployment.

Output
Approval needed: load_skill
Answer:

No answer. The model called load_skill, the first step of using a skill, and that tool needs approval. So the run stopped and returned a ToolApprovalRequestContent instead of an answer, and response.Text is empty. The API documentation of DisableLoadSkillApproval: When false (the default), the tool requires approval before invocation.

An app could answer the request with the approval loop from Tool Approval. But load_skill and read_skill_resource only read skills you wrote yourself, and asking a person about them would hold up every answer.

Step 5: Let the Reading Tools Run Without Asking​

Replace the provider at the top of the file:

Program.cs (the provider)
// 1. The skills in the skills folder next to the app. Loading a skill and reading its files
// only read text you wrote, so they run without asking.
AgentSkillsProvider skills = new(
Path.Combine(AppContext.BaseDirectory, "skills"),
options: new AgentSkillsProviderOptions
{
DisableLoadSkillApproval = true,
DisableReadSkillResourceApproval = true,
});

AgentSkillsProviderOptions turns approval off one tool at a time. Microsoft's guide: Use AgentSkillsProviderOptions to disable approval for individual tools, removing them from the approval flow entirely. DisableRunSkillScriptApproval stays false, so scripts still ask.

Run it again:

Output
Tool call: load_skill {"skillName":"recipe-book"}
Tool call: read_skill_resource {"skillName":"recipe-book","resourceName":"references/recipes.md"}
Answer: To make pancakes (serves 4), you need:

200 g plain flour
300 ml milk
2 eggs
25 g sugar
1 pinch of salt

Whisk everything into a smooth batter and let it rest for 10 minutes. Fry a ladleful at a time in a hot, buttered pan, about 1 minute on each side.

That's progressive disclosure, one stage at a time:

  • load_skill with the skill's name returned the body of SKILL.md.
  • The body says to read references/recipes.md first, so the model called read_skill_resource with that path.
  • The answer comes from the book: the quantities for 4, as the recipe lists them, and the method, word for word.

Step 6: See What the Model Is Told​

The output shows which tools the model called, but not what it was given. IChatClient middleware, from Middleware, sees every request the agent sends to the model. Replace the agent with this version, which declares a request counter first and adds a clientFactory:

Program.cs (the counter and the agent)
// 2. Counts the requests the agent sends to the model. It's declared before the agent,
// because the agent's middleware uses it.
int requestNumber = 0;

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 = "RecipeHelper",
ChatOptions = new ChatOptions
{
ModelId = "gpt-5.6-luna",
Instructions = "You help a family cook from their recipe book. Answer in plain text, without Markdown.",
},
AIContextProviders = [skills],
},
clientFactory: chatClient => chatClient.AsBuilder()
.Use(getResponseFunc: ShowRequestAsync, getStreamingResponseFunc: null)
.Build());

Then add the middleware after the line that prints the answer:

Program.cs (the middleware)
// IChatClient middleware: shows what each request to the model carries.
async Task<ChatResponse> ShowRequestAsync(
IEnumerable<ChatMessage> messages,
ChatOptions? options,
IChatClient innerClient,
CancellationToken cancellationToken)
{
requestNumber++;
string tools = string.Join(", ", options?.Tools?.Select(tool => tool.Name) ?? []);
Console.WriteLine($"[request {requestNumber}] {messages.Count()} message(s), tools: {tools}");
if (requestNumber == 1)
{
Console.WriteLine("[request 1] instructions:");
Console.WriteLine(options?.Instructions);
}

return await innerClient.GetResponseAsync(messages, options, cancellationToken);
}
  • clientFactory wraps the chat client the agent uses, so every request to the model goes through ShowRequestAsync.
  • ShowRequestAsync prints the request's number, how many messages it carries and the names of its tools, and on the first request, the instructions. Then it sends the request on with innerClient.GetResponseAsync.
  • requestNumber is declared before the agent. My first version declared it just above ShowRequestAsync, after the agent, and the build failed:
Output (my first version)
/Users/you/source/RecipeHelper/Program.cs(30,31): error CS0165: Use of unassigned local variable 'requestNumber'

The build failed. Fix the build errors and run again.

Line 30 was the one that hands ShowRequestAsync to Use, which turns it into a delegate, and the C# specification's rule is that Captured variables are definitely assigned for the body if they are definitely assigned before the conversion. requestNumber wasn't assigned yet. Fixed: "error CS0165: Use of unassigned local variable" When a C# Local Function Becomes a Delegate explains it in full.

With the counter first, run it again:

Output
[request 1] 1 message(s), tools: load_skill, read_skill_resource, run_skill_script
[request 1] instructions:
You help a family cook from their recipe book. Answer in plain text, without Markdown.
You have access to skills containing domain-specific knowledge and capabilities.
Each skill provides specialized instructions, reference documents, and assets for specific tasks.

<available_skills>
<skill>
<name>recipe-book</name>
<description>The family recipe book. Use when someone asks which ingredients a recipe needs, how much of each, or how to make it.</description>
</skill>
</available_skills>

When a task aligns with a skill's domain, follow these steps in exact order:
- Use `load_skill` to retrieve the skill's instructions.
- Follow the provided guidance.
- Use `read_skill_resource` to read any referenced resources, using the name exactly as listed
(e.g. `"style-guide"` not `"style-guide.md"`, `"references/FAQ.md"` not `"FAQ.md"`).
- Use `run_skill_script` to run referenced scripts, using the name exactly as listed.
Only load what is needed, when it is needed.
[request 2] 1 message(s), tools: load_skill, read_skill_resource, run_skill_script
[request 3] 1 message(s), tools: load_skill, read_skill_resource, run_skill_script
Tool call: load_skill {"skillName":"recipe-book"}
Tool call: read_skill_resource {"skillName":"recipe-book","resourceName":"references/recipes.md"}
Answer: To make pancakes (serves 4), you need:

200 g plain flour
300 ml milk
2 eggs
25 g sugar
1 pinch of salt

Whisk everything into a smooth batter and let it rest for 10 minutes. Fry a ladleful at a time in a hot, buttered pan, about 1 minute on each side.
  • The [request …] lines are printed by the middleware while the run is going. The Tool call lines come from PrintCalls, after the run has ended, so they appear last.
  • The instructions are the agent's own line, then the provider's: a short prompt, with each skill's name and description inside <available_skills>. That's the Advertise stage. The body of SKILL.md isn't there: the model gets it only when it calls load_skill, the Load stage.
  • Three requests for two tool calls. The model asked for one tool at a time: for load_skill in its answer to request 1, for read_skill_resource in its answer to request 2. Each result went back to it in the next request, and its answer to request 3 was the final answer.
  • Every request offers three tools, run_skill_script too, although no skill has a script yet. Microsoft's guide says run_skill_script is advertised only when at least one skill has scripts, but in Agent Framework 1.28.0 for C#, the provider's BuildTools method always returns all three (the source of AgentSkillsProvider at the dotnet-1.28.0 tag, unchanged on main at the time of writing). The model didn't call it.

Step 7: Add a Skill in Code, with a Script​

A skill doesn't have to be a folder. AgentInlineSkill defines one in C#, and AddScript gives it a script: a C# function the model can ask to run. Add using System.Text.Json; to the usings, and this below them:

Program.cs (the shopping list skill)
// 1. The family's shopping list, which the shopping-list skill's script adds to.
List<string> shoppingList = [];

// 2. A skill defined in code, with a script that adds items to the list.
AgentInlineSkill shoppingListSkill = new AgentInlineSkill(
name: "shopping-list",
description: "The family's shopping list. Use when someone asks to put ingredients or other things on their shopping list.",
instructions: """
Use this skill to put things on the family's shopping list.
1. Work out each item and how much is needed, such as "300 ml milk".
2. Run the add-items script once, with all the items.
3. Say which items you added.
""")
.AddScript("add-items", (string[] items) =>
{
shoppingList.AddRange(items);
return $"Added {items.Length} items. The list has {shoppingList.Count} items.";
}, description: "Adds items to the shopping list.");
  • shoppingList is the family's shopping list, which the script adds to.
  • name, description and instructions are the three parts of a SKILL.md, in code. The model sees the name and the description, and gets the instructions from load_skill, like the recipe book's body.
  • AddScript("add-items", ...) adds a script named add-items. Scripts defined in code run inside your app, as plain calls of the function, and Microsoft's guide adds: The delegate's typed parameters are automatically converted into a JSON Schema that the agent uses to pass arguments. Here, string[] items becomes a list of strings that the model fills in.
  • The script adds the items to the list and returns a sentence, which goes back to the model as the script's result.

Step 8: Put Both Skills in One Provider​

The recipe book comes from a folder and the shopping list from code, and one provider has to offer both. Microsoft's guide recommends AgentSkillsProviderBuilder for mixed skill types, so my first version replaced the provider with one:

Program.cs (my first version)
// 3. One provider for both: the skills in the skills folder and the one defined in code.
// Loading a skill and reading its files only read text you wrote, so they run without asking.
// Running a script still needs a person's approval.
AgentSkillsProvider skills = new AgentSkillsProviderBuilder()
.UseFileSkill(Path.Combine(AppContext.BaseDirectory, "skills"))
.UseSkill(shoppingListSkill)
.UseOptions(options =>
{
options.DisableLoadSkillApproval = true;
options.DisableReadSkillResourceApproval = true;
})
.Build();

It stopped before the agent was even created:

Output
Unhandled exception. System.InvalidOperationException: File-based skill sources require a script runner. Call UseFileScriptRunner or pass a runner to UseFileSkill/UseFileSkills.
at Microsoft.Agents.AI.AgentSkillsProviderBuilder.<>c__DisplayClass8_0.<UseFileSkills>b__0(AgentFileSkillScriptRunner builderScriptRunner, ILoggerFactory loggerFactory)
at Microsoft.Agents.AI.AgentSkillsProviderBuilder.Build()
at Program.<Main>$(String[] args) in /Users/you/source/RecipeHelper/Program.cs:line 29
at Program.<Main>(String[] args)

The builder asks for a script runner, a function that runs script files, for every folder of skills it gets, whether or not the folder has any scripts. The recipe book has none, and the file source itself doesn't need a runner without them: the API documentation of its scriptRunner parameter says Optional runner for file-based scripts. Required only when skills contain scripts. So the provider is now built from sources, the way Microsoft's guide does it under "Composing sources directly". Fixed: "File-based skill sources require a script runner" in Microsoft Agent Framework walks through the error.

Replace the builder with:

Program.cs (the provider)
// 3. One provider for both: the skills in the skills folder and the one defined in code.
// The folder's skills have no scripts, so their source needs no script runner.
AgentSkillsSource folderSkills = new AgentFileSkillsSource([Path.Combine(AppContext.BaseDirectory, "skills")]);
AgentSkillsSource codeSkills = new AgentInMemorySkillsSource([shoppingListSkill]);
AgentSkillsSource allSkills = new CachingAgentSkillsSource(
new DeduplicatingAgentSkillsSource(
new AggregatingAgentSkillsSource([folderSkills, codeSkills])));

// Loading a skill and reading its files only read text you wrote, so they run without asking.
// Running a script still needs a person's approval.
AgentSkillsProvider skills = new(
allSkills,
new AgentSkillsProviderOptions
{
DisableLoadSkillApproval = true,
DisableReadSkillResourceApproval = true,
},
ownsSource: true);
  • AgentFileSkillsSource finds the skills in the folder, here without a script runner.
  • AgentInMemorySkillsSource holds the skill defined in code.
  • AggregatingAgentSkillsSource puts the two together, and changes nothing in them: Microsoft's guide says it returns the skills in registration order with no deduplication or filtering applied.
  • DeduplicatingAgentSkillsSource keeps only the first skill of each name, so two skills can't share one.
  • CachingAgentSkillsSource fetches the skills once, and reuses the list on later runs.
  • new AgentSkillsProvider(allSkills, ...) creates the provider from the finished source, with the same options as before. This constructor adds nothing to the pipeline. Its API documentation: Unlike other constructors, this one does not apply automatic deduplication, which is why the pipeline does it. ownsSource: true hands the sources to the provider, which disposes them when it's disposed.

Step 9: Ask, and Approve the Script​

Replace the lines from AgentSession session to the one that prints the answer with the new question and the approval loop from Tool Approval, so that a person answers every script run:

Program.cs (the question and the approvals)
AgentSession session = await agent.CreateSessionAsync();
AgentResponse response = await agent.RunAsync("I'm making pancakes for 6 people. Put what I need on my shopping list.", session);
PrintCalls(response);

// 5. A person answers every script run before it happens.
List<ToolApprovalRequestContent> requests = ApprovalRequests(response);
while (requests.Count > 0)
{
List<AIContent> answers = [];
foreach (ToolApprovalRequestContent request in requests)
{
FunctionCallContent call = (FunctionCallContent)request.ToolCall;
Console.Write($"Run {call.Name} {JsonSerializer.Serialize(call.Arguments)}? (y/n) ");
bool approved = Console.ReadLine()?.Trim().Equals("y", StringComparison.OrdinalIgnoreCase) == true;
answers.Add(request.CreateResponse(approved));
}

response = await agent.RunAsync(new ChatMessage(ChatRole.User, answers), session);
PrintCalls(response);
requests = ApprovalRequests(response);
}

Console.WriteLine($"Answer: {response.Text}");
Console.WriteLine($"Shopping list: {string.Join(", ", shoppingList)}");

At the end of the file, add the helper that finds the approval requests:

Program.cs (the end)
// The approval requests in a response.
static List<ToolApprovalRequestContent> ApprovalRequests(AgentResponse response) =>
response.Messages.SelectMany(message => message.Contents).OfType<ToolApprovalRequestContent>().ToList();
  • The question needs both skills: the recipe, scaled for 6 people, and the shopping list's script.
  • ApprovalRequests finds the ToolApprovalRequestContent items in a response. While there are any, the loop shows each call with its arguments, and asks.
  • request.CreateResponse(approved) answers a request, and all the answers go back to the same session in one message, as in Tool Approval.
  • The last line prints the app's own list, so the output shows what the script really did, apart from what the model says.

With using System.Text.Json; at the top, PrintCalls can call JsonSerializer.Serialize without its namespace. The complete file, with its comments numbered in order:

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

// 1. The family's shopping list, which the shopping-list skill's script adds to.
List<string> shoppingList = [];

// 2. A skill defined in code, with a script that adds items to the list.
AgentInlineSkill shoppingListSkill = new AgentInlineSkill(
name: "shopping-list",
description: "The family's shopping list. Use when someone asks to put ingredients or other things on their shopping list.",
instructions: """
Use this skill to put things on the family's shopping list.
1. Work out each item and how much is needed, such as "300 ml milk".
2. Run the add-items script once, with all the items.
3. Say which items you added.
""")
.AddScript("add-items", (string[] items) =>
{
shoppingList.AddRange(items);
return $"Added {items.Length} items. The list has {shoppingList.Count} items.";
}, description: "Adds items to the shopping list.");

// 3. One provider for both: the skills in the skills folder and the one defined in code.
// The folder's skills have no scripts, so their source needs no script runner.
AgentSkillsSource folderSkills = new AgentFileSkillsSource([Path.Combine(AppContext.BaseDirectory, "skills")]);
AgentSkillsSource codeSkills = new AgentInMemorySkillsSource([shoppingListSkill]);
AgentSkillsSource allSkills = new CachingAgentSkillsSource(
new DeduplicatingAgentSkillsSource(
new AggregatingAgentSkillsSource([folderSkills, codeSkills])));

// Loading a skill and reading its files only read text you wrote, so they run without asking.
// Running a script still needs a person's approval.
AgentSkillsProvider skills = new(
allSkills,
new AgentSkillsProviderOptions
{
DisableLoadSkillApproval = true,
DisableReadSkillResourceApproval = true,
},
ownsSource: true);

// 4. Counts the requests the agent sends to the model. It's declared before the agent,
// because the agent's middleware uses it.
int requestNumber = 0;

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 = "RecipeHelper",
ChatOptions = new ChatOptions
{
ModelId = "gpt-5.6-luna",
Instructions = "You help a family cook from their recipe book. Answer in plain text, without Markdown.",
},
AIContextProviders = [skills],
},
clientFactory: chatClient => chatClient.AsBuilder()
.Use(getResponseFunc: ShowRequestAsync, getStreamingResponseFunc: null)
.Build());

AgentSession session = await agent.CreateSessionAsync();
AgentResponse response = await agent.RunAsync("I'm making pancakes for 6 people. Put what I need on my shopping list.", session);
PrintCalls(response);

// 5. A person answers every script run before it happens.
List<ToolApprovalRequestContent> requests = ApprovalRequests(response);
while (requests.Count > 0)
{
List<AIContent> answers = [];
foreach (ToolApprovalRequestContent request in requests)
{
FunctionCallContent call = (FunctionCallContent)request.ToolCall;
Console.Write($"Run {call.Name} {JsonSerializer.Serialize(call.Arguments)}? (y/n) ");
bool approved = Console.ReadLine()?.Trim().Equals("y", StringComparison.OrdinalIgnoreCase) == true;
answers.Add(request.CreateResponse(approved));
}

response = await agent.RunAsync(new ChatMessage(ChatRole.User, answers), session);
PrintCalls(response);
requests = ApprovalRequests(response);
}

Console.WriteLine($"Answer: {response.Text}");
Console.WriteLine($"Shopping list: {string.Join(", ", shoppingList)}");

// IChatClient middleware: shows what each request to the model carries.
async Task<ChatResponse> ShowRequestAsync(
IEnumerable<ChatMessage> messages,
ChatOptions? options,
IChatClient innerClient,
CancellationToken cancellationToken)
{
requestNumber++;
string tools = string.Join(", ", options?.Tools?.Select(tool => tool.Name) ?? []);
Console.WriteLine($"[request {requestNumber}] {messages.Count()} message(s), tools: {tools}");
if (requestNumber == 1)
{
Console.WriteLine("[request 1] instructions:");
Console.WriteLine(options?.Instructions);
}

return await innerClient.GetResponseAsync(messages, options, cancellationToken);
}

// Prints the tool calls and approval requests in a response.
static void PrintCalls(AgentResponse response)
{
foreach (AIContent content in response.Messages.SelectMany(message => message.Contents))
{
switch (content)
{
case ToolApprovalRequestContent request:
Console.WriteLine($" Approval needed: {((FunctionCallContent)request.ToolCall).Name}");
break;
case FunctionCallContent call:
Console.WriteLine($" Tool call: {call.Name} {JsonSerializer.Serialize(call.Arguments)}");
break;
}
}
}

// The approval requests in a response.
static List<ToolApprovalRequestContent> ApprovalRequests(AgentResponse response) =>
response.Messages.SelectMany(message => message.Contents).OfType<ToolApprovalRequestContent>().ToList();

Step 10: Run It​

Terminal
dotnet run

When the app asks, read the items and type y:

Output
[request 1] 1 message(s), tools: load_skill, read_skill_resource, run_skill_script
[request 1] instructions:
You help a family cook from their recipe book. Answer in plain text, without Markdown.
You have access to skills containing domain-specific knowledge and capabilities.
Each skill provides specialized instructions, reference documents, and assets for specific tasks.

<available_skills>
<skill>
<name>recipe-book</name>
<description>The family recipe book. Use when someone asks which ingredients a recipe needs, how much of each, or how to make it.</description>
</skill>
<skill>
<name>shopping-list</name>
<description>The family&apos;s shopping list. Use when someone asks to put ingredients or other things on their shopping list.</description>
</skill>
</available_skills>

When a task aligns with a skill's domain, follow these steps in exact order:
- Use `load_skill` to retrieve the skill's instructions.
- Follow the provided guidance.
- Use `read_skill_resource` to read any referenced resources, using the name exactly as listed
(e.g. `"style-guide"` not `"style-guide.md"`, `"references/FAQ.md"` not `"FAQ.md"`).
- Use `run_skill_script` to run referenced scripts, using the name exactly as listed.
Only load what is needed, when it is needed.
[request 2] 1 message(s), tools: load_skill, read_skill_resource, run_skill_script
[request 3] 1 message(s), tools: load_skill, read_skill_resource, run_skill_script
[request 4] 1 message(s), tools: load_skill, read_skill_resource, run_skill_script
Tool call: load_skill {"skillName":"recipe-book"}
Tool call: read_skill_resource {"skillName":"recipe-book","resourceName":"references/recipes.md"}
Tool call: load_skill {"skillName":"shopping-list"}
Approval needed: run_skill_script
Run run_skill_script {"skillName":"shopping-list","scriptName":"add-items","arguments":{"items":["300 g plain flour","450 ml milk","3 eggs","40 g sugar","1.5 pinches of salt","butter for frying"]}}? (y/n) y
[request 5] 1 message(s), tools: load_skill, read_skill_resource, run_skill_script
Tool call: run_skill_script {"skillName":"shopping-list","scriptName":"add-items","arguments":{"items":["300 g plain flour","450 ml milk","3 eggs","40 g sugar","1.5 pinches of salt","butter for frying"]}}
Answer: Added to your shopping list:
300 g plain flour
450 ml milk
3 eggs
40 g sugar
1.5 pinches of salt
Butter for frying
Shopping list: 300 g plain flour, 450 ml milk, 3 eggs, 40 g sugar, 1.5 pinches of salt, butter for frying

A macOS-style terminal window titled Terminal — RecipeHelper showing dotnet run: the first request's instructions advertise two skills, recipe-book and shopping-list, each with its description; four requests each offer load_skill, read_skill_resource and run_skill_script; the tool calls load the recipe book, read references/recipes.md and load the shopping list skill; an approval request for run_skill_script shows the add-items script with six items and is answered y; a fifth request runs the script; the answer lists the items for six people, and the app's own shopping list line shows the same six items

Read it from the top:

  • Both skills are advertised, in name order, each with its description. The shopping list's apostrophe arrives as &apos;, because the provider escapes names and descriptions as XML text.
  • Four requests, one tool each. The model loaded the recipe book, read the recipes, loaded the shopping list skill, and then asked to run add-items. That call needs approval, so the run stopped with Approval needed: run_skill_script.
  • The prompt showed the call with its arguments, so the person approves these six items, not the script in general. After y, the agent ran the script and sent its result to the model in request 5, and the model wrote the answer.
  • The scaling follows the book. The recipe serves 4, so for 6 the model multiplied by 1.5: 300 g of flour, 450 ml of milk and 3 eggs. The sugar, 25 g times 1.5, is 37.5 g, and the model wrote 40 g, rounded to the nearest 5 as the rule asks. The salt stayed at 1.5 pinches, because the rule rounds only grams and millilitres. It also added "butter for frying", which isn't in the ingredient list but comes from the method's "hot, buttered pan". If you'd rather it kept to the ingredient list, that's one more line in the skill's body.

Running the script is the only step here that changes something, with arguments the model wrote. That's why run_skill_script still asks. The skills themselves deserve the same care: Microsoft's guide says Agent Skills should be treated like any third-party code you bring into your project, and the API documentation warns that a skill's content is injected into the agent's context as-is, without validation or sanitization. Read a skill's SKILL.md, resources and scripts before you add it, and use skills only from people you trust.

What You Can Do Now​

  • Explain how a skill is advertised by its name and description, and loaded only when a question needs it.
  • Write a SKILL.md with a reference file, and copy the skills folder to the build output.
  • Attach skills to an agent with AgentSkillsProvider, and choose which skill tools need a person's approval.
  • Define a skill in C# with a script, and put folder skills and code skills in one provider with sources.

Common Mistakes​

MistakeWhat happensDo this instead
Leaving the skills folder only in the project folderThe app looks for it in the build output, where AppContext.BaseDirectory pointsCopy it with the None Update item from Step 3
Keeping the default approvals without an approval loopThe run ends with an approval request and an empty answer, as in Step 4Turn approval off for the reading tools, or answer the requests as in Step 9
Declaring a variable that the middleware uses after the agenterror CS0165: Use of unassigned local variable (Fixed)Declare it before the line that hands the function to Use
Giving AgentSkillsProviderBuilder a folder of skills and no script runnerFile-based skill sources require a script runner, at Build() (Fixed)Compose the sources yourself, as in Step 8
A vague descriptionThe model decides from the name and the description alone whether to load the skillSay what the skill does and when to use it, as the format asks
Adding skills you haven't readTheir content reaches the model as written, and their scripts can runRead every file of a skill first, and keep approval on scripts

Frequently Asked Questions​

When should I use a skill, and when a workflow?​

Microsoft's guide compares the two, and its rule of thumb is short: a skill when you want the AI to work out how to do a task, a workflow when you need to guarantee which steps run, and in what order. A skill runs within one agent run, and the model decides how to follow it. A workflow runs the steps you define, and can resume from its last successful step after a failure.

How much can a skill hold?​

The name and the description go out on every run, at about 100 tokens a skill, so keep the description to what the model needs to choose. For the body that load_skill returns, Microsoft's guide recommends under 5,000 tokens and a SKILL.md under 500 lines, with the details in resource files that the model reads only when it needs them.

Can a skill in a folder have scripts?​

Yes. By default, files with extensions such as .py, .sh or .cs in a skill's folder are its scripts, and running them needs a script runner. Microsoft's guide: To run scripts from file-based skills, pass an AgentFileSkillScriptRunner delegate as the second AgentFileSkillsSource constructor argument. Scripts defined in code, like add-items, need no runner: they're ordinary C# functions in your app.

What if the model calls a reading tool and a script at the same time?​

In this tutorial's runs, the model asked for one tool per request. Microsoft's guide notes that when some tools need approval and others don't, the model may call both types simultaneously, and that setting EnableNonApprovalRequiredFunctionBypassing on ChatClientAgentOptions lets the free tools run at once, while the person is asked only about the others.

Is there another way to skip approval for the reading tools?​

Yes: leave the provider's options alone, and add tool approval middleware with an automatic rule. Microsoft's guide uses UseToolApproval with AgentSkillsProvider.ReadOnlyToolsAutoApprovalRule, which approves load_skill and read_skill_resource and still asks about run_skill_script.

Conclusion​

Agent Skills keep an agent's instructions short and its knowledge deep. A skill is a SKILL.md with a name, a description and instructions, plus files and scripts when it needs them. AgentSkillsProvider advertises every skill's name and description, and the model loads a skill, reads its files and runs its scripts with three tools, only when a question needs them. Each tool asks a person first unless you turn that off, and scripts, the tools that act, are the ones to keep asking about.

Next: Background Responses — let the model write a long answer in the background, and collect it later, even from another process.

Additional Resources​