Once you have your Microsoft Agent Framework (MAF) agent or workflow happily running locally on your dev machine, it’s time to decide how to deploy your agent to production, monitor it, evaluate it and version it. These decisions are just as important as getting the agent running. Hosted Agents in Foundry Agent Service is the easiest way to deploy Agent Framework agent to the cloud – with built-in identity, automatic scaling, managed session state, observability, and versioning.
What are Foundry Hosted Agents?
Foundry Hosted Agents are containerized applications that run inside Foundry Agent Service. Foundry Hosted Agents brings agent-optimized compute and services designed for production-grade enterprise agents, giving agents secure per-session sandboxes with filesystem persistence, integrated identity, and scale-to-zero economics. They are your own code, packaged as a container image and deployed to Foundry-manage infrastructure.
Core Capabilities:
- Predictable cold starts — spin up agent sessions and harnesses in your custom environment virtually instantly
- Scale to zero — pay nothing while your agent is idle, with an agent that will scale down on its own during inactivity
- Resume with filesystem intact — files, disk state, and session identity persist across scale-to-zero events. Your agent restarts with its full working directory exactly where it left off
- Per-session isolation is automatic — Every single agent session gets its own VM-isolated sandbox with persistent session state. Use isolation keys to easily manage and namespace your end users’ sessions
- BYO VNet Support – drive your agents’ outbound traffic via your VNet
- Production-ready agent endpoints – built-in agent versioning with stable endpoints for easy integration, weighted rollouts across versions
- Multiple protocols out of the box – OpenResponses protocol support with automatic mapping to/from Activity Protocol for one-click publish to Microsoft 365. Flexible Invocations protocol for custom application integrations, AG-UI support
When you deploy your MAF agent to Foundry Hosted Agents using azd it:
- (Optional) Creates all necessary resources, including a Foundry project and deploys a model.
- Packages your code, builds an image, and pushes it to Azure Container Registry (ACR).
- Pulls the image from ACR and provisions compute.
- Assigns a dedicated Entra ID to the agent.
- Expose a dedicated endpoint at, for example
https://{project_endpoint}/agents/{agent_name}. - Handles scaling, session state persistence, observability, and lifecycle management.
If unused, sessions persist for up to 30 days; idle compute is deprovisioned after 15 minutes and seamlessly restored on the next request. Read more about sessions in the here.
Choose your protocol: Responses or Invocations
Hosted agents speak one or both of two protocols:
- Responses: An OpenAI-compatible
/responsesendpoint. The platform manages conversation history, streaming events, and background execution. - Invocations: A generic
invocationsendpoint where you define the request/response schema, giving you flexibility for any non-conversational workflow that doesn’t fit a chat-shaped contract.
We recommend starting with `/responses` if you are not sure which one to use. Read more about supported protocols in the here.
Foundry Hosted Agents + Microsoft Agent Framework
Microsoft Agent Framework gives you a clean programming model for building agents – chat clients, tools, MCP integrations, context providers, middleware, and multi-step workflows, with the same concepts and APIs across .Net and Python. Foundry Hosted Agents give that code a production-grade home. Using MAF and Foundry Hosted Agents together enables a bunch of exciting capabilities
- Bring your code as-is: The same agents and workflows you run locally are the ones running in the sandbox.
- First class identity: Each agent gets its own Entra ID, allowing your agent to call Foundry models, Foundry toolbox, and any other Azure services, without the need to store secrets in the image. Â Read more about Agent Identity in the here.
- Version and safe rollout: Every deployment is an immutable version snapshot of your agent. Split traffic between versions for canary or blue/green rollout, and roll back instantly.
- Built-in observability: `APPLICATIONINSIGHTS_CONNECTION_STRING` is injected at runtime, so MAF’s OpenTelemetry traces flow into Application Insights with zero extra wiring.
- Stateful sessions: persist files and state to sessions and the platform restores them when a session resumes, even after idle scale-down.
- Foundry Toolbox: Connect to a Foundry Toolbox provisioned in the same Foundry project to use a wide variety of existing tools.
From local agent to hosted agent
To turn an agent into an agent host, it only takes a few lines of code.
In .Net:
using Microsoft.Agents.AI.Foundry.Hosting;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddFoundryResponses(agent);
var app = builder.Build();
app.MapFoundryResponses();
app.Run();
In Python:
server = ResponsesHostServer(agent)
server.run()
Get started today by exploring our samples:
Each sample contains detailed instructions to run the agent locally and as a Foundry Hosted Agent.
Wrapping up
Microsoft Agent Framework lets you focus on agent logic. Foundry Hosted Agents give that logic a managed home with identity, scaling, sessions, versioning, and observability handled for you. Together, they shorten the distance between a prototype agent and a production agent. If you already have a local agent built using Microsoft Agent Framework, now it is the time to try hosting it in Foundry and experience the production benefits firsthand!
Our teams are working hard to bring Foundry Hosted Agent and MAF integration to General Availability soon. Stay tuned for more!
Further reading:
- Hosted Agent Announcement
- Foundry Hosted Agent Docs
- Foundry Models Docs
- Foundry Hosted Agent .Net Samples
- Foundry Hosted Agent Python Samples
- MAF Hosted Agent Integration Doc
- MAF .Net Samples
- MAF Python Samples
The Microsoft Agent Framework team is dedicated to empowering developers by providing access to the latest advancements in the industry. We encourage you to leverage your creativity and build remarkable solutions with MAF! Please reach out if you have any questions or feedback through our Agent Framework GitHub Discussion Channel. We look forward to hearing from you! We would also love your support, if you’ve enjoyed using Agent Framework, give us a star on GitHub.
0 comments
Be the first to start the discussion.