🤖 Self-Hosted Agents with MAF
In this approach, we deploy a language model through Microsoft Foundry but build and execute the agent using Microsoft Agent Framework (MAF) inside our own .NET application.
Blazor Application
|
v
ASP.NET Core API
|
Microsoft Agent Framework
- Instructions
- C# Function Tools
- AgentSession
- Workflows
- HITL
|
| HTTPS
v
Microsoft Foundry
|
Model DeploymentThe model runs in Microsoft Foundry, while the agent's orchestration logic runs inside our ASP.NET Core application.
When the LLM decides to call a custom tool, the Agent Framework receives the tool call and executes the corresponding C# method.
This separation is important: the LLM decides which tool to request, but our application controls whether and how the operation is executed.
We remain responsible for implementing deterministic business rules, authorization, state persistence, observability, deployment, and scaling.
When should you choose this approach?
Self-hosting is particularly useful when:
- You already have an
ASP.NET Coreapplication or an established .NET infrastructure. - Your agents interact heavily with existing business services and databases.
- You need complete control over custom C# tools and deterministic validation.
- You want to implement custom workflows, HITL approvals, and multi-agent orchestration.
- You need to integrate with existing application authentication, middleware, or operational infrastructure.
- You want to expose agents through protocols such as AG-UI or A2A.
For example, imagine an enterprise ERP application built with Blazor and ASP.NET Core.
An AI agent can help users create orders, retrieve customer information, or generate operational reports. The agent reasons using a Foundry model, while all business operations remain controlled by the existing C# backend.
The main advantage is architectural control. The trade-off is that your team owns the agent's hosting and operational infrastructure.
💡Self-hosted does not necessarily mean running locally. The ASP.NET Core application can run in Azure App Service, Azure Container Apps, Kubernetes, or another hosting environment.
⚡ Foundry Prompt Agents
Prompt Agents take a more managed approach.
Instead of developing the agent's orchestration logic entirely in C#, we define the agent through Microsoft Foundry using instructions, a selected model, and supported tools.
Microsoft Foundry executes the agent and manages its runtime.
Application
|
| Foundry Agent API
v
Microsoft Foundry Agent Service
|
Prompt Agent
|
+-- Instructions
+-- Model
+-- File Search
+-- Supported ToolsThis reduces the amount of application code and infrastructure we need to maintain.
We can configure agents through the Foundry portal or programmatically through supported APIs and SDKs.
When should you choose Prompt Agents?
Prompt Agents are a good fit when:
- You want to develop an AI assistant quickly.
- Your requirements can be expressed through instructions and supported tools.
- You want managed access to knowledge sources such as documents.
- You do not need extensive custom orchestration logic.
- You want to reduce infrastructure and maintenance responsibilities.
For example, consider an internal documentation assistant that answers employee questions using a corporate knowledge base.
If its primary responsibility is searching documents and generating grounded answers, a Prompt Agent may be sufficient.
However, when requirements introduce extensive custom C# execution, complex deterministic workflows, or framework-specific orchestration, a code-based agent may become more appropriate.
The main advantage is simplicity and managed execution. The trade-off is less control over the underlying runtime and custom orchestration.
☁️ Foundry Hosted Agents
Hosted Agents combine custom agent code with Microsoft-managed hosting.
Instead of running our Microsoft Agent Framework application inside our own ASP.NET Core infrastructure, we package the agent and deploy it to Microsoft Foundry Agent Service.
The application continues to use our custom code and framework, but Foundry manages its execution environment.
Blazor / ASP.NET Core Client
|
| Foundry Agent API
v
Microsoft Foundry Agent Service
|
Hosted Agent
|
Custom C# Code
|
Microsoft Agent Framework
- Custom Tools
- Workflows
- Agent Logic
|
v
Foundry ModelFoundry Hosted Agents provide managed endpoints, scaling, identity, session infrastructure, and observability capabilities.
We still own the agent's code, its business logic, security decisions, and any external dependencies it requires.
When should you choose Hosted Agents?
Hosted Agents become attractive when:
- You want to use Microsoft Agent Framework with custom C# tools.
- Your application requires advanced orchestration or multi-agent workflows.
- You need custom runtime behavior rather than a purely prompt-defined agent.
- You want Microsoft to manage the hosting infrastructure.
- You need managed identity, scaling, and agent lifecycle capabilities.
- You are building agents intended to run independently from an existing application backend.
For example, imagine a software engineering agent that analyzes incidents, queries documentation, executes diagnostic tools, and coordinates multiple specialist agents.
We could implement its reasoning and orchestration using Microsoft Agent Framework, then deploy it as a Hosted Agent.
This provides flexibility without requiring our team to operate the complete agent hosting infrastructure.
The main advantage is combining custom-code flexibility with managed hosting. The trade-off is greater platform dependency and potentially additional compute costs.
📊 Comparing the Three Architectures
The most important distinction is that model hosting and agent hosting are separate architectural concerns.
Deploying a GPT model to Microsoft Foundry does not automatically mean our application has deployed an agent to Foundry Agent Service.
We can consume that model from our own .NET application while keeping all agent logic outside Foundry.
🔍 How I Would Choose
My approach would be to evaluate the application's requirements before choosing the hosting model.
- ✅ Choose Self-Hosted MAF when integrating agentic capabilities deeply into an existing .NET application and maintaining control over backend execution is important.
- ✅ Choose a Prompt Agent when supported tools and declarative configuration satisfy the requirements without custom orchestration code.
- ✅ Choose a Hosted Agent when custom code and advanced orchestration are necessary, but managed agent hosting is preferable to operating the infrastructure ourselves.
A useful architectural question is:
Where should the agent's orchestration logic live, and who should operate the infrastructure that executes it?
That decision influences security, scalability, operational complexity, cost, and how easily the agent integrates with existing business systems.
✅ Conclusion
Microsoft Foundry and Microsoft Agent Framework are complementary technologies rather than competing solutions.
Microsoft Foundry can provide model inference and managed agent infrastructure, while Microsoft Agent Framework provides the abstractions required to implement agents, tools, sessions, and workflows in code.
For .NET developers, understanding the distinction between model deployment, agent implementation, and agent hosting is essential when designing enterprise agentic AI systems.
The goal is not always to choose the most sophisticated architecture. It is to select the approach that provides the required capabilities with the appropriate level of control and operational complexity.
The model provides reasoning. The framework provides agent behavior. The hosting platform determines where and how the agent executes.
Comments (1)
Leave a Comment
Grazie mille!