Overview

1 From Conventional Code to Agents

This chapter frames the shift from conventional code to agentic AI in the .NET ecosystem. It explains how generative AI and large (and small) language models are reshaping software by enabling content creation, reasoning, and conversational experiences, while also introducing practical integration hurdles such as provider fragmentation, fast-evolving APIs, rate limits, costs, and security. To address these challenges, the chapter introduces Microsoft’s Agent Framework as the organizing toolkit that lets developers connect, orchestrate, and monitor models and tools from multiple providers so they can focus on building solutions rather than managing infrastructure complexity.

The chapter positions Agent Framework as a unified, production-ready SDK that blends strengths from Semantic Kernel and AutoGen to support single- and multi-agent workflows. It highlights a rich orchestration model with patterns like sequential and concurrent flows, group chat, and handoff; an open-by-design approach via MCP for tool discovery, agent-to-agent messaging, and OpenAPI-first integrations; and layered architecture built atop Microsoft.Extensions.AI abstractions for portability across providers (e.g., OpenAI, Azure OpenAI, Ollama, Azure AI Foundry, and self-hosted models). Readers learn the core agent building blocks—Context, Tools, and Providers—and see both a minimal stateless flow and a standard iterative flow with context enrichment and tool use. Enterprise-grade features round out the platform: middleware pipelines, stateful sessions, checkpointing for long-running durability, human-in-the-loop approvals, and deep observability through OpenTelemetry, enabling robust, governable deployments.

Context is provided on how Agent Framework fits alongside other tools. Microsoft.Extensions.AI offers the foundational, provider-agnostic interfaces for prompts, embeddings, and tool calling—sufficient when simple prompt-response is all that’s needed—while Agent Framework adds higher-level agent orchestration and lifecycle management. Compared with LangChain, which excels at Python-centric chain construction, Agent Framework emphasizes C#/.NET integration, multi-agent coordination, and enterprise readiness. And whereas ML.NET focuses on classic ML and AutoML (and can run some models locally), Agent Framework specializes in orchestrating LLM-driven and deterministic workflows—complementary strengths that can be used together. Throughout, the chapter uses intuitive analogies and a simple robot-car example to demonstrate how a few lines of code can instantiate practical agents, setting the stage for building secure, observable, and scalable agentic applications in .NET.

The diagram shows the Microsoft AI stack dependencies: Microsoft.Agents.AI uses Microsoft.Extensions.AI, and Microsoft.Extensions.AI uses a various set of providers such as Microsoft.Extensions.AI.OpenAI, Microsoft.Extensions.AI.AzureAIInference, or Microsoft.Extensions.AI.Ollama.
The image compares human cognitive processes to Agent Framework's architecture, illustrating how sensory systems like eyes and ears gather data, how the brain processes this information and forms memories, and how the mind filters out irrelevant stimuli while focusing on important details, simulating planning and adaptation. (image generated using Bing Copilot)
Agent components showing context, tools and providers as core resource modules.
The diagram presents a lower-level abstraction, showing the agent's three primary resources (Context, Tools, Providers) with components for each resource category.
The Stateless Agent Architecture diagram shows how an Agent queries a Model Provider via a Chat client, and produces a Result.
The Agent Architecture diagram shows how an Agent enriches a Prompt with Context, queries a Model Provider via a Chat client, optionally calls Tools, and iterates until it produces a Result.

Summary

  • The meaning of generative AI, LLMs, and agentic AI, and how they differ from traditional machine learning.
  • Why production integration is difficult: fragmented providers, reliability, security, governance, and lifecycle complexity.
  • What Microsoft Agent Framework is and how it supports single- and multi-agent applications in .NET.
  • How Agent Framework builds on Microsoft.Extensions.AI to stay provider-agnostic across multiple model backends.
  • Where Agent Framework fits relative to LangChain and ML.NET in the broader AI and .NET ecosystem.
  • The core building blocks of agents: tools, context, providers, and their mapping to human cognitive functions.
  • Key orchestration patterns: sequential, concurrent, group chat, and handoff, represented as workflows and graphs.
  • Enterprise capabilities for agents: identity, security, content safety, governance, and inventory management.
  • Observability, durability, and human-in-the-loop support using OpenTelemetry, Azure Monitor, and Application Insights.

FAQ

What is Microsoft Agent Framework (AF)?Agent Framework is an open-source SDK for building AI agents and multi-agent workflows in .NET. It consolidates ideas from Semantic Kernel and AutoGen into a single, production-ready foundation with first-class support for model providers, graph-based workflows, observability, checkpointing, and modern multi-agent patterns. It targets .NET (C#) in this book, with the broader project also addressing Python.
Why use Agent Framework instead of wiring LLM calls by hand?Integrating generative AI at scale involves juggling multiple providers, evolving APIs, error handling, security, rate limits, and costs. AF abstracts orchestration, messaging, tools, and lifecycle management so you can focus on business solutions. It adds governance, observability, durability, and collaboration patterns to move from simple LLM calls to reliable, production-grade agents.
How does Agent Framework relate to Microsoft.Extensions.AI?AF is built on top of Microsoft.Extensions.AI, which provides unified .NET abstractions like IChatClient, IEmbeddingGenerator, and function/tool calling. By leveraging these interfaces, AF can swap model providers (OpenAI, Azure OpenAI, Ollama, Azure AI Inference, etc.) without changing business logic, while layering on agent orchestration, tools, sessions, and governance.
When should I use Microsoft.Extensions.AI alone vs. Agent Framework?If you only need prompt/response, streaming, embeddings, or basic tool calling with a single model provider, Microsoft.Extensions.AI is sufficient. Choose AF when you need multi-agent orchestration, context/memory, iterative tool use, human-in-the-loop, checkpointing for long-running work, observability, or enterprise governance.
What are the core building blocks of an AF agent?- Context: instructions, chat history, sessions, RAG, memory providers. - Tools: native functions, MCP tools, OpenAPI integrations, code interpreter, file search. - Providers: LLM/model clients (e.g., OpenAI, Azure OpenAI, Ollama, Azure AI Foundry) accessed through Microsoft.Extensions.AI.
What’s the difference between a stateless agent and the standard agent architecture?A stateless agent handles a single turn: prompt in, model response out—no memory or tools, ideal for simple tasks. The standard architecture enriches prompts with context, optionally calls tools, iterates as needed (looping model-and-tool steps), and composes a final result—suited for real-world, multi-step tasks.
Which multi-agent collaboration patterns does AF support?AF supports sequential and concurrent orchestration, group chat for brainstorming, and handoff orchestration for transferring responsibility among specialized agents—enabling flexible, goal-oriented teamwork.
How does AF enable interoperability and avoid vendor lock-in?- Model Context Protocol (MCP): dynamic discovery/use of external tools and data services. - Agent-to-Agent (A2A): structured messaging across runtimes/frameworks for safe collaboration. - OpenAPI-first: import any REST API with an OpenAPI spec as callable agent tools.
What enterprise features are built into AF?- Security and governance: Entra ID identities, least-privilege access, Azure AI Content Safety (e.g., prompt injection, PII), admin inventory/control in Microsoft 365. - Observability: native OpenTelemetry to Azure Monitor/Application Insights. - Durability: checkpointing, retries, pause/resume for long-running workflows. - Human-in-the-loop: pause for approvals on sensitive operations.
How does AF compare to LangChain and ML.NET?- Versus LangChain: LangChain excels at Python-centric chains but is lighter on enterprise integration/multi-agent coordination. AF is C#/.NET-first, with built-in multi-agent orchestration and enterprise features. - Versus ML.NET: ML.NET provides classic ML and AutoML and can run some local LLMs; AF focuses on orchestrating LLM-driven agents, tools, and workflows. They are complementary and can be used together.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Building AI Agents in .NET ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Building AI Agents in .NET ebook for free