Executive Summary
Building an AI agent in C# using modern libraries like the Microsoft Agent Framework and Microsoft.Extensions.AI has become remarkably straightforward: a fully functional agent can be implemented in ten lines of console code. However, taking that agent "beyond localhost" into production introduces enterprise-grade requirements:
- How do you expose the agent over standardized protocols?
- How do you test and inspect agent execution loops locally without building a custom chat frontend?
- How do you package, version, and deploy C# agent code to the cloud?
- How do you govern credentials without leaking API keys?
- How do you monitor execution traces, token consumption, and tool latencies?
In this session, Bruno Capuano presents the complete productionization lifecycle for .NET agents using Azure AI Foundry. He demystifies the distinction between portal-configured Prompt Agents and code-first Hosted Agents—where developers write and debug custom C# logic locally, package it via the Azure Developer CLI (azd), and host it inside isolated container runtimes within Foundry. Capuano also challenges the assumption that every agent requires a generative Large Language Model (LLM), demonstrating how to implement ultra-fast, deterministic Microsoft Decision Models for classification tasks, enable real-time Voice Mode, and orchestrate diverse frontier models such as Moonshot AI's Kimi 3.1.
Visual Timeline & Key Moments
| Timestamp | Screenshot | Core Technical Topic |
|---|---|---|
00:00:15 |
01-title-beyond-localhost-foundry.jpg | Session introduction: Bruno Capuano on taking .NET agents from localhost to production in Foundry. |
00:01:25 |
02-journey-localhost-to-production.jpg | The Developer Journey: Progressing from a minimal 10-line C# prototype to cloud deployment. |
00:02:15 |
03-demo1-ten-line-minimum-agent.jpg | Demo 1: The minimum viable C# agent using AIProjectClient, Azure CLI credentials, and AIAgent. |
00:03:30 |
04-demo2-aspnetcore-agent-host-builder.jpg | Demo 2: Wrapping the agent in ASP.NET Core WebApplicationBuilder and registering Foundry protocol. |
00:04:45 |
05-demo2-local-chat-test-harness.jpg | Demo 2: Local test harness (azd ai agent run) running test chat UI on port 8087 against agent on 8088. |
00:06:20 |
06-demo2-local-agent-logs-tracking.jpg | Demo 2: Live console logs showing request streaming, tool execution, and token usage tracking. |
00:07:35 |
07-foundry-prompt-vs-hosted-agents.jpg | Architectural comparison: Portal-defined Prompt Agents vs. Containerized C# Hosted Agents. |
00:09:15 |
08-packaging-container-hosted-agents.jpg | Container definition: azure.yaml configuring .NET 11 binary execution and Foundry response protocol. |
00:10:45 |
09-foundry-portal-hosted-agent-versions.jpg | Foundry Management: Hosted Agent overview with active version selection and A/B testing controls. |
00:12:35 |
10-foundry-real-time-trace-observability.jpg | Observability: Deep conversational trace view detailing model calls, tools executed, and latency spans. |
00:14:00 |
11-foundry-enterprise-entra-a2a-teams.jpg | Enterprise integrations: Entra ID Agent Identity, Agent-to-Agent (A2A) Agent Cards, and Teams export. |
00:16:30 |
12-beyond-llms-decision-models.jpg | Beyond Generative LLMs: Microsoft Decision Models for low-cost, deterministic classification. |
00:18:20 |
13-code-support-routing-decision-agent.jpg | Code: Implementing custom AIAgent overriding RunCoreAsync with Microsoft.Decision-1 model. |
00:20:45 |
14-demo-decision-model-probabilities-output.jpg | Demo: Ticket routing outputting exact category probabilities (Billing: 99.7% confidence). |
00:22:20 |
15-demo-voice-mode-on-decision-agent.jpg | Live Demo: Activating real-time Voice Mode over the hosted C# Decision Agent in Foundry. |
00:25:00 |
16-multi-model-kimi-tools-conversation-traces.jpg | Multi-Model Ecosystem: Hosting Moonshot AI's Kimi 3.1 with custom C# tools and complete trace graphs. |
1. The Productionization Lifecycle: From Localhost to Cloud
The development progression follows three architectural phases:
flowchart LR
subgraph Phase1["Phase 1: Local Console Prototype"]
C_Code["Program.cs (10 Lines)"]
C_Cred["AzureCliCredential"]
C_Agent["AIAgent Execution"]
C_Code --> C_Cred --> C_Agent
end
subgraph Phase2["Phase 2: Local HTTP Agent Host"]
H_Web["WebApplicationBuilder"]
H_Prot["AddFoundryResponses()"]
H_Port["localhost:8088"]
H_Test["azd Local Chat: 8087"]
H_Web --> H_Prot --> H_Port <==> H_Test
end
subgraph Phase3["Phase 3: Azure AI Foundry Hosted Agent"]
F_Yaml["azure.yaml Container Spec"]
F_Entra["Microsoft Entra Agent Identity"]
F_Svc["Foundry Hosted Agent Service"]
F_Obs["Traces, A2A Cards & Teams"]
F_Yaml --> F_Entra --> F_Svc --> F_Obs
end
Phase1 ==> Phase2 ==> Phase3
2. Phase 1 & 2: Local Authoring and Testing
Phase 1: The 10-Line Console Agent
In the earliest prototyping phase, developers initialize an AIProjectClient from the Microsoft Agent Framework connected to an Azure AI Foundry project:
// 01-hello-agent / Program.cs
using Azure.Identity;
using Azure.AI.Projects;
using Microsoft.Agents.Core;
// Authenticate securely via local developer Azure CLI credentials (zero API keys):
var projectClient = new AIProjectClient(
new Uri("https://my-foundry-resource.services.ai.azure.com/api/projects/sample"),
new AzureCliCredential());
// Instantiate an AI Agent wired to a deployed foundation model:
var agent = await projectClient.CreateAgentAsync(
model: "gpt-6-luna",
name: "DotNetConfHelloAgent",
instructions: "You are a concise .NET assistant. Answer developer queries factually.");
// Execute conversational query:
var response = await agent.AskAsync("Tell me a fun story about .NET history.");
Console.WriteLine(response.Text);
Phase 2: Exposing the Agent via ASP.NET Core & azd
To decouple questions from hardcoded source code and test how the agent behaves over network transport, developers wrap the agent in an ASP.NET Core minimal web host exposing the Foundry Protocol:
// 02-agent-host / Program.cs
var builder = WebApplication.CreateBuilder(args);
// Register the Foundry request/response protocol handler:
builder.Services.AddFoundryResponses(options =>
{
options.Agent = agent;
options.EnableStreaming = true;
});
var app = builder.Build();
app.MapFoundryProtocol(); // Maps standard JSON-RPC / SSE agent endpoints
app.Run("http://localhost:8088");
The Local Test Harness (azd ai agent run)
Rather than forcing developers to build a frontend just to test tool calling or streaming responses, the Azure Developer CLI (azd) provides an instant local web harness:
- Port
8088: Houses the developer's C# agent process. - Port
8087: Serves an interactive chat GUI with real-time token tracking, event streams, tool execution timelines, and inspector views directly inside Visual Studio Code.
3. Prompt Agents vs. Hosted Agents in Azure AI Foundry
Foundry offers two fundamentally distinct agent architectures:
classDiagram
class PromptAgent {
+Configured in Foundry Web UI
+Predefined System Prompt in Portal
+Standard Foundation Model (GPT/Grok)
+Built-in Web Search / Azure AI Search
+Zero Code Deployment Required
}
class HostedAgent {
+Authoring in Pure C# (.NET 10 / 11)
+Custom Business Rules & State Machines
+Custom C# Tool Handlers (Calculators, DBs, ERPs)
+Decision Models or Non-LLM Algorithms
+Packaged into Container via azure.yaml
+Managed by Entra ID Agent Identity
}
Comparison Matrix
| Capability | Prompt Agents | Hosted Agents (C# / .NET) |
|---|---|---|
| Authoring Surface | Foundry Portal Web UI | Visual Studio / VS Code (C# codebase) |
| Logic Customization | Natural language instructions only | Full C# object-oriented code, loops, conditions |
| Tool Calling | Built-in search, OpenAPI specs, Python code interpreter | Native C# methods, microservices, MCP servers, EF Core |
| Supported Models | Standard LLMs hosted in Foundry catalog | Any model: GPT, Grok, Kimi, or non-generative Decision Models |
| Deployment Model | Cloud metadata record | Containerized microservice managed via azd |
| Enterprise Identity | User credentials or system keys | Microsoft Entra Agent Identity (Managed Identity) |
| Lifecycle & CI/CD | Portal editing | GitHub Actions / Azure Pipelines with semantic versioning |
4. Containerizing & Deploying Hosted Agents
Hosted agents are packaged using standard cloud-native container definitions. Capuano shows how azure.yaml configures the service deployment:
# azure.yaml
name: dotnetconf-hosted-agent
metadata:
template: dotnet-foundry-hosted-agent@1.0
services:
agent:
project: ./src/HelloAgent.csproj
host: containerapp
language: dotnet
env:
- name: AZURE_AI_PROJECT_ENDPOINT
value: "https://my-foundry.services.ai.azure.com/api/projects/production"
- name: AZURE_DEPLOYMENT_NAME
value: "gpt-6-luna"
- name: FOUNDRY_RESPONSE_PROTOCOL
value: "enabled"
Deployment is executed via two automated CLI commands:
# Provision Azure Container App infrastructure & Entra Identity:
azd ai agent provision
# Build .NET 11 binary, package container, push to registry, and activate in Foundry:
azd ai agent deploy
Foundry Enterprise Features Unlocked for C# Agents
Once deployed as a Hosted Agent, Foundry automatically wraps the C# service with enterprise-grade capabilities:
- Semantic Versioning & Traffic Routing: Every deployment registers a new immutable version (e.g. Version 1 -> Version 6). Developers can toggle active versions, conduct A/B split testing, or roll back instantly without touching consumer endpoints.
- Microsoft Entra Agent Identity: Agents mint their own security tokens via Entra Managed Identity, allowing them to access downstream SQL databases, Blob Storage, or internal APIs without storing a single password or API secret.
- Agent-to-Agent (A2A) Protocols: Foundry generates an Agent Card exposing metadata, capabilities, and input/output contracts so other autonomous agents across the organization can discover and invoke it.
- Multi-Channel Distribution: One-click deployment to Microsoft Teams, web chat iframes, or real-time WebSockets.
- Full Conversational Observability: Deep trace inspector mapping each conversational turn to underlying LLM token costs, prompt tokens, completion tokens, latency waterfalls, and tool execution payloads.
5. Beyond Generative LLMs: Deterministic Microsoft Decision Models
A critical architectural insight emphasized by Capuano is that agents do not always require generative Large Language Models. Generative models suffer from non-deterministic outputs, prompt injection risks, high token costs, and unnecessary verbal verbosity when the task is pure decision-making.
What are Microsoft Decision Models?
Decision Models (such as Microsoft.Decision-1) are non-generative AI models optimized specifically for deterministic classification and routing. Given an input query and a set of candidate choices with evaluation criteria, the model outputs an exact probability distribution across choices without generating chat text.
┌─────────────────────────────────────────────────────────────────┐
│ MICROSOFT DECISION-1 MODEL │
│ │
│ Input Query: "I was charged twice for my subscription!" │
│ │
│ Candidate Choices & Output Probabilities: │
│ ├── Billing: 99.7% ████████████████████ (WINNER!) │
│ ├── Technical Support: 0.1% │
│ ├── Account Access: 0.1% │
│ └── Manual Review: 0.1% │
└─────────────────────────────────────────────────────────────────┘
Implementing a Decision Agent in C#
Developers inherit from AIAgent and implement the execution contracts:
public class SupportRoutingAgent : AIAgent
{
private readonly DecisionClient _decisionClient;
public SupportRoutingAgent(DecisionClient decisionClient)
{
_decisionClient = decisionClient;
}
protected override async Task<AgentResponse> RunCoreAsync(
AgentContext context, CancellationToken cancellationToken)
{
var criteria = new[]
{
new DecisionChoice("Billing", "Inquiries regarding invoices, double charges, refunds, or payment methods."),
new DecisionChoice("TechnicalSupport", "Issues relating to crashes, search failures, API timeouts, or code errors."),
new DecisionChoice("AccountAccess", "Password resets, MFA lockouts, or permission changes."),
new DecisionChoice("ManualReview", "Ambiguous, high-risk, or unrecognized inquiries.")
};
var result = await _decisionClient.EvaluateAsync(context.UserPrompt, criteria, cancellationToken);
// Output deterministic routing decision with confidence score:
return new AgentResponse
{
SelectedChoice = result.TopChoice.Name,
Confidence = result.TopChoice.Probability,
Distribution = result.AllProbabilities
};
}
}
Voice Mode Over Decision Agents
In a live demonstration, Capuano toggles Voice Mode on the hosted Decision Agent in the Foundry portal. When spoken to ("Search stopped returning results after the latest update..."), the agent routes the issue to Technical Support (Confidence: 0.98) and speaks the routing action aloud in real time.
6. Multi-Model Ecosystem: Running Moonshot AI's Kimi 3.1
Foundry is not restricted to Microsoft or OpenAI models. Capuano demonstrates hosting an agent running Moonshot AI's Kimi 3.1 (Moonshot-Kimi-k3.1):
- Connected to custom C# tools (e.g. arithmetic calculation and word frequency counter).
- Interrogated via the Foundry conversation interface.
- Trace graphs display the complex multi-step tool execution loop:
Invoke Agent -> Chat with Kimi 3.1 -> Tool Call: CountWords -> Receive Output -> Tool Call: AddNumbers -> Final Response.
Technical Recommendations for .NET Engineering Teams
- Use
azd ai agentfor Local Inner Loops: Adoptazd ai agent runto test and inspect C# agents onlocalhost:8088using the local8087web inspector before writing deployment scripts. - Favor Hosted Agents for Enterprise Codebases: When building production agents, use Hosted Agents rather than prompt agents so business logic, entity models, and tool invocations remain version-controlled in C#.
- Eliminate API Keys with Entra Agent Identity: Deploy agents with managed identities so containerized services authenticate to Foundry endpoints, databases, and external tools without hardcoded secrets.
- Choose Decision Models for Routing & Triage: Stop wasting generative LLM tokens on classification and ticket routing. Implement
Microsoft.Decision-1for instant, deterministic, low-cost routing. - Instrument Every Agent with OpenTelemetry: Ensure all tool invocations and model calls emit distributed traces into Application Insights for latency and cost auditing.















