Building AI Agents
with C# and .NET 10
A Developer’s First Guide to the Microsoft Agent Framework
From your first agent in twenty lines of C# to a hosted, observable, guarded multi-agent system — all on the stable GA surface of Microsoft Agent Framework 1.16.
PDF. Lifetime updates. Read a free sample on Leanpub before you buy.
About this book
Between the launch of ChatGPT and the GA release of the Microsoft Agent Framework in April 2026, a new class of .NET application emerged: programs that hold a language model in one hand and a set of tools in the other, and decide for themselves how to string them together to reach a goal.
The framework is ready. The guidance mostly isn’t — it lives scattered across API docs, conference talks, and GitHub samples pinned to preview builds that broke last Tuesday. This book is the picture on the puzzle box. Nineteen chapters take you from your first LLM call in C# to a production-hosted, observability-instrumented, safety-filtered multi-agent system, all on the stable GA surface of Microsoft Agent Framework 1.16, .NET 10 LTS, and C# 14.
Along the way you build the Contoso FAQ agent, a small but real production system that grows chapter by chapter until it ships: hosted, observable, guarded, and evaluated.
What makes it different is discipline. Every listing compiles and runs, and every one is paired with its expected console output. Chapters follow an Explain–Demonstrate–Practice rhythm, and exercises come in three tiers — 18 Basic, 21 Intermediate, 14 Challenge — with worked solutions in Appendix E.
What you’ll learn
Build your first ChatClientAgent, give it a persona, and expose it over HTTP with Minimal API.
Solve the amnesia problem with sessions, history providers, and context providers.
Get typed C# records back from the model instead of strings you have to regex.
Give agents tools and function calling, with human-in-the-loop approval for the dangerous ones.
Build and consume Model Context Protocol (MCP) servers in C#.
Ground answers in your own documents with retrieval-augmented generation, and send images, audio and video to multimodal agents.
Coordinate specialists with multi-agent orchestration and typed workflow graphs.
Host with ASP.NET Core and .NET Aspire, instrument with OpenTelemetry, and layer guardrails against the OWASP LLM Top 10.
Built on
Table of contents
Five parts, nineteen chapters, five appendices.
Part I — Foundations
- The AI Revolution in .NET
- C# Essentials for AI Development
- How LLMs Work: A Developer’s Mental Model
- Setting Up Your Dev Environment
Part II — Your First Agents
- Hello, Agent!
- Conversations and Memory
- Structured Output and Typed Responses
Part III — Giving Agents Superpowers
- Tools and Function Calling
- The Model Context Protocol
- Introduction to RAG
- Multimodal Agents
Part IV — Multi-Agent Collaboration
- Multi-Agent Systems
- Introduction to Workflows
Part V — Going to Production
- Hosting and Deployment
- Observability and Debugging
- Safety and Guardrails
- Agent Skills
- Evaluation
- Your Next Steps
Appendices
- A — NuGet Package Reference
- B — Semantic Kernel to MAF Migration Map
- C — AutoGen to MAF Migration Map
- D — Glossary
- E — Exercise Solutions Reference
Inside the book
Code in the text is not pseudocode. Every listing compiles, runs, and is printed next to the console output it produces.
// Chapter 5 — a client, a persona, one call.
var chatClient = new AzureOpenAIClient(new Uri(endpoint), credential)
.GetChatClient(deploymentName)
.AsIChatClient();
AIAgent agent = new ChatClientAgent(chatClient, new ChatClientAgentOptions
{
Name = "ContosoFaq",
Instructions = "You answer questions about Contoso products. " +
"If the answer is not in the context, say you do not know."
});
AgentRunResponse reply = await agent.RunAsync(
"How long is the return window?", cancellationToken: ct);
Console.WriteLine(reply.Text);
Read the free sample on Leanpub
Companion repository
MIT-licensed. One project per listing, plus every exercise solution.
- Projects
- 120
- Exercise tiers
- 18 / 21 / 14
- Providers
- 4
- Licence
- MIT
Who this is for
- Intermediate C# developers with no AI or ML background. If you can write a class, use LINQ, and wire up dependency injection, you’re ready.
- Semantic Kernel users migrating to the Microsoft Agent Framework.
- Python and AutoGen developers moving to .NET.
- Tech leads evaluating MAF before committing a team to it.
What it is not
- A beginner’s guide to C#. Chapter 2 refreshes what AI work needs, nothing more.
- A machine-learning textbook. You will not be training models.
- Tied to preview APIs. Everything runs on the generally available surface.
Frequently asked
No. If you can write a class, use LINQ, and wire up dependency injection, you are ready. Chapter 3 gives you the mental model of how LLMs work without the mathematics.
All samples run against Azure OpenAI, OpenAI, GitHub Models, or a local Ollama model with a single configuration change. Dedicated helpers ship for Anthropic and Microsoft Foundry.
Yes. Appendix B is a Semantic Kernel to Microsoft Agent Framework migration map, and Appendix C covers AutoGen.
The book is written against Microsoft Agent Framework 1.16, the generally available release, not a preview build. The companion repository is updated when the pinned version moves.
Start here if you have never built an agent in C#. If you already have an agent and need to ground it in your own documents, start with Production-Grade RAG with C# and .NET. The two are sold together as a bundle.
Buy it with the RAG book and save 15%
Both books together for $54.99, against $64.98 apart. 1,268 pages, 44 chapters, 174 projects.
Building AI Agents with C# and .NET 10
600 pages. 19 chapters. 120 runnable projects, every one on the GA surface of Microsoft Agent Framework 1.16.
Get it on Leanpub — from $29.99Not ready to buy? Start with the free book.