This repository demonstrates how to build an Agent with the Azure AI Agent Service.
Our agent uses the Bing Search API to fetch news articles and stores the results in Azure Blob Storage with a timestamped filename.
The tutorial also guides you through setting up Azure AI Foundry, deploying a model (e.g., GPT-4o-mini), and testing agents in the Agent Playground.
Note: This tutorial has been tested with Python 3.11.5 and is configured for the sweden_central region.
- Setup and Prerequisites
- Azure AI Foundry and Model Deployment
- Azure Resources Setup
- Repository Setup and Environment
- Running and Testing the Code
- Extending Your Agent with Additional Tools
- Security Considerations
- Further Ideas and Next Steps
-
Python Installation:
Install Python 3.11.5 on your machine. -
Azure CLI:
Ensure you have the Azure CLI installed. Log in with:az login --tenant <your-tenant-id>
You can check if you are logged into by executing
az account list --output table
-
Git:
Make sure Git is installed to clone the repository.
-
Azure AI Foundry Setup:
- Login to Azure Portal and set up Azure AI Foundry with your Hub and Project.
- Deploy at least one model (e.g., GPT-4o-mini). If you use a different model, adjust the name accordingly.
- Use sweden_central for testing.
- Once deployed, play in the playground by chatting with your model and executing agents in the Agent Playground.
-
Deploying a Model:
- In Azure AI Foundry, navigate to your workspace and create a hub and a project.
- Deploy your model (e.g., GPT-4o-mini) with Global Standard following the deployment wizard.
- Verify that the model is active and available for testing in the playground.
Before turning to the code, ensure you have the following Azure resources ready:
-
Bing Search Resource:
- Create a Bing Search resource in Azure.
- Obtain the API key from the resource and copy it.
-
Azure Blob Storage:
- Create a new Azure Storage account (Data Lake Gen2). Do not use the one that comes with Azure AI Foundry.
- Copy the connection string from your Blob Storage account.
- Azure AI Project Connection:
- Obtain your Azure AI Project connection string from Azure AI Foundry.
- Copy this connection string for later use in the code.
-
Clone the Repository:
git clone https://github.com/yourusername/azure-ai-agent-tutorial.git cd azure-ai-agent-tutorial -
Create a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment Variables:
Create a.envfile in the repository root with the following values (replace placeholders with your actual values):BING_API_KEY=your_bing_api_key_here PROJECT_CONNECTION_STRING=your_project_connection_string_here AZURE_STORAGE_CONNECTION_STRING=your_storage_connection_string_here
-
Run the Code:
Execute the Python script to run the agent and store news data in Azure Blob Storage:python your_script.py
-
Verify Blob Storage:
After running the code, verify that a new file with a timestamp (e.g.,news_YYYYMMDD_HHMMSS.json) is created in your designated Blob Storage container. -
Agent Playground:
Once your agent is running in Azure AI Foundry, interact with it in the Agent Playground by sending messages and executing available tools.
This tutorial is a starting point. Consider adding additional tools to extend your agent’s capabilities. For example:
- Social Media Integration:
Wrap APIs to fetch social media information. - Email Functionality:
Integrate with an email service to send notifications. - Document Intelligence:
Use Azure Document Intelligence to read and process PDFs. - SharePoint Search:
Build a tool to search through SharePoint documents. - Code Interpreter:
Integrate a code interpreter for data analysis and visualization. - SQL Database Interaction:
Connect to a SQL database to execute queries and retrieve data.
Each tool should be a narrow wrapper around a specific API. This design reduces complexity and improves performance.
- Action Permissions:
Ensure that your agent’s actions do not unintentionally expose or modify sensitive data. - API Wrappers:
Design tools with the principle of least privilege in mind. - Risk Management:
Agents may be autonomous or require human approval when handling challenging cases. Evaluate the security implications of automated actions, especially those affecting customer data.
- Autonomous vs. Interactive Agents:
Agents can either be fully autonomous, interact with users, or operate with human oversight when necessary. - Performance Tuning:
The performance of your agent is heavily influenced by how you design its tools. Narrow, purpose-built tools can reduce complexity. - Expand Use Cases:
Consider expanding your agent’s capabilities with more integrations, such as IoT data processing or advanced data analytics.
Happy coding and experimenting with your Azure AI Agent!


