Skip to main content

Fixed: "File-based skill sources require a script runner" in Microsoft Agent Framework

· 14 min read
Jagdish Kumawat
Founder @ Dewiride

I combined a folder of Agent Skills with a skill defined in code through Microsoft Agent Framework's AgentSkillsProviderBuilder, and the app crashed at Build() with System.InvalidOperationException: File-based skill sources require a script runner. The folder's skill had no scripts, so nothing needed a runner. Building the skill sources myself, without the builder, fixed it.

What I Was Doing​

I was building a .NET 10 console app whose Microsoft Agent Framework agent helps a family cook, with Microsoft.Agents.AI.Foundry 1.28.0-preview.261106.1 (which brings in Microsoft.Agents.AI 1.28.0) and Azure.Identity 1.21.0. The agent gets two Agent Skills. Microsoft describes Agent Skills as portable packages of instructions, scripts, and resources that give agents specialized capabilities and domain expertise; the agent loads one only when a question needs it.

  • recipe-book comes from a skills folder next to the app: a SKILL.md file with its instructions and a references/recipes.md file with the recipes. It has no scripts.
  • shopping-list is defined in code as an AgentInlineSkill, with one script, add-items: a C# function that adds items to the app's shopping list.

To give the agent both, I used AgentSkillsProviderBuilder:

Program.cs (as it was)
// 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.
// 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();
  • AddScript("add-items", ...) registers the C# function as the skill's script. The model calls it with a list of items.
  • UseFileSkill adds the skills found in the skills folder, and UseSkill adds the code-defined one.
  • UseOptions turns off the approval step for loading a skill and reading its files. Every skill tool needs a person's approval by default, so running a script still does.
  • Build() creates the AgentSkillsProvider, which the agent gets through AIContextProviders = [skills].

The app then asks the agent to put the ingredients for pancakes for 6 people on the shopping list.

What I Expected​

The provider to build, and the agent to answer with both skills available. Nothing in the app needed a script runner, the part that runs a skill's script files: the folder's skill has no scripts, and Microsoft's page on Agent Skills says about scripts defined in code: Code-defined scripts run in-process as direct delegate calls. No script runner is needed.

What I Got​

Terminal
dotnet run
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)

macOS-style terminal window titled Terminal — RecipeHelper where dotnet run ends with Unhandled exception. System.InvalidOperationException: File-based skill sources require a script runner. Call UseFileScriptRunner or pass a runner to UseFileSkill/UseFileSkills, thrown from AgentSkillsProviderBuilder.Build() called at Program.cs line 29.

The app stopped before the agent was even created, and the process ended with exit code 134. Line 29 is where the statement that builds the provider starts. The stack trace shows the exception came from inside Build(), from code that belongs to UseFileSkills.

What I Checked​

The builder's code. Agent Framework is open source. At its version 1.28.0 tag, UseFileSkills in AgentSkillsProviderBuilder.cs doesn't create the file source right away. UseFileSkill calls it, and it stores a small factory that Build() runs later. That factory takes the runner passed to UseFileSkill or UseFileSkills, or else the builder's runner from UseFileScriptRunner, and throws when there's neither:

AgentSkillsProviderBuilder.cs (Agent Framework 1.28.0)
this._sourceFactories.Add((builderScriptRunner, loggerFactory) =>
{
var resolvedRunner = scriptRunner
?? builderScriptRunner
?? throw new InvalidOperationException($"File-based skill sources require a script runner. Call {nameof(this.UseFileScriptRunner)} or pass a runner to {nameof(this.UseFileSkill)}/{nameof(this.UseFileSkills)}.");
return new AgentFileSkillsSource(skillPaths, resolvedRunner, options, loggerFactory);
});

The check never looks inside the folder: every file-based source added through the builder needs a runner, whether or not its skills have scripts. The file is the same on the main branch today.

What the file source itself needs. The documentation of the AgentFileSkillsSource constructors in Microsoft.Agents.AI 1.28.0 describes their scriptRunner parameter as Optional runner for file-based scripts. Required only when skills contain scripts. The AgentSkillsProvider constructor that takes a folder path says the same about its own: Optional delegate that runs file-based scripts. Required only when skills contain scripts. Before I added the code-defined skill, the app used that constructor, without a runner, and ran fine.

What Microsoft Learn shows. The Agent Skills page lists three ways to create a provider: the builder, composing the sources yourself, and the convenience constructors. About the second, it says: No automatic caching or deduplication is applied - you control the full pipeline. Its builder example that mixes skill types passes SubprocessScriptRunner.RunAsync to UseFileScriptRunner, a runner that starts each script as a local process, and the page says that runner is provided for demonstration purposes only.

Learn's own filtering example. The same page's Skill filtering example builds a provider with UseFileSkill and UseFilter, and no runner. I ran it as printed, as a one-file C# program with Microsoft.Agents.AI 1.28.0, and Build() threw the same exception:

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/LearnFilter/filter.cs:line 7

So that example gives this error too when you copy it as it is, and the fix below works for it the same way.

Why It Happens​

In Agent Framework 1.28.0, AgentSkillsProviderBuilder asks for a script runner for every file-based source, when Build() runs, without checking whether the folder's skills have any scripts. The file source and the provider ask for one only when the skills contain scripts. My folder had none, and the code-defined skill's script runs in-process, so only the builder's check stood in the way.

The Fix​

Build the source pipeline yourself, as the "Composing sources directly" section of Microsoft's Agent Skills page shows, and leave the runner out of the file source:

Program.cs
// 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);

macOS-style code window titled Program.cs — RecipeHelper showing an AgentFileSkillsSource for the skills folder created without a script runner, an AgentInMemorySkillsSource for the shopping-list skill, both combined by AggregatingAgentSkillsSource and wrapped in DeduplicatingAgentSkillsSource and CachingAgentSkillsSource, and the result passed to a new AgentSkillsProvider with the same approval options and ownsSource set to true.

What each line does:

  • new AgentFileSkillsSource([...]) finds the skills in the skills folder. It gets no runner, which its constructor allows.
  • new AgentInMemorySkillsSource([shoppingListSkill]) holds the skill defined in code.
  • new AggregatingAgentSkillsSource([folderSkills, codeSkills]) combines the two sources into one, keeping their order.
  • new DeduplicatingAgentSkillsSource(...) removes skills with the same name, keeping the first one. The provider constructor used below doesn't do that by itself: its documentation says Unlike other constructors, this one does not apply automatic deduplication, allowing callers to customize deduplication behavior via the source pipeline.
  • new CachingAgentSkillsSource(...) keeps the list of skills after the first time it's read, so the sources aren't read again on every request.
  • new AgentSkillsProvider(allSkills, options, ownsSource: true) creates the provider with the same approval options as before. ownsSource: true hands the pipeline to the provider, so disposing the provider disposes the sources too.

The rest of the app didn't change.

When the Folder's Skills Do Have Scripts​

Then the file source needs a runner, and so does the builder: give it one with UseFileScriptRunner, as Microsoft's builder example does, or pass one to UseFileSkill. The runner decides how a skill's script files run on your machine, so choose one you trust: for SubprocessScriptRunner, Microsoft's page lists sandboxing, resource limits, input validation and audit logs to add for production use. I didn't run this variant, so there's no output for it here.

After the Fix​

Terminal
dotnet run
Output (shortened)
[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>
…
[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

macOS-style terminal window titled Terminal — RecipeHelper where dotnet run now works: the first request's instructions list two available skills, recipe-book and shopping-list, the model loads both and reads the recipes, the app asks whether to run the add-items script and gets y, the script runs, and the answer and the shopping list show 300 g plain flour, 450 ml milk, 3 eggs, 40 g sugar, 1.5 pinches of salt and butter for frying.

The provider builds, and the instructions the agent sends with its first request list both skills: recipe-book from the folder and shopping-list from the code. The provider writes that list as XML and escapes each description, which is why the apostrophe in "family's" shows as &apos;. The … stands for the rest of the instructions, which I left out.

Then the model loads recipe-book, reads references/recipes.md and loads shopping-list. Running the add-items script needs a person's approval, so the app's approval loop asks in the terminal, and I typed y. The script ran, and the agent made one more request to the model, request 5, before it answered. The last line comes from the app's own list, so the script really added the items.

Common Mistakes​

MistakeWhat happensDo this instead
Using AgentSkillsProviderBuilder with UseFileSkill and no runner, as Learn's Skill filtering example doesBuild() throws InvalidOperationException: File-based skill sources require a script runnerCompose the sources directly when the folder's skills have no scripts
Passing your own pipeline to new AgentSkillsProvider(source, ...) without DeduplicatingAgentSkillsSourceThat constructor doesn't remove duplicate skill namesAdd DeduplicatingAgentSkillsSource to the pipeline
Copying SubprocessScriptRunner.RunAsync from the examples into production codeIt starts scripts as local processes, and Microsoft provides it for demonstration onlyChoose a runner you trust, with the safeguards Microsoft lists

Troubleshooting​

SymptomLikely causeFix
File-based skill sources require a script runner at AgentSkillsProviderBuilder.Build()A file-based source added with UseFileSkill or UseFileSkills, with no runner passed and none set with UseFileScriptRunnerCompose the sources directly, or set a runner when the skills have scripts
The stack trace points at the line where the provider is createdThe builder checks for a runner only when Build() runsCheck every UseFileSkill and UseFileSkills call in that statement

FAQ​

Do skills defined in code need a script runner?​

No. Their scripts are C# functions that run inside your app. In the run above, the add-items script ran with no runner anywhere in the app.

Why does the error come from building the provider, not from adding the folder?​

UseFileSkills, which UseFileSkill calls, only stores a factory for the file source. Build() runs every stored factory, and the runner check is inside the factory.

Does building the sources myself lose anything the builder does?​

The builder adds caching and deduplication for you. When you compose the sources yourself, you add them yourself, as the fix does with DeduplicatingAgentSkillsSource and CachingAgentSkillsSource. Microsoft's page also lists FilteringAgentSkillsSource for including or excluding skills.

Conclusion​

File-based skill sources require a script runner comes from AgentSkillsProviderBuilder.Build(): in Agent Framework 1.28.0, the builder wants a runner for every file-based source, even when its skills have no scripts, though the file source itself doesn't. Build the pipeline yourself instead: an AgentFileSkillsSource without a runner, an AgentInMemorySkillsSource, aggregation, deduplication and caching, passed to AgentSkillsProvider. When your folder's skills do have scripts, give the builder a runner you trust.

Additional Resources​

  • Agent Skills, on Microsoft Learn: skill sources, the builder, composing sources directly, script runners and tool approval.
  • AgentFileSkillsSource, on Microsoft Learn: the file-based source and its optional runner.
  • AgentSkillsProviderBuilder, on Microsoft Learn: the builder's methods, including UseFileScriptRunner.

The skills provider is an AIContextProvider: it adds the list of skills to the agent's instructions and the three skill tools to its requests.