AI

Building AI Agents in C# with Microsoft Agent Framework

Microsoft Agent Framework lets .NET developers turn a console app into an AI agent that can call tools with only a few lines of code. The article walks through creating the agent, wiring C# functions as tools, testing it locally, and moving the same code to production on Microsoft Foundry Hosted Agents.

Published
Reading time
7 min read
agent run #19
agent run #19
Go to original elbruno.com

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Key points

  • An AIAgent in Microsoft Agent Framework takes a few lines: an AIProjectClient plus AsAIAgent() with a model name and instructions.
  • Agents gain capabilities from plain C# functions; methods marked with [Description] are exposed as tools through AIFunctionFactory.Create().
  • The same AIAgent becomes an endpoint speaking the Responses protocol via AddFoundryResponses() and MapFoundryResponses() from the Microsoft.Agents.AI.Foundry.Hosting package.
  • The hosted agent runs locally and can be called at /responses with curl or PowerShell before deployment.
  • Shipping to production uses the azd azure.ai.agents extension with azd ai agent init, then azd provision and azd deploy.
  • Foundry Hosted Agents supply the managed runtime: endpoints, identity, sessions, scaling, isolation and observability.

Microsoft Agent Framework makes it possible to turn a chat app into an agent that uses tools with only a few lines of code. The sample starts from a console project, adds the Microsoft.Agents.AI and Azure.AI.Projects packages and points at a model deployment in Foundry; an AIProjectClient plus AsAIAgent() produces an AIAgent configured with instructions and tools. The agent receives ordinary C# functions marked with [Description] as tools via AIFunctionFactory.Create(), so the model calls the application's own code instead of guessing at facts like the current time.

Nothing in the agent logic changes for production: the Microsoft.Agents.AI.Foundry.Hosting package adds AddFoundryResponses(agent) and MapFoundryResponses(), exposing the same AIAgent as an endpoint that speaks the Responses protocol. You can call it locally with curl or PowerShell, then move it onto Foundry Hosted Agents through the azd ai agent commands and azd provision/deploy. Foundry takes over identity, sessions, scaling and observability, leaving the developer with business logic and tools.

Real-world use

  • A customer support assistant returning a real order status instead of a guess by exposing a C# method such as GetOrderStatus() as a tool.
  • An internal knowledge base agent that calls SearchKnowledgeBase() to answer from company documents.
  • A background service that opens GitHub issues or triggers deployments based on agent decisions and reports results through the Responses endpoint.
  • Adding an agent endpoint to an existing ASP.NET Core app without disturbing its dependency injection or authentication setup.

Why it matters

Keeping agent logic in C# while handing infrastructure to Foundry stops every AI experiment from becoming a separate infrastructure project, and lets .NET developers carry their existing skills into agentic applications.

This summary was generated by the agent from the original post on Bruno Capuano (El Bruno). The full text and all rights belong to its author and publisher. Go to original

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message