Over the last few days, I’ve been exploring Microsoft’s new Agent Framework, a preview library that brings structured, context-aware AI capabilities directly into .NET applications.
To get familiar with its architecture and basic features, I’ve built five small “Getting Started” console samples in .NET 9, all powered by Azure OpenAI and defined via a simple .env configuration.
Each example builds upon the previous one — from a simple agent call to multi-turn conversations, function tools, approvals, and structured object outputs.
01 – SimpleAgent
The most basic example: connecting to Azure OpenAI using AzureKeyCredential, creating a simple AIAgent, and asking a question.
AIAgent agent = new AzureOpenAIClient(
new Uri(endpoint),
new AzureKeyCredential(key))
.GetChatClient(deployment)
.CreateAIAgent(instructions: "Tell me which language is most popular for development.", name: "Developer Assistant");
Console.WriteLine(await agent.RunAsync("Tell me which language is most popular for development."));
02 – ThreadAgent
Introduces multi-turn conversation threads that preserve context between user messages.
AgentThread thread = agent.GetNewThread();
Console.WriteLine(await agent.RunAsync("Tell me which language is most popular for development.", thread));
Console.WriteLine(await agent.RunAsync("Now tell me which of them to use if I want to build a web application in Microsoft ecosystem.", thread));
03 – FunctionTool
Shows how to extend the agent with function tools (custom methods) that can be invoked automatically by the AI when relevant.
[Description("Talk about dogs and provide interesting facts, tips, or stories.")]
static string TalkAboutDogs(string topic) =>
topic.ToLower() switch
{
"labrador" => "Labradors are friendly and full of energy.",
"poodle" => "Poodles are smart and hypoallergenic.",
_ => $"Dogs are amazing companions! 🐶"
};
var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(key))
.GetChatClient(deployment)
.CreateAIAgent("You are a funny assistant who loves dogs.",
tools: [AIFunctionFactory.Create(TalkAboutDogs)]);
04 – FunctionToolWithApprovals
Adds user approval flow before the AI can execute a tool (e.g., to confirm a sensitive action).
.CreateAIAgent(instructions: "You are a funny assistant who loves dogs.",
tools: [new ApprovalRequiredAIFunction(AIFunctionFactory.Create(TalkAboutDogs))]);
05 – ObjectOutput
Demonstrates how to deserialize structured JSON responses directly into typed .NET objects — a key feature for integrating AI into real apps.
AgentRunResponse<DogInfo> response = await agent.RunAsync<DogInfo>("Please provide information about a Husky.");
Console.WriteLine($"Name: {response.Result.Name}");
Console.WriteLine($"Eye Color: {response.Result.EyeColor}");
Console.WriteLine($"Fur Color: {response.Result.FurColor}");
Project setup
Each sample shares the same project structure and NuGet packages:
<PackageReference Include="Azure.AI.OpenAI" Version="2.5.0-beta.1" />
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.251028.1" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.1-preview.1.25521.4" />
<PackageReference Include="DotNetEnv" Version="3.1.1" />
Environment configuration in .env:
AZURE_OPENAI_ENDPOINT=https://xxxxxxxxxxxxxxx.openai.azure.com/
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o
AZURE_OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxx
This is just the beginning.
In the coming weeks, I’ll be sharing more practical examples, best practices, and articles around AI in the .NET ecosystem — especially focusing on the Agent Framework, Semantic Kernel, and integration with Azure OpenAI and local AI models.
Stay tuned for the next part of the series, where I’ll dive deeper into adding memory, multimodal capabilities, and integration with external systems to your agents.
That’s all folks!
Cheers!
Gašper Rupnik
{End.}
