A working agent takes about twenty lines of C#. The trouble starts once it’s attached to something that matters. A reimbursement is paid twice because a timeout made the orchestration retry an approved call. An answer cites last year’s travel policy. A user in one tenant reads another tenant’s conversation by sending its id. None of those failures lives in the model. They live in the code around it, which is the code you own.
Building AI Agents with C# and .NET 10, Second Edition is about that code. The first edition showed you how to make an agent work. This one shows you how to tell whether it keeps working: when the model is wrong, when the network drops between an approval and a payment, when the process dies while a claim waits for review. Twenty-four chapters in six parts, on Microsoft Agent Framework 1.28, .NET 10 LTS and C# 14.
You will learn how to:
• Decide whether a task needs an agent at all, and when a plain function does the job better
• Count tokens for real, pin the SDK and the packages, and keep every secret out of the repository
• Build your first ChatClientAgent together with its first test, against a fake model that needs no key
• Get typed C# records back from the model, and check that the record describes something possible
• Give an agent conversations that survive a restart, belong to one person and can be deleted
• Add tools with real brakes on the loop, and turn a model’s proposal into an action that application policy authorizes and commits once
• Serve tools over the Model Context Protocol across trust boundaries, without letting a visible tool become a callable one
• Ground answers in documents the user is allowed to see, keep a replaced policy out of today’s answer, and read receipts into typed fields
• Choose a multi-agent topology by measurement, draw a review as a typed workflow graph, and resume a claim in another process after a crash
• Host agents behind validated identities with tenant isolation, and build streaming interfaces where an approval is a decision about exact arguments
• Trace a wrong answer to the step that produced it, enforce security policy where the effect happens, and evaluate with the uncertainty printed next to the score
• Price the work, find the load at which the service stops keeping its promises, qualify a release candidate, and keep it working while models and data change
Along the way you build Contoso’s expense assistant through eight versions, from a first agent with a fake model to a release candidate with a qualification dossier that states what was tested and what wasn’t. Payments are simulated: no sample moves real money.
What makes this book different is proof. Every printed output was copied from a captured run. Most samples have a --self-test mode that runs against a scripted chat client, needs no model and no key, prints RESULT n/n and fails when a check fails, so you can check a chapter’s claims on your own machine. The samples that call a model were run against a local Ollama. The Azure OpenAI, OpenAI, Anthropic and Microsoft Foundry paths compile and pass their offline tests, but the book says plainly that they weren’t run against those services. Every chapter ends with three exercises (Basic, Intermediate, Challenge) with acceptance criteria, and the companion repository holds 177 projects: 122 chapter samples, 47 exercise solutions and the 8 Contoso versions.
Written for .NET developers who have shipped an ASP.NET Core service or a console tool and now have to put an agent into a system that already has users. No machine-learning background required. Read the first edition? The Introduction gives you a path through what changed, and Appendix E maps the old project names to the new ones. Coming from Semantic Kernel or AutoGen? Appendix C is your map, with the full migration guides in the repository.
Buying for a team? Volume licenses are available from 3 copies, with team pricing up to 40% off for larger groups: one purchase, one invoice, a copy for everyone.
The companion code lives at https://github.com/RachidD68/building-ai-agents-with-csharp-and-dotnet-10