Cover of Building AI Agents with C# and .NET 10 by Rachid Dahir
Microsoft Agent Framework

Building AI Agents with C# and .NET 10

A Developer’s First Guide to the Microsoft Agent Framework

600 pages 19 chapters 5 appendices 120 runnable projects

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.

Get it on Leanpub
From $29.99 · suggested $39.99

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

01

Build your first ChatClientAgent, give it a persona, and expose it over HTTP with Minimal API.

02

Solve the amnesia problem with sessions, history providers, and context providers.

03

Get typed C# records back from the model instead of strings you have to regex.

04

Give agents tools and function calling, with human-in-the-loop approval for the dangerous ones.

05

Build and consume Model Context Protocol (MCP) servers in C#.

06

Ground answers in your own documents with retrieval-augmented generation, and send images, audio and video to multimodal agents.

07

Coordinate specialists with multi-agent orchestration and typed workflow graphs.

08

Host with ASP.NET Core and .NET Aspire, instrument with OpenTelemetry, and layer guardrails against the OWASP LLM Top 10.

Built on

.NET 10 LTS C# 14 Microsoft Agent Framework 1.16 Microsoft.Extensions.AI ASP.NET Core Minimal API .NET Aspire OpenTelemetry Model Context Protocol Azure OpenAI Ollama

Table of contents

Five parts, nineteen chapters, five appendices.

Part I — Foundations

  1. The AI Revolution in .NET
  2. C# Essentials for AI Development
  3. How LLMs Work: A Developer’s Mental Model
  4. Setting Up Your Dev Environment

Part II — Your First Agents

  1. Hello, Agent!
  2. Conversations and Memory
  3. Structured Output and Typed Responses

Part III — Giving Agents Superpowers

  1. Tools and Function Calling
  2. The Model Context Protocol
  3. Introduction to RAG
  4. Multimodal Agents

Part IV — Multi-Agent Collaboration

  1. Multi-Agent Systems
  2. Introduction to Workflows

Part V — Going to Production

  1. Hosting and Deployment
  2. Observability and Debugging
  3. Safety and Guardrails
  4. Agent Skills
  5. Evaluation
  6. 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
View on GitHub

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.

See the bundle

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.99

Not ready to buy? Start with the free book.