This repository demonstrates how to deploy a Hosted Agent on Microsoft Foundry using the Azure Developer CLI (azd) AI Agent extension.
More information on my blog.
- Azure Developer CLI (azd) (version 1.21.3 or later)
- Azure CLI
- Azure AI Agent extension for azd (installed automatically on first run, or manually via
azd extension install azure.ai.agents)
This repository includes a dev container configuration. To use it:
- Open this repository in VS Code
- When prompted, click "Reopen in Container" (or use
Dev Containers: Reopen in Containerfrom the command palette) - The container will automatically install all required tools (Azure CLI, azd, Docker)
az login
azd auth login
azd upThe azd up command orchestrates the complete deployment workflow:
- Provisions the Azure infrastructure (Microsoft Foundry account, project, Container Registry)
- Builds the container image and pushes it to Azure Container Registry
- Deploys the agent to Microsoft Foundry
- Starts the hosted agent container
When complete, the output displays:
- Microsoft Foundry project endpoint
- Agent name and version
- Direct link to the agent playground in the Microsoft Foundry portal
# Only provision infrastructure
azd provision
# Only deploy the agent (after code changes)
azd deploy
# View deployment outputs
azd env get-values
# Delete all resources
azd downUse the link provided at the end of the deployment (🌐 View in portal) to access the playground and chat with your agent:
├── agent/
│ ├── agent.yaml # Agent definition and metadata
│ ├── Dockerfile # Container image definition
│ ├── hostedAgent.py # Agent implementation using Microsoft Agent Framework
│ └── pyproject.toml # Python dependencies
├── infra/
│ ├── main.bicep # Azure infrastructure as code
│ └── main.parameters.json
└── azure.yaml # Azure Developer CLI configuration
This project uses a declarative approach with the Azure Developer CLI AI Agent extension:
- Agent Definition (
agent/agent.yaml): Defines the agent's metadata, instructions, and container configuration - Service Configuration (
azure.yaml): Declares the agent as a service with container resources, scaling, and environment variables - Infrastructure (
infra/main.bicep): Provisions Microsoft Foundry account, project, Container Registry, and RBAC permissions - Automatic Deployment:
azd uphandles the entire lifecycle from infrastructure to running agent
The agent uses:
- Ollama running locally in the container with the Llama 3.2 3B model
- Microsoft Agent Framework for agent runtime capabilities
- Azure Container Registry for image storage
- Microsoft Foundry Hosted Agents for scalable, managed hosting
azd supports multiple named environments for different deployment stages:
# Create a new environment (e.g., production)
azd env new my-agent-prod
# Switch between environments
azd env select my-agent-dev
azd env select my-agent-prod
# Deploy to the selected environment
azd up