azd deployment steps.
Prerequisites
Before you begin, you need:- An Azure subscription—Create one for free.
-
If you have an existing Foundry project, you need
Foundry Project Managerat project scope. If you need to create a new Foundry project, you needOwnerrole at resource group scope. For the full role matrix, see Hosted agent permissions reference. - Azure Developer CLI (azd) 1.27.1 or later.
-
The
azd microsoft.foundryextension: -
An authenticated
azdsession: - Your existing agent code in a local directory.
- For the Python path, Python 3.13 or later.
- For the C# path, the .NET 10 SDK or later.
- (Optional) To start from a sample in Visual Studio Code, install Visual Studio Code and the Microsoft Foundry Toolkit for Visual Studio Code.
Choose your framework
The hosting library you add in Step 1 handles the protocol - the HTTP server, health checks, and request and response schemas. It doesn’t depend on a specific agent framework, so your agent logic can use any packages you prefer, in Python or C#. To use a framework, add its packages next to the hosting library, then call the framework from the handler. The following table lists common choices and a Python sample for each.
Each sample’s
requirements.txt lists the exact package versions. For the full set of bring-your-own samples, see the Python samples folder.
For C#, add framework packages to your project file next to the hosting package, then call the framework from the handler in Program.cs. For the full set of C# examples, see the C# bring-your-own samples folder.
Microsoft Agent Framework has a built-in hosting integration that uses its own package. To deploy a Microsoft Agent Framework agent, see Deploy your first hosted agent.
Start from a sample in Visual Studio Code
To start from a working framework template instead of your own code, use the sample gallery in the Microsoft Foundry Toolkit for Visual Studio Code:- In the Visual Studio Code Activity Bar, select the Foundry Toolkit icon.
- Under Developer Tools > Agent Dev Tools, select Create Agent.
- Under Create in code with full control, select Use a sample.
- On Create Hosted Agent from Sample, use the filters to narrow the gallery:
- For Framework, select Agent Framework, Bring Your Own, LangGraph, or Copilot SDK.
- For Protocol Type, select Responses API or Invocations API.
- Select a sample, and then select Next.
- Enter an agent name, select your Foundry project, and then select Create.
Choose your protocol
Each code step has a tab for every combination of language and protocol. Responses manages conversation history and is OpenAI-compatible. Invocations gives you full control over request and response schemas. Select the same language and protocol combination in every step.Step 1: Add the hosting library
Add the protocol library to your project. The library handles the HTTP server, health checks, and protocol compliance, independent of the agent framework you use. If you use a framework, add its packages alongside the hosting library - see Choose your framework.- Python (Responses)
- Python (Invocations)
- C# (Responses)
- C# (Invocations)
Add the protocol library to your
requirements.txt:Step 2: Add the hosting wrapper
Create or update your agent entry point with the hosting wrapper. The following examples show the minimal pattern. Replace the marked block with your existing agent logic.- Python (Responses)
- Python (Invocations)
- C# (Responses)
- C# (Invocations)
Create or update
main.py:These examples echo user input to demonstrate the hosting wrapper. Replace the marked block with your own agent logic - model calls, RAG, or a framework like LangGraph or the GitHub Copilot SDK. For complete examples, see the Python samples and C# samples.
Step 3: Initialize the project
Runazd ai agent init from your agent source directory. The Azure Developer CLI detects your language from the project files:
- Agent name: Customize the name or accept the default.
- Foundry Project: Select Use an existing Foundry project or Create a new Foundry project.
- Subscription: Select your Azure subscription.
- Location: Select an Azure region.
Step 4: Provision Azure resources
Step 5: Test the agent locally
Step 6: Deploy to Foundry Agent Service
Step 7: Invoke the deployed agent
Clean up resources
Troubleshooting
For the full permission and role-assignment matrix, see Hosted agent permissions reference.
What you learned
In this quickstart, you:- Added one hosting library to your existing agent code.
- Initialized an
azdproject from your source directory. - Tested locally with
azd ai agent runandazd ai agent invoke --local. - Deployed to Foundry Agent Service with
azd deploy.
Next steps
Manage hosted agent lifecycle
- Build a toolbox and use it with a hosted agent to combine tools behind one managed endpoint.