Building AI Agents with C# and .NET 10
What's in this book
The Microsoft Agent Framework (MAF) is Microsoft's unified, production-minded SDK for building AI agents in .NET — the consolidation of Semantic Kernel and AutoGen into one stack. This is the developer's first guide to it, built entirely on the stable 1.22.0 release and .NET 10 / C# 14.
Across twenty chapters in five parts you go from your first call to an LLM, through tools and function calling, the Model Context Protocol, retrieval-augmented generation, and multimodal agents (vision), into multi-agent orchestration and workflows, all the way to hosting, observability, safety guardrails, agent skills, and evaluation. Every concept is anchored in a runnable companion project in this repository, and every code listing targets MAF 1.22.0 — no preview ceremony, no alpha-only attributes, no shifting namespaces.
By the final chapter you will have built the Contoso FAQ agent — a small but real production system — and developed the intuition to design, build, and ship your own.
Who this book is for
This book is written for .NET developers who want to build AI-powered agent systems without abandoning the tools and patterns they already know. You should be comfortable with C# fundamentals, have written at least one ASP.NET Core service or console application, and have a working relationship with dependency injection. If you can write a class, use LINQ, and navigate your IDE without a tutorial, you're ready.
No prior machine-learning background is assumed. The book explains what you need to know about how LLMs behave, from a developer's point of view, as you go.
Table of Contents
Plus five appendices — a themed package reference, a Semantic Kernel and AutoGen migration guide, a troubleshooting catalogue, a glossary, and worked solutions to every exercise — followed by a keyword index.
Companion code
125 runnable projects across 127 in total: 82 chapter samples under src/ and 45 worked exercise solutions under exercises/, plus two shared libraries. Each one is self-contained — you don't need to run everything to follow along, so pick the project for the chapter you're reading.
Target stack
- .NET 10 (LTS) / C# 14
- Microsoft Agent Framework 1.22.0 (the first paperback printing was verified against 1.20.0; every listing it prints builds and runs unchanged on 1.22.0)
- Microsoft.Extensions.AI 10.9.0
- Visual Studio 2026, or VS Code with the C# Dev Kit
Every package version is pinned centrally in Directory.Packages.props (Central Package Management); individual .csproj files reference packages without version numbers. The full, themed package list is Appendix A of the book.
Prerequisites
- .NET 10 SDK
- A model provider. The samples default to Ollama running locally — zero cost, no API key — using llama3.2. They also support Azure OpenAI, OpenAI, Anthropic, and Microsoft Foundry. Chapter 4 walks through each one.
- For the multimodal samples (Chapter 11), a vision-capable model —
ollama pull llavalocally, or a cloud GPT-5.6-class model.
For the zero-config local default:
ollama pull llama3.2
Clone & build
git clone https://github.com/RachidD68/building-ai-agents-with-csharp-and-dotnet-10.git
cd building-ai-agents-with-csharp-and-dotnet-10
dotnet build AgenticAI.slnx
Open AgenticAI.slnx once and every chapter's projects load together.
Run a sample
dotnet run --project src/Ch05.HelloAgent/Ch05.BasicAgent
Configuration
Provider settings live in each project's appsettings.json; secrets belong in a gitignored appsettings.local.json or in .NET User Secrets — never in source control. For example, to use Azure OpenAI:
dotnet user-secrets set "AzureOpenAI:Endpoint" "https://YOUR-RESOURCE.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:ApiKey" "YOUR-KEY"
Azure/Foundry auth uses DefaultAzureCredential (run az login once for local dev; scope the credential chain in production).
Repository layout
Exercise solutions
The exercises/ folder holds the full worked answers to every Practice Exercise in the book — 45 projects across Chapters 2–16, one folder per chapter. Each solution matches the brief printed in its chapter and reproduced in Appendix E, and each runs on its own:
dotnet run --project exercises/Ch08.Exercises/Ex01.UnitConverterTool
Try the exercise yourself first — the chapter gives you hints, and Appendix E walks through the reasoning before you reach for the code here.
Errata & feedback
Found a typo, an outdated API, a code sample that doesn't compile, or a factual mistake? Help make the next printing better:
- 📋 Open an errata report — guided form that asks for the page number, chapter, and what's wrong.
- 🔍 Browse known errata — see what's already been reported before filing a duplicate.
For general feedback, questions about the companion code, or suggestions, use the Issues tab without the errata label.
License
- The companion code in this repository is released under the MIT License — use it, fork it, build on it freely.
- The book itself is sold separately — available on Leanpub; the full copyright page is inside the book.