This repository contains a starter template for building an Microsoft Foundry that hosts AI agents using the Microsoft Foundry Hosted Agent Service.
Clone this repository to your local machine using the following command:
git clone https://github.com/hatasaki/hosted-agent-workshop.git
cd hosted-agent-workshop- Install azd
- Windows:
winget install microsoft.azd - Linux:
curl -fsSL https://aka.ms/install-azd.sh | bash - MacOS:
brew tap azure/azd && brew install azd
- Windows:
-
Create new directory and navigate into it:
mkdir my-hosted-agent cd my-hosted-agent -
Bring down the template code:
azd init -t https://github.com/Azure-Samples/azd-ai-starter-basic
- input your unique project name when prompted. Ex.
<username>-hosted-agent
This will perform a git clone
- input your unique project name when prompted. Ex.
-
Sign into your Azure account:
azd auth login
-
Download a sample agent definition:
azd ai agent init -m ../msft-docs-agent/agent.yaml
- install agent extension if prompted.
- select your subscription when prompted.
- select supported region. (List of supported regions)
- select
GlobalStandardfor mode SKU. - deployment name of model cab be left as default. (gpt-4o-mini)
- container memory, CPU, and replicas can be left as default. (2GB, 1 CPU, 1 min replica and 3 max replicas)
-
Provision Microsoft Foundry and the sample agent:
azd up
-
Open Microsoft Foundry portal and test the agent
- Note: azd up creates new Microsoft Foundry account. Navigate to your Microsoft Foundry (should be listed under resource group
rg-<username>-hosted-agentyou specified in step 1).
-
Deleting Resources: To delete all associated resources and shut down the application, execute the following command:
azd down
Please note that this process may take up to 20 minutes to complete.
-
Install the Azure CLI
- Windows:
winget install --id Microsoft.AzureCLI - Linux:
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash - MacOS:
brew update && brew install azure-cli
- Windows:
-
You have already provisioned a Foundry project and deployed a model (for example by running
azd up). -
Your signed-in user has Azure RBAC access to the Foundry project (at minimum the
Azure AI Userrole on the project). -
Python 3.10+ is installed. Using a virtual environment (such as
venv) is strongly recommended.- Example (Linux/MacOS):
python3 -m venv .venv source .venv/bin/activate - Example (Windows PowerShell):
python3 -m venv .venv .\.venv\Scripts\Activate.ps1
- Example (Linux/MacOS):
-
In a terminal, set the following environment variables using values from the Foundry portal (https://ai.azure.com):
AZURE_AI_PROJECT_ENDPOINTAZURE_AI_MODEL_DEPLOYMENT_NAME
Example (Linux/MacOS):
export AZURE_AI_PROJECT_ENDPOINT="<your-project-endpoint>" export AZURE_AI_MODEL_DEPLOYMENT_NAME="<your-model-deployment-name>"
Example (Windows PowerShell):
$env:AZURE_AI_PROJECT_ENDPOINT = "<your-project-endpoint>" $env:AZURE_AI_MODEL_DEPLOYMENT_NAME = "<your-model-deployment-name>"
-
Sign in with Azure CLI and ensure you are using the tenant and subscription that contain your Foundry project:
az login
If needed, select a subscription:
az account set --subscription "<subscription-id>"
-
Install dependencies:
cd msft-docs-agent python3 -m pip install -r requirements.txt -
Run the agent locally:
python3 main.py
This starts a local server (see
sample.httpfor the request format). -
Test the agent:
- Using VS Code REST Client: open
sample.httpand send the request. - Or with
curl:curl -sS http://0.0.0.0:8088/responses \ -H 'Content-Type: application/json' \ -d '{"input":"Explain overview of Microsoft Foundry in Japanese?"}'
- Using VS Code REST Client: open