This file documents the structure and conventions of the .NET samples so that agents (AI or human) can maintain them without rediscovering decisions.
dotnet/samples/
├── 01-get-started/ # Progressive tutorial (steps 01–06)
│ ├── 01_hello_agent/ # Create and run your first agent
│ ├── 02_add_tools/ # Add function tools
│ ├── 03_multi_turn/ # Multi-turn conversations with AgentSession
│ ├── 04_memory/ # Agent memory with AIContextProvider
│ ├── 05_first_workflow/ # Build a workflow with executors and edges
│ └── 06_host_your_agent/ # Host your agent via Azure Functions
├── 02-agents/ # Deep-dive concept samples
│ ├── Agents/ # Core agent patterns (tools, structured output,
│ │ # conversations, middleware, plugins, MCP, etc.)
│ ├── AgentProviders/ # One project per provider (Azure OpenAI, OpenAI,
│ │ # Anthropic, Gemini, Ollama, ONNX, Foundry, etc.)
│ ├── AgentOpenTelemetry/ # OpenTelemetry integration
│ ├── AgentSkills/ # Agent skills patterns
│ ├── AgentWithAnthropic/ # Anthropic-specific samples
│ ├── AgentWithMemory/ # Memory providers (chat history, Mem0, Foundry)
│ ├── AgentWithOpenAI/ # OpenAI-specific samples
│ ├── AgentWithRAG/ # RAG patterns (text, vector store, Foundry)
│ ├── AGUI/ # AG-UI protocol samples
│ ├── DeclarativeAgents/ # Declarative agent definitions
│ ├── DevUI/ # DevUI samples
│ ├── AgentsWithFoundry/ # Microsoft Foundry samples (FoundryAgent + AsAIAgent extensions)
│ └── ModelContextProtocol/ # MCP server/client patterns
├── 03-workflows/ # Workflow patterns
│ ├── _StartHere/ # Introductory workflow samples
│ ├── Agents/ # Agents in workflows
│ ├── Checkpoint/ # Checkpointing & resume
│ ├── Concurrent/ # Concurrent execution
│ ├── ConditionalEdges/ # Conditional routing
│ ├── Declarative/ # YAML-based workflows
│ ├── HumanInTheLoop/ # HITL patterns
│ ├── Loop/ # Loop patterns
│ ├── Observability/ # Workflow telemetry
│ ├── SharedStates/ # State isolation
│ └── Visualization/ # Workflow visualization
├── 04-hosting/ # Deployment & hosting
│ ├── A2A/ # Agent-to-Agent protocol
│ └── DurableAgents/ # Durable task framework
│ ├── AzureFunctions/ # Azure Functions hosting
│ └── ConsoleApps/ # Console app hosting
├── 05-end-to-end/ # Complete applications
│ ├── A2AClientServer/ # A2A client/server demo
│ ├── AgentWebChat/ # Aspire-based web chat
│ ├── AgentWithPurview/ # Purview integration
│ ├── AGUIClientServer/ # AG-UI client/server demo
│ ├── AGUIWebChat/ # AG-UI web chat
│ ├── HostedAgents/ # Hosted agent scenarios
│ └── M365Agent/ # Microsoft 365 agent
-
Progressive complexity: Sections 01→05 build from "hello world" to production. Within 01-get-started, projects are numbered 01–06 and each step adds exactly one concept.
-
One concept per project in 01-get-started. Each step is a standalone C# project with a single
Program.csfile. -
Workflows preserved: 03-workflows/ keeps the upstream folder names intact. Do not rename or restructure workflow samples.
-
Per-project structure: Each sample is a separate .csproj. Shared build configuration is inherited from
Directory.Build.props.
All canonical samples (01-get-started) use Azure OpenAI via AzureOpenAIClient
with DefaultAzureCredential:
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using OpenAI.Chat;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-5.4-mini";
// WARNING: DefaultAzureCredential is convenient for development but requires careful consideration in production.
// In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid
// latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
.GetChatClient(deploymentName)
.AsAIAgent(instructions: "...", name: "...");Environment variables:
AZURE_OPENAI_ENDPOINT— Your Azure OpenAI endpointAZURE_OPENAI_DEPLOYMENT_NAME— Model deployment name (defaults togpt-5.4-mini)
For authentication, run az login before running samples.
Samples embed named snippet regions for future :::code integration:
// <snippet_name>
code here
// </snippet_name>All samples use project references to the framework source. To build and run:
cd dotnet/samples/01-get-started/01_hello_agent
dotnet runAIAgentis the primary agent abstraction (created viaChatClient.AsAIAgent(...))AgentSessionmanages multi-turn conversation stateAIContextProviderinjects memory and context- Prefer
client.GetChatClient(deployment).AsAIAgent(...)extension method pattern - Azure Functions hosting uses
ConfigureDurableAgents(options => options.AddAIAgent(agent)) - Workflows use
WorkflowBuilderwithExecutor<TIn, TOut>and edge connections