This sample demonstrates the construction of a hosted agent workflow using the Agent Framework. It features two agents—a "Writer" and a "Reviewer"—integrated in a streamlined, one-way workflow to illustrate best practices for agent orchestration and interaction.
| File | Description |
|---|---|
workflow_core.py |
Builds the workflow, creates agents, and manages credentials. |
interactive.py |
Runs the workflow in local/interactive mode. |
container.py |
Starts the workflow in container/server mode. |
.env |
Stores environment configuration for Microsoft Foundry integration. |
- Python 3.10 or higher.
- A Microsoft Foundry Project and a model deployment.
-
Creating virtual environments
python -m venv .venv
-
Activate the virtual environment
# PowerShell ./.venv/Scripts/Activate.ps1 # Windows cmd .venv\Scripts\activate.bat # Unix/MacOS source .venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Create or update the
.envfile with your Microsoft Foundry configuration# Your Microsoft Foundry project endpoint AZURE_AI_PROJECT_ENDPOINT="your-foundry-project-endpoint" # Your model deployment name in Microsoft Foundry AZURE_AI_MODEL_DEPLOYMENT_NAME="your-model-deployment-name"
Important: Never commit the
.envfile to version control. Add it to your.gitignorefile.
This sample authenticates using DefaultAzureCredential. Ensure your development environment is configured to provide credentials via one of the supported sources, for example:
- Azure CLI (
az login) - Visual Studio Code account sign-in
- Visual Studio account sign-in
- Environment variables for a service principal (AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET)
Confirm authentication locally (for example, az account show or az account get-access-token) before running the sample.
Run the hosted agent directly for development and testing:
python interactive.pyTo run the agent in container mode:
- Open the Visual Studio Code Command Palette and execute the
Microsoft Foundry: Open Container Agent Playground Locallycommand. - Execute
container.pyto initialize the containerized hosted agent. - Submit a request to the agent through the playground interface. For example, you may enter a prompt such as: "Create a slogan for a new electric SUV that is affordable and fun to drive."
- Review the agent's response in the playground interface.
Note: Open the local playground before starting the container agent to ensure the visualization functions correctly.
To deploy the hosted agent:
- Open the Visual Studio Code Command Palette and run the
Microsoft Foundry: Deploy Hosted Agentcommand. - Configure the deployment settings by selecting your target workspace, specifying the container agent file (
container.py), and defining any additional deployment parameters as needed. - Upon successful deployment, the hosted agent will appear in the
Hosted Agents (Preview)section of the Microsoft Foundry extension tree view. - Select the deployed agent to access detailed information and test functionality using the integrated playground interface.
This sample requires the Microsoft Foundry Project to authenticate using a Managed Identity when running remotely in Azure. Grant the project's managed identity the required permissions by assigning the built-in Azure AI User role.
To configure the Managed Identity:
- In the Azure Portal, open the Foundry Project.
- Select "Access control (IAM)" from the left-hand menu.
- Click "Add" and choose "Add role assignment".
- In the role selection, search for and select "Azure AI User", then click "Next".
- For "Assign access to", choose "Managed identity".
- Click "Select members", locate the managed identity associated with your Foundry Project (you can search by the project name), then click "Select".
- Click "Review + assign" to complete the assignment.
- Allow a few minutes for the role assignment to propagate before running the application.