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