-
Notifications
You must be signed in to change notification settings - Fork 1.4k
.NET: [Breaking] Restructure agent skills to use multi-source architecture #4871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SergeyMenshykh
merged 14 commits into
microsoft:main
from
SergeyMenshykh:agent-skills-agent-file-skill-source-1
Mar 26, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0e78d14
initial commit
SergeyMenshykh 7db9d61
address comments
SergeyMenshykh b23dabd
address comments
SergeyMenshykh eefa6da
address comments
SergeyMenshykh 2486d7d
address comments
SergeyMenshykh 500ae25
rename executor to runner to align naming with python implementation
SergeyMenshykh 6c4a296
rename runner execute method to run method
SergeyMenshykh fbaa0d1
remove poc leftovers and fix compilation issues
SergeyMenshykh 53efe89
make script runner optional
SergeyMenshykh 9d703a6
remove unnecessary pragmas
SergeyMenshykh 0d18a1b
make resources and scripts props virtual
SergeyMenshykh 5f86e15
address comments
SergeyMenshykh 9270ee2
update comment for name validation regex
SergeyMenshykh d7e5712
address comments
SergeyMenshykh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
dotnet/samples/02-agents/AgentSkills/Agent_Step01_BasicSkills/Program.cs
This file was deleted.
Oops, something went wrong.
63 changes: 0 additions & 63 deletions
63
dotnet/samples/02-agents/AgentSkills/Agent_Step01_BasicSkills/README.md
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
...s/02-agents/AgentSkills/Agent_Step01_BasicSkills/skills/expense-report/SKILL.md
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...gent_Step01_BasicSkills/skills/expense-report/assets/expense-report-template.md
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
...tSkills/Agent_Step01_BasicSkills/skills/expense-report/references/POLICY_FAQ.md
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
dotnet/samples/02-agents/AgentSkills/Agent_Step01_FileBasedSkills/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| // This sample demonstrates how to use file-based Agent Skills with a ChatClientAgent. | ||
| // Skills are discovered from SKILL.md files on disk and follow the progressive disclosure pattern: | ||
| // 1. Advertise — skill names and descriptions in the system prompt | ||
| // 2. Load — full instructions loaded on demand via load_skill tool | ||
| // 3. Read resources — reference files read via read_skill_resource tool | ||
| // 4. Run scripts — scripts executed via run_skill_script tool with a subprocess executor | ||
| // | ||
| // This sample uses a unit-converter skill that converts between miles, kilometers, pounds, and kilograms. | ||
|
|
||
| using Azure.AI.OpenAI; | ||
| using Azure.Identity; | ||
| using Microsoft.Agents.AI; | ||
| using OpenAI.Responses; | ||
|
|
||
| // --- Configuration --- | ||
| string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set."); | ||
| string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini"; | ||
|
|
||
| // --- Skills Provider --- | ||
| // Discovers skills from the 'skills' directory containing SKILL.md files. | ||
| // The script runner runs file-based scripts (e.g. Python) as local subprocesses. | ||
| var skillsProvider = new AgentSkillsProvider( | ||
| Path.Combine(AppContext.BaseDirectory, "skills"), | ||
| SubprocessScriptRunner.RunAsync); | ||
| // --- Agent Setup --- | ||
| AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential()) | ||
| .GetResponsesClient() | ||
| .AsAIAgent(new ChatClientAgentOptions | ||
| { | ||
| Name = "UnitConverterAgent", | ||
| ChatOptions = new() | ||
| { | ||
| Instructions = "You are a helpful assistant that can convert units.", | ||
| }, | ||
| AIContextProviders = [skillsProvider], | ||
| }, | ||
| model: deploymentName); | ||
|
|
||
| // --- Example: Unit conversion --- | ||
| Console.WriteLine("Converting units with file-based skills"); | ||
| Console.WriteLine(new string('-', 60)); | ||
|
|
||
| AgentResponse response = await agent.RunAsync( | ||
| "How many kilometers is a marathon (26.2 miles)? And how many pounds is 75 kilograms?"); | ||
|
|
||
| Console.WriteLine($"Agent: {response.Text}"); | ||
51 changes: 51 additions & 0 deletions
51
dotnet/samples/02-agents/AgentSkills/Agent_Step01_FileBasedSkills/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # File-Based Agent Skills Sample | ||
|
|
||
| This sample demonstrates how to use **file-based Agent Skills** with a `ChatClientAgent`. | ||
|
|
||
| ## What it demonstrates | ||
|
|
||
| - Discovering skills from `SKILL.md` files on disk via `AgentFileSkillsSource` | ||
| - The progressive disclosure pattern: advertise → load → read resources → run scripts | ||
| - Using the `AgentSkillsProvider` constructor with a skill directory path and script executor | ||
| - Running file-based scripts (Python) via a subprocess-based executor | ||
|
|
||
| ## Skills Included | ||
|
|
||
| ### unit-converter | ||
|
|
||
| Converts between common units (miles↔km, pounds↔kg) using a multiplication factor. | ||
|
|
||
| - `references/conversion-table.md` — Conversion factor table | ||
| - `scripts/convert.py` — Python script that performs the conversion | ||
|
|
||
| ## Running the Sample | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - .NET 10.0 SDK | ||
| - Azure OpenAI endpoint with a deployed model | ||
| - Python 3 installed and available as `python3` on your PATH | ||
|
|
||
| ### Setup | ||
|
|
||
| ```bash | ||
| export AZURE_OPENAI_ENDPOINT="https://your-endpoint.openai.azure.com/" | ||
| export AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o-mini" | ||
| ``` | ||
|
|
||
| ### Run | ||
|
|
||
| ```bash | ||
| dotnet run | ||
| ``` | ||
|
|
||
| ### Expected Output | ||
|
|
||
| ``` | ||
| Converting units with file-based skills | ||
| ------------------------------------------------------------ | ||
| Agent: Here are your conversions: | ||
|
|
||
| 1. **26.2 miles → 42.16 km** (a marathon distance) | ||
| 2. **75 kg → 165.35 lbs** | ||
| ``` |
11 changes: 11 additions & 0 deletions
11
...-agents/AgentSkills/Agent_Step01_FileBasedSkills/skills/unit-converter/SKILL.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| name: unit-converter | ||
| description: Convert between common units using a multiplication factor. Use when asked to convert miles, kilometers, pounds, or kilograms. | ||
| --- | ||
|
|
||
| ## Usage | ||
|
|
||
| When the user requests a unit conversion: | ||
| 1. First, review `references/conversion-table.md` to find the correct factor | ||
| 2. Run the `scripts/convert.py` script with `--value <number> --factor <factor>` (e.g. `--value 26.2 --factor 1.60934`) | ||
| 3. Present the converted value clearly with both units |
10 changes: 10 additions & 0 deletions
10
...ent_Step01_FileBasedSkills/skills/unit-converter/references/conversion-table.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Conversion Tables | ||
|
|
||
| Formula: **result = value × factor** | ||
|
|
||
| | From | To | Factor | | ||
| |-------------|-------------|----------| | ||
| | miles | kilometers | 1.60934 | | ||
| | kilometers | miles | 0.621371 | | ||
| | pounds | kilograms | 0.453592 | | ||
| | kilograms | pounds | 2.20462 | |
29 changes: 29 additions & 0 deletions
29
...-agents/AgentSkills/Agent_Step01_FileBasedSkills/skills/unit-converter/scripts/convert.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Unit conversion script | ||
| # Converts a value using a multiplication factor: result = value × factor | ||
| # | ||
| # Usage: | ||
| # python scripts/convert.py --value 26.2 --factor 1.60934 | ||
| # python scripts/convert.py --value 75 --factor 2.20462 | ||
|
|
||
| import argparse | ||
| import json | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser( | ||
| description="Convert a value using a multiplication factor.", | ||
| epilog="Examples:\n" | ||
| " python scripts/convert.py --value 26.2 --factor 1.60934\n" | ||
| " python scripts/convert.py --value 75 --factor 2.20462", | ||
| formatter_class=argparse.RawDescriptionHelpFormatter, | ||
| ) | ||
| parser.add_argument("--value", type=float, required=True, help="The numeric value to convert.") | ||
| parser.add_argument("--factor", type=float, required=True, help="The conversion factor from the table.") | ||
| args = parser.parse_args() | ||
|
|
||
| result = round(args.value * args.factor, 4) | ||
| print(json.dumps({"value": args.value, "factor": args.factor, "result": result})) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.