Skip to content

AzureOpenAI

Rasmus Wulff Jensen edited this page Oct 10, 2026 · 8 revisions

NuGet README

Features

  • AgentFactory (AzureOpenAIAgentFactory)
  • AIToolsFactory integration (tools in AgentOptions.Tools)
  • EmbeddingFactory (AzureOpenAIEmbeddingFactory)
  • BatchRunner (AzureOpenAIBatchRunner)
  • DecisionFactory (AzureOpenAIDecisionFactory) for Microsoft-Decision-1
  • OpenAI-style reasoning settings and ClientType (ChatClient or ResponsesApi)

Package

dotnet add package AgentFrameworkToolkit.AzureOpenAI

Breaking change in 1.21.0

The Azure.AI.OpenAI dependency was replaced with the OpenAI NuGet package, following Microsoft's recommendation and ensuring compatibility with Microsoft Agent Framework 1.21.0.

For most scenarios, no code changes are required. However, this changes the public API for consumers using:

  • AzureOpenAIConnection.GetClient(), which now returns OpenAIClient.
  • AzureOpenAIConnection.AdditionalOpenAIClientOptions, which now configures OpenAIClientOptions.

These are the corresponding types from the unified OpenAI SDK.

Quick start

AzureOpenAIAgentFactory agentFactory = new("<endpoint>", "<apiKey>");
AzureOpenAIAgent agent = agentFactory.CreateAgent(new AgentOptions
{
    Model = "gpt-5",
    ReasoningEffort = OpenAIReasoningEffort.Low,
    Instructions = "You are a nice AI"
});

AgentRunResponse response = await agent.RunAsync("Hello World");
Console.WriteLine(response);

Note

In Azure OpenAI, Model refers to your deployment name, not the model id.

Embeddings

AzureOpenAIEmbeddingFactory embeddingFactory = new("<endpoint>", "<apiKey>");
IEmbeddingGenerator<string, Embedding<float>> generator =
    embeddingFactory.GetEmbeddingGenerator("text-embedding-3-small");
Embedding<float> embedding = await generator.GenerateAsync("Hello");

Decisions (Microsoft-Decision-1)

using AgentFrameworkToolkit.Decisions;

IDecisionFactory decisionFactory = new AzureOpenAIDecisionFactory(
    "https://<resource>.services.ai.azure.com", "<apiKey>", "<decision-deployment-name>");

bool urgent = await decisionFactory.IsTrueAsync(new ProbabilityRequest
{
    Input = "The production website is unavailable.",
    Question = "Does this need urgent attention?",
    Threshold = 0.7
});

This factory uses Microsoft's dedicated decision API and supports API keys or RBAC. It accepts AzureOpenAIConnection for advanced connection options. Image requests and SafetyIdentifier are unsupported. See DecisionFactories for shared usage and an RBAC example.

Runtime-defined questions (1.24.2+)

Supply named questions without a result class or enums:

DecisionResponse response = await decisionFactory.CreateDecisionAsync(
    new DynamicDecisionRequest
    {
        Input = "The production website is unavailable.",
        Questions =
        [
            new ScoreQuestion
            {
                Id = "impact",
                Question = "How severe is the impact?",
                Levels = ["Minor", "Degraded", "Unavailable"]
            },
            new ProbabilityQuestion
            {
                Id = "urgent",
                Question = "Does this need urgent attention?",
                Threshold = 0.7
            }
        ]
    });

ScoreAnswer impact = response.GetScore("impact");
Console.WriteLine(impact.Value);
Console.WriteLine(response.GetProbability("URGENT").IsTrue);
Console.WriteLine(response.TotalTokenCount);

IDs and answer lookup are case-insensitive. See runtime-defined questions for choices, detailed option and level probabilities, and validation rules. Microsoft-Decision-1 remains text-only, including for dynamic requests.

Connection options

  • Endpoint (required)
  • ApiKey or Credentials (TokenCredential) for RBAC
  • NetworkTimeout
  • DefaultClientType
  • AutoCorrectFoundryEndpoint (optional, defaults to true)
  • AdditionalOpenAIClientOptions

Dependency injection

builder.Services.AddAzureOpenAIAgentFactory("<endpoint>", "<apiKey>");
builder.Services.AddAzureOpenAIAgentFactory(new AzureOpenAIConnection
{
    Endpoint = "<endpoint>",
    ApiKey = "<apiKey>"
});

builder.Services.AddAzureOpenAIEmbeddingFactory("<endpoint>", "<apiKey>");
builder.Services.AddAzureOpenAIDecisionFactory("<endpoint>", "<apiKey>", "<decision-deployment-name>");

Notes

Clone this wiki locally