Introduction
Building an AI agent locally is usually the easy part.
A small .NET application can connect to a model, provide instructions, call tools, and return a response with relatively little code. The more difficult question often comes afterward:
How do you move that agent from a developer machine into a managed production environment?
Traditionally, deployment can involve containerization, hosting, authentication, session management, observability, scaling, and version management.
Microsoft Foundry Hosted Agents are designed to provide a managed hosting layer for custom agent applications. Hosted Agents support custom agent code and frameworks, including C# applications built with Microsoft Agent Framework. Microsoft manages infrastructure around the deployed agent, including compute, session handling, identity, and deployment lifecycle.
This makes deployment overhead an interesting engineering topic.
Rather than simply saying that deployment is "easy," we can measure the work involved in moving a .NET agent from local execution to a hosted environment.
What Is a Foundry Hosted Agent?
A Hosted Agent allows custom agent code to run inside Microsoft Foundry Agent Service.
The basic architecture looks like this:
.NET Agent
|
v
Container Image
|
v
Azure Container Registry
|
v
Microsoft Foundry Agent Service
|
+--> Compute
+--> Agent Identity
+--> Session State
+--> Endpoint
+--> ObservabilityThe platform packages the agent and deploys it into managed infrastructure. Microsoft documents that Hosted Agents can use custom code or supported agent frameworks and expose a dedicated endpoint after deployment.
For C# developers, this means an existing agent does not necessarily need to be redesigned as a completely separate web application.
Starting With a Minimal .NET Agent
A simple Microsoft Agent Framework application can start as a console application.
For example:
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
var endpoint =
Environment.GetEnvironmentVariable(
"FOUNDRY_PROJECT_ENDPOINT")
?? throw new InvalidOperationException(
"FOUNDRY_PROJECT_ENDPOINT is not configured.");
var deployment =
Environment.GetEnvironmentVariable(
"AZURE_AI_MODEL_DEPLOYMENT_NAME")
?? "gpt-5-mini";
AIAgent agent =
new AIProjectClient(
new Uri(endpoint),
new DefaultAzureCredential())
.AsAIAgent(
model: deployment,
instructions:
"You are a helpful assistant.",
name: "HelloAgent");
var response =
await agent.RunAsync(
"Explain dependency injection in .NET.");
Console.WriteLine(response);The exact model deployment name depends on the Foundry project.
At this point, the application is simply a .NET process running the agent locally.
The deployment problem starts when another application or user needs to communicate with it.
The Traditional Deployment Path
Without a managed hosting service, the developer may need to build several pieces around the agent:
Agent Code
|
+--> HTTP Server
|
+--> Container
|
+--> Authentication
|
+--> Session Storage
|
+--> Scaling
|
+--> Telemetry
|
+--> Deployment PipelineEach component introduces additional configuration and maintenance.
The purpose of Hosted Agents is to provide managed infrastructure around the agent rather than requiring every team to build these components independently.
Making a .NET Agent Hosted-Ready
Microsoft's current .NET integration uses the Microsoft.Agents.AI.Foundry.Hosting package.
The documented setup uses:
dotnet add package Microsoft.Agents.AI.Foundry.Hosting --prereleaseThe hosting package is currently published as a prerelease package even though Foundry Hosted Agents themselves are generally available, so teams should review package versions and release notes before using it in production.
The hosted version can use the Foundry agent host:
using Azure.AI.AgentServer.Core;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Foundry.Hosting;
var projectEndpoint =
new Uri(
Environment.GetEnvironmentVariable(
"FOUNDRY_PROJECT_ENDPOINT")
?? throw new InvalidOperationException(
"FOUNDRY_PROJECT_ENDPOINT is not configured."));
var deployment =
Environment.GetEnvironmentVariable(
"AZURE_AI_MODEL_DEPLOYMENT_NAME")
?? "gpt-5-mini";
AIAgent agent =
new AIProjectClient(
projectEndpoint,
new DefaultAzureCredential())
.AsAIAgent(
model: deployment,
instructions:
"You are a helpful assistant.",
name: "HelloAgent");
var builder = AgentHost.CreateBuilder(args);
builder.Services.AddFoundryResponses(agent);
builder.RegisterProtocol(
"responses",
endpoints =>
endpoints.MapFoundryResponses());
var app = builder.Build();
app.Run();The three hosting-related additions are the agent host builder, Responses registration, and protocol registration. Microsoft describes this as the minimal path for exposing an existing Agent Framework agent through the Foundry Responses protocol.
Why the Responses Protocol Matters
Hosted Agents support two protocol approaches:
Responses
Invocations
The Responses protocol is the recommended starting point for most conversational agents. It provides an OpenAI-compatible /responses endpoint and allows the hosting platform to manage conversation history, streaming, and session lifecycle.
The Invocations protocol is more appropriate when the application needs greater control over the raw request and response or requires custom payloads.
For a normal conversational .NET agent, Responses is usually the simpler starting point.
Running the Agent Locally
Before deploying to Azure, test the hosted version locally.
The Azure Developer CLI provides an agent extension:
azd ext install azure.ai.agentsThe project can then be initialized for agent hosting:
azd ai agent initStart the local agent:
azd ai agent runThe local hosting environment listens on port 8088 by default.
You can invoke it with:
azd ai agent invoke --local "Hello!"Or with HTTP:
curl -X POST http://localhost:8088/responses \
-H "Content-Type: application/json" \
-d '{"input":"Explain async programming in C#."}'The local environment is intended for development and testing. It should not be treated as a production authentication boundary.
Measuring Local Startup
Before deployment, record the local startup characteristics.
Useful measurements include:
| Metric | Measurement |
|---|---|
| Application startup time | Record |
| First successful request | Record |
| Agent response time | Record |
| Build time | Record |
| Published output size | Record |
| Container build time | Record |
Do not assume that local startup time represents cloud startup time.
The environments are different.
The purpose of the local measurement is to establish a baseline.
Measuring Provisioning Time
The first deployment step is resource provisioning.
The documented workflow uses:
azd provisionDepending on the project configuration, provisioning can create resources such as:
Microsoft Foundry resources
Foundry project
Model deployment
Application Insights
Azure Container Registry
Microsoft documents this as part of the standard Hosted Agent deployment flow.
Record the time before and after provisioning:
T0 = azd provision starts
T1 = provisioning completes
Provisioning Time = T1 - T0The actual duration depends on the Azure region, resource availability, subscription configuration, and resources being created.
Measuring Deployment Time
After provisioning, deploy the agent:
azd deployThe deployment process packages the agent, pushes the container image to Azure Container Registry, and deploys it to Foundry Agent Service.
Measure:
T2 = azd deploy starts
T3 = hosted agent becomes available
Deployment Time = T3 - T2This provides a much more meaningful measurement than saying deployment requires "two commands."
Two commands describe the developer experience.
Timing describes the actual operational overhead.
Breaking Deployment Overhead Into Stages
A better benchmark separates the process.
Source Preparation
|
v
Build
|
v
Container Packaging
|
v
Image Push
|
v
Agent Registration
|
v
Infrastructure Startup
|
v
ReadyMeasure each stage where the tooling exposes sufficient information.
This helps identify the actual source of deployment delay.
For example:
Build -> Measure
Container push -> Measure
Agent activation -> Measure
First request -> Measure
Join the conversation! Your thoughts help the community grow.