Skip to content
Conduit

mcp server

building-ai-agents-with-csharp-and-dotnet-10

Building AI Agents with C# and .NET 10 — A Developer's First Guide to the Microsoft Agent Framework. Companion code: 125 runnable projects across 20 chapters, built on MAF 1.20.0, .NET 10 and C# 14.

Set up

Runs on your computer. Pick your agent and operating system.

This project does not publish an install method we can turn into a config. Follow the README instead.

README

synced Oct 26, 2026

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

#ChapterPart
1The AI Revolution in .NETI — Foundations
2C# Essentials for AI DevelopmentI
3How LLMs Work: A Developer's Mental ModelI
4Setting Up Your Dev EnvironmentI
5Hello, Agent!II — Your First Agents
6Conversations and MemoryII
7Structured Output and Typed ResponsesII
8Tools and Function CallingIII — Giving Agents Superpowers
9The Model Context ProtocolIII
10Introduction to RAGIII
11Multimodal AgentsIII
12Multi-Agent SystemsIV — Multi-Agent Collaboration
13Introduction to WorkflowsIV
14Hosting and DeploymentV — Going to Production
15Observability and DebuggingV
16Safety and GuardrailsV
17Agent SkillsV
18EvaluationV
19The Agent HarnessV
20Your Next StepsV

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 llava locally, 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

FolderChapterTopic
src/Common/—Shared configuration, DI, provider wiring, resilience
src/Ch01.*1The AI Revolution in .NET (concept + a first code glimpse)
src/Ch02.CSharpEssentials/2C# Essentials for AI Development
src/Ch03.HowLLMsWork/3How LLMs Work
src/Ch04.DevEnvironment/4Setting Up Your Dev Environment
src/Ch05.HelloAgent/5Hello, Agent!
src/Ch06.ConversationsMemory/6Conversations and Memory
src/Ch07.StructuredOutput/7Structured Output and Typed Responses
src/Ch08.ToolsFunctionCalling/8Tools and Function Calling (incl. FileAccessProvider)
src/Ch09.MCP/9The Model Context Protocol
src/Ch10.IntroRAG/10Introduction to RAG
src/Ch11.Multimodal/11Multimodal Agents — vision, image-to-typed-data
src/Ch12.MultiAgent/12Multi-Agent Systems
src/Ch13.Workflows/13Introduction to Workflows
src/Ch14.Hosting/14Hosting and Deployment
src/Ch15.Observability/15Observability and Debugging
src/Ch16.SafetyGuardrails/16Safety and Guardrails
src/Ch17.AgentSkills/17Agent Skills
src/Ch18.EvalSuite/, Ch18.FaqEval/, Ch18.EvalTests/18Evaluation
src/Ch19.AgentHarness/19The Agent Harness
src/Ch20.NextSteps/20Your Next Steps
exercises/2–16Worked exercise solutions (also indexed in Appendix E)

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:

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.

↑↓ navigate openesc close