Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dotnet/agent-framework-dotnet.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<Project Path="samples/02-agents/AgentProviders/foundry/Agent_Step24_CodeInterpreterFileDownload/Agent_Step24_CodeInterpreterFileDownload.csproj" />
<Project Path="samples/02-agents/AgentProviders/foundry/Agent_Step25_FoundryToolboxMcp/Agent_Step25_FoundryToolboxMcp.csproj" />
<Project Path="samples/02-agents/AgentProviders/foundry/Agent_Step26_FoundryToolboxMcpSkills/Agent_Step26_FoundryToolboxMcpSkills.csproj" />
<Project Path="samples/02-agents/AgentProviders/foundry/Agent_Step27_AgentSkills/Agent_Step27_AgentSkills.csproj" />
</Folder>
<Folder Name="/Samples/02-agents/Evaluation/">
<Project Path="samples/02-agents/Evaluation/Evaluation_CustomEvals/Evaluation_CustomEvals.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net10.0</TargetFrameworks>

<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.Projects" />
<PackageReference Include="Azure.Identity" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\src\Microsoft.Agents.AI.Foundry\Microsoft.Agents.AI.Foundry.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) Microsoft. All rights reserved.

// This sample demonstrates how to use Agent Skills with a FoundryAgent backed by a
// server-side versioned agent.

using Azure.AI.Projects;
using Azure.AI.Projects.Agents;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Foundry;
using Microsoft.Extensions.AI;

// --- Configuration ---
string endpoint = Environment.GetEnvironmentVariable("FOUNDRY_PROJECT_ENDPOINT")
?? throw new InvalidOperationException("FOUNDRY_PROJECT_ENDPOINT is not set.");
string deploymentName = Environment.GetEnvironmentVariable("FOUNDRY_MODEL") ?? "gpt-5.4-mini";

string agentName = $"AgentSkillsAgent-{Guid.NewGuid():N}";

// --- Define an Agent Skill ---
var supportSkill = new AgentInlineSkill(
name: "support-policy",
description: "Example support response-time policy.",
instructions: """
Use this skill when answering questions about support response times or escalation.

Read the response-times resource before answering the user.
""")
.AddResource(
"response-times",
"""
# Example Support Response Times

- Severity 1: Initial response within 15 minutes.
- Severity 2: Initial response within 1 hour.
- Severity 3: Initial response within 4 hours.

These values are illustrative, used only by this sample.
""");

var skillsProvider = new AgentSkillsProvider(supportSkill);

// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
AIProjectClient aiProjectClient = new(new Uri(endpoint), new DefaultAzureCredential());

// --- Create a server-side versioned Foundry agent ---
ProjectsAgentVersion agentVersion = await aiProjectClient.AgentAdministrationClient.CreateAgentVersionAsync(
agentName,
new ProjectsAgentVersionCreationOptions(
new DeclarativeAgentDefinition(model: deploymentName)
{
Instructions = "You are a helpful support assistant. Use available skills when relevant.",
}));

try
{
FoundryAgent foundryAgent = aiProjectClient.AsAIAgent(
agentVersion,
tools: null,
clientFactory: inner => inner
.AsBuilder()
.UseAIContextProviders(skillsProvider)
.Build());

AIAgent agent = foundryAgent
.AsBuilder()
.UseToolApproval(new ToolApprovalAgentOptions
{
AutoApprovalRules = [AgentSkillsProvider.ReadOnlyToolsAutoApprovalRule],
})
.Build();

Console.WriteLine(await agent.RunAsync(
"According to the support policy, how quickly should a Severity 1 incident receive an initial response?"));
}
finally
{
// Cleanup: deletes the agent and all its versions.
await aiProjectClient.AgentAdministrationClient.DeleteAgentAsync(agentName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Foundry Agent Skills

This sample demonstrates how to use Agent Skills with a `FoundryAgent` backed by a
server-side versioned agent in Microsoft Foundry.

## What this sample demonstrates

- Creating a server-side versioned Foundry agent
- Defining an Agent Skill in code with `AgentInlineSkill`
- Injecting `AgentSkillsProvider` through the `clientFactory`
- Auto-approving read-only Agent Skills operations
- Invoking the agent and cleaning up the server-side agent

## Prerequisites

- A Microsoft Foundry project
- An authenticated Azure identity (for example, sign in with `az login`)

Set the following environment variables:

```powershell
$env:FOUNDRY_PROJECT_ENDPOINT="https://your-foundry-service.services.ai.azure.com/api/projects/your-foundry-project"
$env:FOUNDRY_MODEL="gpt-5.4-mini"
```

## Run the sample

```powershell
dotnet run
```
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Some samples require extra tool-specific environment variables. See each sample
| [Code interpreter file download](./Agent_Step24_CodeInterpreterFileDownload/) | Download container files generated by code interpreter |
| [Foundry toolbox via MCP](./Agent_Step25_FoundryToolboxMcp/README.md) | Use a Foundry Toolbox from a non-hosted agent via its MCP endpoint |
| [Foundry toolbox MCP skills](./Agent_Step26_FoundryToolboxMcpSkills/README.md) | Use a Foundry Toolbox with MCP-based skills discovery (SEP-2640) via AIContextProviders |
| [Agent Skills](./Agent_Step27_AgentSkills/README.md) | Use Agent Skills with a server-side versioned Foundry agent |

## Running the samples

Expand Down
Loading