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.
Building AI Agents in .NET ebook for free