Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Microsoft Agent Framework supports creating agents using models deployed with Azure AI Foundry Models via an OpenAI Responses compatible API, and therefore the OpenAI client libraries can be used to access Foundry models.
Getting Started
Add the required NuGet packages to your project.
dotnet add package Azure.Identity
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
Creating an OpenAI Responses Agent with Foundry Models
As a first step you need to create a client to connect to the OpenAI service.
Since the code is not using the default OpenAI service, the URI of the OpenAI compatible Foundry service, needs to be provided via OpenAIClientOptions.
using System;
using System.ClientModel.Primitives;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI;
var clientOptions = new OpenAIClientOptions() { Endpoint = new Uri("https://<myresource>.services.ai.azure.com/openai/v1/") };
#pragma warning disable OPENAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
OpenAIClient client = new OpenAIClient(new BearerTokenPolicy(new AzureCliCredential(), "https://ai.azure.com/.default"), clientOptions);
#pragma warning restore OPENAI001
// You can optionally authenticate with an API key
// OpenAIClient client = new OpenAIClient(new ApiKeyCredential("<your_api_key>"), clientOptions);
A client for responses can then be created using the model deployment name.
#pragma warning disable OPENAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
var responseClient = client.GetOpenAIResponseClient("gpt-4o-mini");
#pragma warning restore OPENAI001
Finally, the agent can be created using the CreateAIAgent extension method on the ResponseClient.
AIAgent agent = responseClient.CreateAIAgent(
instructions: "You are good at telling jokes.",
name: "Joker");
// Invoke the agent and output the text result.
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
Using the Agent
The agent is a standard AIAgent and supports all standard AIAgent operations.
See the Agent getting started tutorials for more information on how to run and interact with agents.
More docs coming soon.