本案示範如何使用 Azure AI Agent 執行各種 AI 任務,包括基礎、中階、進階,以及與 MCP 整合的應用,並提供 Jupyter Notebook 及 Python 範例。
This repository demonstrates how to use Azure AI Agent for various AI tasks, including basic, intermediate, advanced, and MCP-integrated applications. It provides examples in both Jupyter Notebooks and Python scripts. Please see the user guide at the bottom.
下載本專案:
git clone https://github.com/ownway22/azure-ai-agent.git
進入專案資料夾:
cd azure-ai-agent
- 建立虛擬環境:
python -m venv .venv
- 啟用虛擬環境:
- Windows PowerShell 指令:
.venv\Scripts\Activate
- CMD 指令:
.venv\Scripts\activate.bat
- macOS/Linux 指令:
source .venv/bin/activate
- Windows PowerShell 指令:
- 安裝所需套件:
pip install -r requirements.txt
- 快速建立與安裝虛擬環境:
uv sync
- 啟用虛擬環境:
- Windows PowerShell 指令:
.venv\Scripts\Activate
- CMD 指令:
.venv\Scripts\activate.bat
- macOS/Linux 指令:
source .venv/bin/activate
- Windows PowerShell 指令:
請到 Azure AI Foundry Project 複製您 AI project 中相關的環境變數,並將其填入 .env
檔案中。
PROJECT_ENDPOINT="https://*****.services.ai.azure.com/api/projects/*****"
API_KEY="86CBilkUxBKM3s8VYa7blR40bgIkDGhYnDys*****"
MODEL_DEPLOYMENT_NAME="gpt-4o"
AZURE_OPENAI_ENDPOINT="https://openai-ai-workshop.openai.azure.com/"
AZURE_OPENAI_API_KEY="AYj128C1av4Y9MLl01p5k6tIRY6pYRWOPjH*****"
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME="gpt-4o"
AZURE_OPENAI_API_VERSION="2025-01-01-preview"
AZURE_BING_CONNECTION_ID="*****"
在執行範例前,請先安裝並登入 Azure CLI:
- 若尚未安裝 Azure CLI,請參考官方說明:如何安裝 Azure CLI
- 登入 Azure 帳號:
- Windows (PowerShell 或 CMD):
az login
- macOS / Linux (Terminal):
az login
- Windows (PowerShell 或 CMD):
執行後會自動開啟瀏覽器進行帳號驗證,登入成功即可繼續後續步驟。
依序執行以下檔案:
01_ai-agent-basic.ipynb
02_ai-agent-intermediate.py
03_ai-agent-advanced.py
04_ai-agent-mcp-basic.ipynb
05_ai-agent-mcp-intermediate.py
06_ai-agent-mcp-advanced.py
pip install notebook
jupyter notebook
然後在瀏覽器中開啟上述的 .ipynb
檔案。
python 02_ai-agent-intermediate.py
python 03_ai-agent-advanced.py
python 05_ai-agent-mcp-intermediate.py
python 06_ai-agent-mcp-advanced.py
當所有程式碼執行完成後,您可以在 Azure AI Foundry portal 的 agent 清單中看到如下畫面:
該畫面顯示已成功建立的 agent 清單,包含其名稱、ID、模型類型、建立時間等資訊。
This repository demonstrates how to use Azure AI Agent for various AI tasks, including basic, intermediate, advanced, and MCP-integrated applications. It provides examples in both Jupyter Notebooks and Python scripts.
Download the repository:
git clone https://github.com/ownway22/azure-ai-agent.git
Navigate to the project folder:
cd azure-ai-agent
- Create a virtual environment:
python -m venv .venv
- Activate the virtual environment:
- Windows PowerShell:
.venv\Scripts\Activate
- CMD:
.venv\Scripts\activate.bat
- macOS/Linux:
source .venv/bin/activate
- Windows PowerShell:
- Install required packages:
pip install -r requirements.txt
- Quickly set up and install the virtual environment:
uv sync
- Activate the virtual environment:
- Windows PowerShell:
.venv\Scripts\Activate
- CMD:
.venv\Scripts\activate.bat
- macOS/Linux:
source .venv/bin/activate
- Windows PowerShell:
Go to the Azure AI Foundry Project to copy the relevant environment variables for your AI project and add them to the .env
file:
PROJECT_ENDPOINT="https://*****.services.ai.azure.com/api/projects/*****"
API_KEY="86CBilkUxBKM3s8VYa7blR40bgIkDGhYnDys*****"
MODEL_DEPLOYMENT_NAME="gpt-4o"
AZURE_OPENAI_ENDPOINT="https://openai-ai-workshop.openai.azure.com/"
AZURE_OPENAI_API_KEY="AYj128C1av4Y9MLl01p5k6tIRY6pYRWOPjH*****"
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME="gpt-4o"
AZURE_OPENAI_API_VERSION="2025-01-01-preview"
AZURE_BING_CONNECTION_ID="*****"
Before running the examples, install and log in to the Azure CLI:
- If you haven't installed the Azure CLI yet, follow the official guide: Install the Azure CLI
- Log in to your Azure account:
- Windows (PowerShell or CMD):
az login
- macOS / Linux (Terminal):
az login
- Windows (PowerShell or CMD):
This will automatically open a browser for account verification. Once logged in, you can proceed to the next steps.
Execute the following files in order:
01_ai-agent-basic.ipynb
02_ai-agent-intermediate.py
03_ai-agent-advanced.py
04_ai-agent-mcp-basic.ipynb
05_ai-agent-mcp-intermediate.py
06_ai-agent-mcp-advanced.py
pip install notebook
jupyter notebook
Then open the .ipynb
files in your browser.
python 02_ai-agent-intermediate.py
python 03_ai-agent-advanced.py
python 05_ai-agent-mcp-intermediate.py
python 06_ai-agent-mcp-advanced.py
After executing all the code, you can see the agent list in the Azure AI Foundry portal as shown below:
This screen displays the list of successfully created agents, including their names, IDs, model types, creation times, and other information.
- Quickstart - Create a new Azure AI Foundry Agent Service project (2025/07)
- Azure AI Projects client library for Python - version 1.0.0b12 (2025/06)
- Azure AI Agents client library for Python - version 1.0.2 (2025/07)
- Announcing Model Context Protocol Support (preview) in Azure AI Foundry Agent Service | Azure AI Foundry Blog (2025/06)
- Code Samples for the Model Context Protocol Tool (Preview) - Azure AI Foundry | Microsoft Learn (2025/07)
- Create a Remote MCP server for your GitHub repository
- QuickStart to MCP Tools Development with Azure AI Foundry SDK (2025/07)
- AI-Foundry-Agent-MCP by Christian Coello (2025/07)