
Building AI Agents with Microsoft Agent Framework in C#
Br Re
August 22, 2026
7 views
Microsoft Agent Framework is awesome for building AI agents quickly. It gives developers a way to connect language models to real application features instead of using an LLM only for simple question-and-answer prompts.
An AI agent can understand a request, decide what needs to happen, use tools, retrieve information, and then return a useful response. Microsoft Agent Framework helps organize all of that work, especially when building applications with C# and .NET.
It works well with Azure AI Foundry and other LLM providers, so developers are not necessarily locked into one model. It also supports context providers, MCP servers, and other tool calls. The backend of this website uses Microsoft Agent Framework to power its AI features.
What is Microsoft Agent Framework?
Microsoft Agent Framework is a framework for building AI agents and multi-agent applications. It provides the pieces needed to connect an agent to a language model, provide context, call tools, and coordinate different parts of a workflow.
Rather than treating an LLM as a basic text-generation service, an agent can use the model to understand a request and then interact with the rest of the application. For example, it could look up information, call an internal API, use a knowledge source, or start an approved operation.
Microsoft Agent Framework brings together ideas from Microsoft’s earlier agent-development projects, including Semantic Kernel and AutoGen. It is the next direction for building these types of applications and is intended to make agent development easier for .NET developers.
Why I like Microsoft Agent Framework
The biggest benefit for me is how quickly I can turn an idea into a working AI feature. I can define an agent, connect it to a model, provide instructions, and then add tools or context without building the entire orchestration system from scratch.
It is also a natural fit for applications already built with C# and .NET. Instead of adding a completely separate technology stack, I can build AI features alongside the existing application, services, and business logic.
Some of the main capabilities include:
- Model integration: Agents can connect to models available through Azure AI Foundry and other supported LLM providers.
- Tool use: Agents can call application functions, APIs, MCP servers, and other services.
- Context management: Applications can provide relevant information from conversations, users, databases, and other sources.
- Multi-agent workflows: Multiple agents can be used when different parts of a task need different responsibilities.
- Application integration: Agent functionality can be added to existing C# and .NET backends.
This means I can spend more time working on the actual feature instead of repeatedly creating the same plumbing for model calls, tool calls, and context handling.
Azure AI Foundry and other LLM models
Microsoft Agent Framework works especially well with Azure AI Foundry. Azure AI Foundry provides services and tools for building and deploying generative AI applications, and Agent Framework provides the agent layer around those models.
It can also work with other LLM providers. This gives developers more flexibility when choosing a model based on its capabilities, price, speed, hosting requirements, or data requirements.
That flexibility is important because there is no single model that is best for every task. A fast and inexpensive model might be enough for classification or a simple support request, while a more capable model might be better for a complicated reasoning task.
By keeping the agent workflow separate from the model connection, it is easier to change models later. The application can still use the same general agent structure while the model is updated or replaced.
Context providers
A language model does not automatically know what is happening inside an application. It does not know the current user, the page they are viewing, their account information, or the latest data in a company database unless the application provides that information.
Context providers help solve this problem. They allow the application to supply useful information to an agent at the right time.
Context might include:
- Conversation history
- User preferences
- The current page or feature being used
- Account or customer information
- Documents and knowledge-base content
- Data retrieved from internal services
Instead of adding every possible piece of data to every prompt, the application can provide only the context relevant to the current request. This can improve the quality of the response and reduce unnecessary prompt content.
Context providers are also important for control. The application decides what information is available to the agent, rather than allowing the model to access everything automatically.
MCP servers and tool calls
AI agents become much more useful when they can do things instead of only generating text. Microsoft Agent Framework supports tool calls, including connections to Model Context Protocol, commonly called MCP, servers.
MCP provides a standard way for AI applications to discover and use tools and resources exposed by compatible servers. An MCP server could provide access to a service, a data source, or a business operation.
I can also expose my own C# functions and services as tools. This allows an agent to interact with the application through clearly defined operations. For example, a tool could retrieve information, validate a value, create a draft, or start an approved workflow.
The agent can decide when a tool is useful, but the application still needs to control what the tool is allowed to do. Sensitive operations should include authentication, authorization, validation, logging, and possibly human approval.
Giving an agent access to a tool does not mean the agent should have unlimited access to the application. Tools should be kept small, focused, and limited to the operations required for the feature.
Using it in a website backend
Microsoft Agent Framework is not only useful for demos or standalone chat applications. It can be used in the backend of a website to power real AI features.
The general flow is fairly straightforward. The website sends a request to the backend. The backend provides the relevant context, calls the agent, and allows the agent to use any approved tools. The final result is then returned to the website.
The backend of this website uses Microsoft Agent Framework for its AI features. This lets the website connect AI capabilities to its own application context and services while continuing to use a C# backend.
Keeping the agent in the backend has several advantages:
- Model credentials do not need to be exposed in the browser.
- Tool access can be controlled on the server.
- Business rules can be enforced before an action is performed.
- Requests and tool calls can be logged and monitored.
- The frontend can stay focused on the user experience.
This separation also makes it easier to update the AI workflow without rebuilding the entire frontend application.
Why C# support matters
Many businesses already use C#, .NET, Azure, and Microsoft services. Adding AI capabilities is easier when the agent can be built using the same language and application architecture that the rest of the system already uses.
With Microsoft Agent Framework, developers can define agents, register tools, connect context providers, and coordinate model interactions in C#. Existing development practices such as dependency injection, testing, authorization, and logging can still be used.
I also like that the framework keeps an important boundary in place. The model can help understand a request and decide which available tool might be useful, but the C# application remains responsible for business rules and permissions.
The model should not be trusted to enforce every rule by itself. The application needs to verify inputs and decide whether an action is actually allowed.
From prompts to workflows
A simple prompt can be enough for a small feature. However, more advanced applications usually need several steps, tool calls, context sources, error handling, and clear rules about what happens next.
Microsoft Agent Framework helps provide structure for those workflows. An agent can receive a request, use context, call one or more tools, process the results, and return a final response.
The goal is not to let the agent operate without limits. The goal is to give the model a controlled environment where it can help decide how to complete a task while the application controls the available data and actions.
This is the part I find most useful. The model provides language understanding and flexible reasoning, while the application provides trusted context, tools, permissions, and business logic.
Getting started
A good first project should be small and focused. I would start with one agent, one model, and a limited number of tools. It is much easier to understand how the system behaves when the first workflow has a clear purpose.
- Define the task: Decide exactly what the agent should help the user accomplish.
- Choose a model: Select an appropriate model through Azure AI Foundry or another supported provider.
- Provide context: Connect the information the agent needs to respond accurately.
- Add tools carefully: Expose only the functions and services needed for the task.
- Set boundaries: Add authorization, validation, error handling, and approval steps where necessary.
- Test the workflow: Test both the quality of the responses and the safety of tool calls.
After the first workflow is reliable, additional tools, context sources, or agents can be added. Starting small makes it easier to see where better instructions, more context, or stronger application controls are needed.
Conclusion
Microsoft Agent Framework is a great foundation for building AI agents in C#. It makes it possible to connect language models to real application features, including context providers, MCP servers, APIs, and custom tools.
Its integration with Azure AI Foundry and support for other LLM models gives developers flexibility. The framework also makes it easier to build AI features directly into existing .NET applications instead of creating a completely separate system.
For me, the main value is the combination of speed and control. I can build AI features quickly, while still keeping data access, permissions, business logic, and workflow rules inside the application.
That is why Microsoft Agent Framework works well for the backend of this website and why I think it is worth exploring for other C# and .NET projects.
References
- Microsoft Agent Framework: https://learn.microsoft.com/agent-framework/
- Microsoft Agent Framework GitHub repository: https://github.com/microsoft/agent-framework
- Azure AI Foundry documentation: https://learn.microsoft.com/azure/ai-foundry/
- Model Context Protocol documentation: https://modelcontextprotocol.io/
- Semantic Kernel documentation: https://learn.microsoft.com/semantic-kernel/
- AutoGen documentation: https://microsoft.github.io/autogen/