mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
7ba636d642
* support agent skills * make the new agent skill provider experimental * Fix file encoding: add UTF-8 BOM to .cs files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix final newline and simplify new expressions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix broken links in Agent Skills sample README Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add null check for skillPaths parameter Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Normalize references * normilize skill path * address comments regarding symlink check * address comments * fix failing test + regex improvements * small optimizations and improvments * address pr review comments * Update dotnet/src/Microsoft.Agents.AI/Skills/FileAgentSkillsProvider.cs Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> * address pr review comments * address pr review comments --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
50 lines
2.3 KiB
C#
50 lines
2.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// This sample demonstrates how to use Agent Skills with a ChatClientAgent.
|
|
// Agent Skills are modular packages of instructions and resources that extend an agent's capabilities.
|
|
// Skills follow the progressive disclosure pattern: advertise -> load -> read resources.
|
|
//
|
|
// This sample includes the expense-report skill:
|
|
// - Policy-based expense filing with references and assets
|
|
|
|
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 and makes them available to the agent
|
|
var skillsProvider = new FileAgentSkillsProvider(skillPath: Path.Combine(AppContext.BaseDirectory, "skills"));
|
|
|
|
// --- Agent Setup ---
|
|
AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
|
|
.GetResponsesClient(deploymentName)
|
|
.AsAIAgent(new ChatClientAgentOptions
|
|
{
|
|
Name = "SkillsAgent",
|
|
ChatOptions = new()
|
|
{
|
|
Instructions = "You are a helpful assistant.",
|
|
},
|
|
AIContextProviders = [skillsProvider],
|
|
});
|
|
|
|
// --- Example 1: Expense policy question (loads FAQ resource) ---
|
|
Console.WriteLine("Example 1: Checking expense policy FAQ");
|
|
Console.WriteLine("---------------------------------------");
|
|
AgentResponse response1 = await agent.RunAsync("Are tips reimbursable? I left a 25% tip on a taxi ride and want to know if that's covered.");
|
|
Console.WriteLine($"Agent: {response1.Text}\n");
|
|
|
|
// --- Example 2: Filing an expense report (multi-turn with template asset) ---
|
|
Console.WriteLine("Example 2: Filing an expense report");
|
|
Console.WriteLine("---------------------------------------");
|
|
AgentSession session = await agent.CreateSessionAsync();
|
|
AgentResponse response2 = await agent.RunAsync("I had 3 client dinners and a $1,200 flight last week. Return a draft expense report and ask about any missing details.",
|
|
session);
|
|
Console.WriteLine($"Agent: {response2.Text}\n");
|