Overview

1 From Conventional Code to Agents

This chapter introduces the shift from conventional, single-call LLM integrations to building agentic AI systems in .NET using Microsoft’s Agent Framework (AF). It motivates the change through the rapid rise of generative AI and large language models, outlining how they augment productivity, creativity, and decision-making while also creating challenges around provider diversity, evolving APIs, reliability, safety, and costs. AF is positioned as a unifying, production-ready foundation that consolidates strengths from Semantic Kernel and AutoGen, offering model provider support, graph-based orchestration, observability, checkpointing, and modern multi-agent patterns so developers can focus on outcomes rather than wiring.

The framework’s core value lies in orchestration and interoperability: a unified engine for single- and multi-agent workflows; collaboration patterns like sequential, concurrent, group chat, and handoff; and open standards such as MCP for tool discovery, agent-to-agent messaging, and OpenAPI-first tool integration. Enterprise readiness is built in through identity and access controls, content safety, centralized inventory, deep observability with OpenTelemetry, long-running durability with checkpointing, and human-in-the-loop approvals. AF is layered atop Microsoft.Extensions.AI’s provider-agnostic abstractions (e.g., IChatClient), allowing easy swaps of OpenAI, Azure OpenAI, Ollama, and others; for simple prompt-response needs, Microsoft.Extensions.AI alone may suffice. The chapter also contrasts AF with LangChain (Python-centric chaining versus AF’s .NET-first enterprise and multi-agent focus) and with ML.NET (complementary roles: orchestration vs traditional ML/AutoML).

Architecturally, AF frames agents around three primary resource groups—Context, Tools, and Providers—and explains lightweight stateless flows versus standard, iterative flows that enrich context and invoke tools until goals are satisfied. A human-body analogy maps sensing, reasoning, memory, focus, and action to providers, orchestration, state, middleware, and tool invocation, clarifying how agents plan, decide, and act. A minimal code example demonstrates creating an agent that decomposes complex robot-car commands into basic moves, illustrating how AF streamlines real tasks while enabling advanced features like middleware, stateful sessions, checkpointing, observability, and governance. The chapter sets the stage for building secure, observable, and scalable agentic applications through practical, code-first patterns in the .NET ecosystem.

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 and why should .NET developers use it?Agent Framework is an SDK for building single- and multi-agent AI applications in .NET. It consolidates ideas from Semantic Kernel and AutoGen into a production-ready foundation that connects LLMs and tools, orchestrates graph-based workflows, supports multi-agent collaboration (sequential, concurrent, group chat, handoff), and adds observability and durability. It reduces complexity across providers, APIs, governance, cost, and reliability so you can focus on solutions instead of plumbing.
How does Agent Framework relate to Microsoft.Extensions.AI?Agent Framework is built on top of Microsoft.Extensions.AI. Microsoft.Extensions.AI provides unified .NET abstractions like IChatClient, embeddings, and tool/function invocation across model providers. Agent Framework layers on agent lifecycle, orchestration, multi-agent patterns, sessions, middleware, tools integration, and enterprise controls—reusing the provider-agnostic building blocks from Microsoft.Extensions.AI.
When should I use Microsoft.Extensions.AI alone instead of Agent Framework?If you only need to send prompts and receive responses (including streaming), call tools/functions, generate embeddings, and compose middleware—without agent orchestration, multi-agent collaboration, stateful sessions, checkpointing, or governance—then Microsoft.Extensions.AI by itself is sufficient. Choose Agent Framework when you need agents, tools orchestration, workflows, durability, observability, or enterprise policies.
How does Agent Framework compare with LangChain and ML.NET?LangChain (Python) excels at building chains and experimentation in the Python ecosystem but is less focused on enterprise integration and multi-agent coordination. Agent Framework is first-class for C#/.NET with strong enterprise features and multi-agent orchestration, integrating providers like OpenAI, Azure OpenAI, Ollama, and Azure AI Foundry. ML.NET provides traditional ML and AutoML and can run some LLMs locally; Agent Framework focuses on integrating and orchestrating AI services and agents. They are complementary—pick based on language, orchestration needs, and ML vs. agent focus.
What multi-agent collaboration and orchestration patterns does Agent Framework support?It supports sequential and concurrent workflows, group chat for collaborative problem-solving, and handoff orchestration where specialized agents pass control as tasks evolve (similar to a state machine). These patterns are coordinated via graph-based workflows, enabling flexible, reliable multi-agent solutions.
What open standards enable interoperability (MCP, A2A, OpenAPI-first)?Model Context Protocol (MCP) lets agents discover and use external tools and data via a common contract, avoiding custom wiring. Agent-to-Agent (A2A) communication enables structured messaging between agents across runtimes. OpenAPI-first integration lets any REST API with an OpenAPI spec be imported as callable tools, making enterprise API integration straightforward and portable.
Which enterprise features are built in (security, observability, durability, HITL)?- Identity and access with Microsoft Entra ID for least-privilege agent identities - Azure AI Content Safety integration for prompt injection protection and PII detection - Centralized inventory and governance via Microsoft 365 Admin Center - Observability through OpenTelemetry, flowing to Azure Monitor and Application Insights - Long-running durability with retries, pause/resume, and checkpointing - Human-in-the-loop (HITL) approvals for sensitive operations
What are an agent’s primary components in Agent Framework?Agents center on three resource groups: Context (instructions, chat history, sessions, RAG, memory providers), Tools (native functions, MCP integrations, OpenAPI-imported APIs, code interpreter, file search), and Providers (OpenAI, Azure OpenAI, Ollama, Azure AI Foundry) accessed through a chat client interface. These pieces combine to ground reasoning, call capabilities, and produce reliable results.
What’s the difference between the stateless and standard agent architectures?A stateless agent handles each prompt independently—no memory or tool calls—ideal for single-turn tasks. The standard architecture enriches prompts with context (memory, history, knowledge), queries a model, optionally calls tools, updates context, and iterates until it can compose a final result. The standard flow suits practical, multi-step tasks that need grounding, external data, and control.
How do I get started with Agent Framework, and what’s a minimal example?Install the prerelease package (e.g., dotnet add package Microsoft.Agents.AI.OpenAI --prerelease), create an OpenAIClient, get a chat client, then CreateAIAgent with system instructions and call RunAsync with your query. Follow best practices for secrets: don’t hard-code API keys—use environment variables, key vaults, or secrets managers.

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