Add some OpenAI and Foundry extension methods (#225)

* Add some OpenAI specific extensions

* Update samples and extension methods

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add extension methods for creating agents using the Assistant API

* Add orchestration sample

* Add orchestration sample

* Sample for the Foundry alignment document

* Address code review feedback

* Rename provider samples

* Sample showing how to get an AI agent for Foundry SDK

* Add OpenAI chat completion based implementation of AIAgent

* Split OpenAI client extension methods by client type

* Remove OpenAIClient extension methods

* Rename AsRunnableAgent

* Fix XML comments

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Mark Wallace
2025-07-31 18:08:17 +00:00
committed by GitHub
co-authored by Copilot
parent 42c7a59640
commit 624709e5d1
22 changed files with 1330 additions and 160 deletions
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Extensions.Logging;
using Microsoft.Shared.Samples;
using OpenAI;
using OpenAI.Chat;
namespace Custom;
/// <summary>
/// End-to-end sample showing how to use a custom <see cref="OpenAIChatClientAgent"/>.
/// </summary>
public sealed class Custom_OpenAIChatClientAgent(ITestOutputHelper output) : AgentSample(output)
{
/// <summary>
/// This will create an instance of <see cref="MyOpenAIChatClientAgent"/> and run it.
/// </summary>
[Fact]
public async Task RunCustomChatClientAgent()
{
var chatClient = new OpenAIClient(TestConfiguration.OpenAI.ApiKey).GetChatClient(TestConfiguration.OpenAI.ChatModelId);
var agent = new MyOpenAIChatClientAgent(chatClient);
var chatMessage = new UserChatMessage("Tell me a joke about a pirate.");
var chatCompletion = await agent.RunAsync(chatMessage);
Console.WriteLine(chatCompletion.Content.Last().Text);
}
}
public class MyOpenAIChatClientAgent : OpenAIChatClientAgent
{
private const string JokerName = "Joker";
private const string JokerInstructions = "You are good at telling jokes.";
public MyOpenAIChatClientAgent(ChatClient client, ILoggerFactory? loggerFactory = null) :
base(client, instructions: JokerInstructions, name: JokerName, loggerFactory: loggerFactory)
{
}
}