Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this quickstart, you deploy a containerized AI agent with Foundry tools to Foundry Agent Service. The sample agent uses web search and optionally MCP tools to answer questions. By the end, you have a running hosted agent that you can interact with through the Foundry playground. Choose your preferred deployment method to get started.
In this quickstart, you:
- Set up an agent sample project with Foundry tools
- Test the agent locally
- Deploy to Foundry Agent Service
- Interact with your agent in the playground
- Clean up resources
Prerequisites
Before you begin, you need:
- An Azure subscription - Create one for free
- (Optional) An MCP tool, if you have one you want to use.
- Python 3.10 or later
- Azure Developer CLI version 1.23.0 or later
Note
Hosted agents are currently in preview.
Step 1: Set up the sample project
Install the Azure Developer CLI agent extension and initialize a new hosted agent project.
Install the
ai agentextension for the Azure Developer CLI:azd ext install azure.ai.agentsTo verify the extension is installed, run:
azd ext listInitialize a new hosted agent project:
azd ai agent initWhen prompted, select Start new from a template. The interactive flow guides you through the following configuration:
- Environment name — determines your resource group name (for example,
my-hosted-agentcreatesrg-my-hosted-agent). - Azure subscription — select the subscription where you want the Foundry resources to be created.
- Location — select a region for the resources.
- Model SKU — select the SKU available for your region and subscription.
- Deployment name — enter a name for the model deployment.
- Container size — select the CPU and memory allocation or accept the defaults.
Note
If a resource group with the same name already exists,
azd provisionuses the existing group. To avoid conflicts, choose a unique environment name or delete the existing resource group first.Important
If you aren't using an MCP server, comment out or remove the following lines in the
agent.yamlfile:- name: AZURE_AI_PROJECT_TOOL_CONNECTION_ID value: <CONNECTION_ID_PLACEHOLDER>- Environment name — determines your resource group name (for example,
Provision the required Azure resources:
Note
You need Contributor access on your Azure subscription for resource provisioning.
azd provisionThis command takes about 5 minutes and creates the following resources:
Resource Purpose Cost Resource group Organizes all related resources in the same area No cost Model deployment Model used by the agent See Foundry pricing Foundry project Hosts your agent and provides AI capabilities Consumption-based; see Foundry pricing Azure Container Registry Stores your agent container images Basic tier; see ACR pricing Log Analytics Workspace Manage all log data in one place No direct cost. See Log Analytics cost Application Insights Monitors agent performance and logs Pay-as-you-go; see Azure Monitor pricing Managed identity Authenticates your agent to Azure services No cost Tip
Run
azd downwhen you finish this quickstart to delete resources and stop incurring charges.
Step 2: Test the agent locally
Before deploying, verify the agent works locally.
Start the agent locally:
azd ai agent runThis command automatically sets up the environment, installs dependencies, and starts the agent. It uses the
startupCommanddefined inazure.yamlto launch your agent.If the agent fails to start, check these common issues:
Error Solution AuthenticationErrororDefaultAzureCredentialfailureRun azd auth loginagain to refresh your session.ResourceNotFoundVerify your endpoint URLs match the values in the Foundry portal. DeploymentNotFoundCheck the deployment name in Build > Deployments. Connection refusedEnsure no other process is using port 8088. In a separate terminal, send a test message to the local agent:
azd ai agent invoke --local "What is Microsoft Foundry?"You should see a response with web search results about Microsoft Foundry.
Step 3: Deploy to Foundry Agent Service
Since you already provisioned infrastructure in Step 1, deploy your agent code to Azure:
azd deploy
The agent container is built remotely, so Docker Desktop isn't required on your machine.
Warning
Your hosted agent incurs charges while deployed. After you finish testing, complete Clean up resources to delete resources and stop charges.
When finished, the output shows a link to the Agent Playground and the endpoint for invoking the agent programmatically:
Deploying services (azd deploy)
(✓) Done: Deploying service af-agent-with-foundry-tools
- Agent playground (portal): https://ai.azure.com/nextgen/.../build/agents/af-agent-with-foundry-tools/build?version=1
- Agent endpoint: https://ai-account-<name>.services.ai.azure.com/api/projects/<project>/agents/af-agent-with-foundry-tools/versions/1
Step 1: Create a Foundry project
Use the Microsoft Foundry extension in VS Code to create a new Microsoft Foundry Project resource.
Open the Command Palette (Ctrl+Shift+P) and select Microsoft Foundry: Create Project.
Select your Azure subscription.
Create a new resource group or select an existing one.
Enter a name for the Foundry Project resource.
Once the project creation is complete, continue to the next step and deploy a model.
Step 2: Deploy a model
Use the Microsoft Foundry extension in VS Code to deploy a model to Foundry.
Open the Command Palette (Ctrl+Shift+P) and select Microsoft Foundry: Open Model Catalog.
Browse the model catalog or search for gpt-4.1 and select the Deploy button.
In the Model deployment page, select the Deploy to Microsoft Foundry button.
Once the model is deployed successfully, move on to the next step and create a Hosted Agent project
Step 3: Create a Hosted Agent project
Use the Microsoft Foundry extension in VS Code to scaffold a new hosted agent project.
Open the Command Palette (Ctrl+Shift+P) and select Microsoft Foundry: Create new Hosted Agent.
Select either the Single Agent or Multi-Agent Workflow template
Select a programming language, Python or C#.
Choose the existing gpt-4.1 model you deployed in the previous step.
Choose the folder where you want your project files to be saved.
Enter a name for the hosted agent.
A new VS Code window will launch with the new agent project folder as the active workspace.
Step 4: Install dependencies
It's recommended to use a virtual environment to isolate project dependencies:
macOS/Linux:
python -m venv .venv
source .venv/bin/activate
Windows (PowerShell):
python -m venv .venv
.\.venv\Scripts\Activate.ps1
Installing Dependencies
Install the required Python dependencies using pip:
pip install -r requirements.txt
The required packages are:
azure-ai-agentserver-agentframework- Agent Framework and AgentServer SDK
Step 5: Test the agent locally
Run and test your agent before deploying.
Option 1: Press F5 (Recommended)
Press F5 in VS Code to start debugging. Alternatively, you can use the VS Code debug menu:
- Open the Run and Debug view (Ctrl+Shift+D / Cmd+Shift+D)
- Select "Debug Local Workflow HTTP Server" from the dropdown
- Click the green Start Debugging button (or press F5)
This will:
- Start the HTTP server with debugging enabled
- Open the AI Toolkit Agent Inspector for interactive testing
- Allow you to set breakpoints and inspect the workflow
Option 2: Run in Terminal
Run as HTTP server (default):
python main.py
This will start the hosted agent locally on http://localhost:8088/.
PowerShell (Windows):
$body = @{
input = "I need a hotel in Seattle from 2025-03-15 to 2025-03-18, budget under `$200 per night"
stream = $false
} | ConvertTo-Json
Invoke-RestMethod -Uri http://localhost:8088/responses -Method Post -Body $body -ContentType "application/json"
Bash/curl (Linux/macOS):
curl -sS -H "Content-Type: application/json" -X POST http://localhost:8088/responses \
-d '{"input": "Find me hotels in Seattle for March 20-23, 2025 under $200 per night","stream":false}'
The agent will use the get_available_hotels tool to search for available hotels matching your criteria.
Step 6: Deploy to Foundry Agent Service
Deploy your agent directly from VS Code.
Open the Command Palette (Ctrl+Shift+P) and select Microsoft Foundry: Deploy Hosted Agent.
Select the CPU and Memory configuration for the Hosted Agent container.
In the dialog that appears, select the Confirm and Deploy button.
Switch to the Microsoft Foundry explorer by selecting the icon on the left. The agent appears in the Hosted Agents (Preview) tree view sidebar after deployment completes.
Verify and test your agent
After deployment completes, verify your agent is running.
Check agent status
Check the status of your agent to confirm it's running.
Select your hosted agent from the Hosted Agents (Preview) tree view.
Select a version (v1) to open the detail page.
The detail page shows the Status under the Container Details section.
Test in the playground using VS Code
Microsoft Foundry for VS Code includes an integrated Playground to chat and interact with your agent.
Select your hosted agent from the Hosted Agents (Preview) tree view.
Select a version (v1) to open the detail page.
Select the Playground option and type a message and send to test your agent.
Verify agent status
Check the status of your deployed agent:
azd ai agent show
Test the deployed agent
Send a test message to your deployed agent:
azd ai agent invoke "What is Microsoft Foundry?"
You should see a response with web search results about Microsoft Foundry. The response might take a few seconds as the agent queries external sources.
View agent logs
Monitor your agent's live logs:
azd ai agent monitor
Test in the Foundry playground
Navigate to the agent in the Foundry portal:
Open the Foundry portal and sign in with your Azure account.
Select your project from the Recent projects list, or select All projects to find it.
In the left navigation, select Build to expand the menu, then select Agents.
In the agents list, find your deployed agent (it matches the agent name from your deployment).
Select the agent name to open its details page, then select Open in playground in the top toolbar.
In the chat interface, type a test message like "What is Microsoft Foundry?" and press Enter.
Verify that the agent responds with information from web search results. The response might take a few seconds as the agent queries external sources.
Tip
If the playground doesn't load or the agent doesn't respond, verify the agent status is Started using the Container Details page described above.
Clean up resources
To avoid charges, delete the resources when you're finished.
Warning
This command permanently deletes all Azure resources in the resource group, including the Foundry project, model deployments, Container Registry, Application Insights, and your hosted agent. This action can't be undone. If you're using an existing resource group that contains other resources, use caution — azd down removes everything in the group, not just resources created by this quickstart.
To preview what will be deleted before confirming:
azd down --preview
When you're ready to delete, run:
azd down
The cleanup process takes approximately 2-5 minutes.
Warning
Deleting resources permanently removes all Azure resources created in this quickstart, including the Foundry project, Container Registry, Application Insights, and your hosted agent. This action can't be undone.
To delete your resources, open the Azure portal, navigate to your resource group, and delete it along with all contained resources.
To verify resources were deleted, open the Azure portal, go to your resource group, and confirm the resources no longer appear. If the resource group is empty, you can delete it as well.
Troubleshooting
If you encounter issues, try these solutions for common problems:
| Issue | Solution |
|---|---|
SubscriptionNotRegistered error |
Register providers: az provider register --namespace Microsoft.CognitiveServices |
AuthorizationFailed during provisioning |
Request Contributor role on your subscription or resource group. |
| Agent doesn't start locally | Verify environment variables are set and run az login to refresh credentials. |
AcrPullUnauthorized error |
Grant AcrPull role to the project's managed identity on the container registry. |
| Issue | Solution |
|---|---|
azd ai agent init fails |
Run azd version to verify version 1.23.0+. Update with winget upgrade Microsoft.Azd (Windows) or brew upgrade azd (macOS). Verify the agent extension is installed with azd ext list. |
| Model not found in catalog | Fork the sample agent.yaml and change the model deployment to one available in your subscription like gpt-4.1. Then remove the AZURE_LOCATION value in the .azure/<environment name>/.env file. Re-run the azd ai agent init command with your forked agent.yaml file. |
View the container logs of your agent
You can check the console and system logs of the container to troubleshoot issues.
Select your hosted agent from the Hosted Agents (Preview) tree view.
Select a version (v1) to open the detail page.
Select the Logs button on the right to open the log viewer.
| Issue | Solution |
|---|---|
| Extension not found | Install the Microsoft Foundry for VS Code extension from the VS Code Marketplace. |
What you learned
In this quickstart, you:
- Set up a hosted agent sample with Foundry tools (web search and MCP)
- Tested the agent locally
- Deployed to Foundry Agent Service
- Verified your agent in the Foundry playground
Next steps
Now that you've deployed your first hosted agent, learn how to:
Customize your agent with additional capabilities:
- Connect MCP tools to extend agent functionality
- Use function calling to integrate custom logic
- Add file search to search your documents
- Enable code interpreter to run Python code
You can see a full list of available tools in the tool catalog article.