Skip to content

Commit 0e78d14

Browse files
initial commit
1 parent 9a47620 commit 0e78d14

49 files changed

Lines changed: 4246 additions & 1206 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dotnet/agent-framework-dotnet.slnx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
</Folder>
102102
<Folder Name="/Samples/02-agents/AgentSkills/">
103103
<File Path="samples/02-agents/AgentSkills/README.md" />
104-
<Project Path="samples/02-agents/AgentSkills/Agent_Step01_BasicSkills/Agent_Step01_BasicSkills.csproj" />
104+
<Project Path="samples/02-agents/AgentSkills/Agent_Step01_FileBasedSkills/Agent_Step01_FileBasedSkills.csproj" />
105105
</Folder>
106106
<Folder Name="/Samples/02-agents/AGUI/Step05_StateManagement/">
107107
<Project Path="samples/02-agents/AGUI/Step05_StateManagement/Client/Client.csproj" />

dotnet/samples/02-agents/AgentSkills/Agent_Step01_BasicSkills/Program.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

dotnet/samples/02-agents/AgentSkills/Agent_Step01_BasicSkills/README.md

Lines changed: 0 additions & 63 deletions
This file was deleted.

dotnet/samples/02-agents/AgentSkills/Agent_Step01_BasicSkills/skills/expense-report/SKILL.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

dotnet/samples/02-agents/AgentSkills/Agent_Step01_BasicSkills/skills/expense-report/assets/expense-report-template.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

dotnet/samples/02-agents/AgentSkills/Agent_Step01_BasicSkills/skills/expense-report/references/POLICY_FAQ.md

Lines changed: 0 additions & 55 deletions
This file was deleted.

dotnet/samples/02-agents/AgentSkills/Agent_Step01_BasicSkills/Agent_Step01_BasicSkills.csproj renamed to dotnet/samples/02-agents/AgentSkills/Agent_Step01_FileBasedSkills/Agent_Step01_FileBasedSkills.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<PackageReference Include="Azure.Identity" />
1515
</ItemGroup>
1616

17+
<ItemGroup>
18+
<Compile Include="..\SubprocessScriptExecutor.cs" Link="SubprocessScriptExecutor.cs" />
19+
</ItemGroup>
20+
1721
<ItemGroup>
1822
<ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI.OpenAI\Microsoft.Agents.AI.OpenAI.csproj" />
1923
</ItemGroup>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
// This sample demonstrates how to use file-based Agent Skills with a ChatClientAgent.
4+
// Skills are discovered from SKILL.md files on disk and follow the progressive disclosure pattern:
5+
// 1. Advertise — skill names and descriptions in the system prompt
6+
// 2. Load — full instructions loaded on demand via load_skill tool
7+
// 3. Read resources — reference files read via read_skill_resource tool
8+
// 4. Run scripts — scripts executed via run_skill_script tool with a subprocess executor
9+
//
10+
// This sample uses a unit-converter skill that converts between miles, kilometers, pounds, and kilograms.
11+
12+
using Azure.AI.OpenAI;
13+
using Azure.Identity;
14+
using Microsoft.Agents.AI;
15+
using OpenAI.Responses;
16+
17+
// --- Configuration ---
18+
string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
19+
string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
20+
21+
// --- Skills Provider ---
22+
// Discovers skills from the 'skills' directory containing SKILL.md files.
23+
// The script executor runs file-based scripts (e.g. Python) as local subprocesses.
24+
var skillsProvider = new AgentSkillsProviderBuilder()
25+
.UseFileSkill(Path.Combine(AppContext.BaseDirectory, "skills"))
26+
.UseFileScriptExecutor(SubprocessScriptExecutor.ExecuteAsync)
27+
.Build();
28+
// --- Agent Setup ---
29+
AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
30+
.GetResponsesClient()
31+
.AsAIAgent(new ChatClientAgentOptions
32+
{
33+
Name = "UnitConverterAgent",
34+
ChatOptions = new()
35+
{
36+
Instructions = "You are a helpful assistant that can convert units.",
37+
},
38+
AIContextProviders = [skillsProvider],
39+
},
40+
model: deploymentName);
41+
42+
// --- Example: Unit conversion ---
43+
Console.WriteLine("Converting units with file-based skills");
44+
Console.WriteLine(new string('-', 60));
45+
46+
AgentResponse response = await agent.RunAsync(
47+
"How many kilometers is a marathon (26.2 miles)? And how many pounds is 75 kilograms?");
48+
49+
Console.WriteLine($"Agent: {response.Text}");
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# File-Based Agent Skills Sample
2+
3+
This sample demonstrates how to use **file-based Agent Skills** with a `ChatClientAgent`.
4+
5+
## What it demonstrates
6+
7+
- Discovering skills from `SKILL.md` files on disk via `AgentFileSkillsSource`
8+
- The progressive disclosure pattern: advertise → load → read resources → run scripts
9+
- Using the `AgentSkillsProviderBuilder` with `UseFileSkill` and `UseFileScriptExecutor`
10+
- Running file-based scripts (Python) via a subprocess-based executor
11+
12+
## Skills Included
13+
14+
### unit-converter
15+
16+
Converts between common units (miles↔km, pounds↔kg) using a multiplication factor.
17+
18+
- `references/conversion-table.md` — Conversion factor table
19+
- `scripts/convert.py` — Python script that performs the conversion
20+
21+
## Running the Sample
22+
23+
### Prerequisites
24+
25+
- .NET 10.0 SDK
26+
- Azure OpenAI endpoint with a deployed model
27+
- Python 3 installed and available as `python3` on your PATH
28+
29+
### Setup
30+
31+
```bash
32+
export AZURE_OPENAI_ENDPOINT="https://your-endpoint.openai.azure.com/"
33+
export AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o-mini"
34+
```
35+
36+
### Run
37+
38+
```bash
39+
dotnet run
40+
```
41+
42+
### Expected Output
43+
44+
```
45+
Converting units with file-based skills
46+
------------------------------------------------------------
47+
Agent: Here are your conversions:
48+
49+
1. **26.2 miles → 42.16 km** (a marathon distance)
50+
2. **75 kg → 165.35 lbs**
51+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
name: unit-converter
3+
description: Convert between common units using a multiplication factor. Use when asked to convert miles, kilometers, pounds, or kilograms.
4+
---
5+
6+
## Usage
7+
8+
When the user requests a unit conversion:
9+
1. First, review `references/conversion-table.md` to find the correct factor
10+
2. Run the `scripts/convert.py` script with `--value <number> --factor <factor>` (e.g. `--value 26.2 --factor 1.60934`)
11+
3. Present the converted value clearly with both units

0 commit comments

Comments
 (0)