--- title: 03-Low-Code Agent實作演練 --- # Day2 - Low-Code Agent 實作演練 --- 參考資料: + [Download the latest Python for Windows](https://www.python.org/downloads/) + [Creation of virtual environments in Python](https://docs.python.org/3/library/venv.html) + [Azure AI Foundry for VS Code extension](https://learn.microsoft.com/en-us/azure/ai-foundry/how-to/develop/get-started-projects-vs-code) + [How to use the Deep Research tool](https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/deep-research-samples?pivots=python) + [Time MCP Server](https://github.com/modelcontextprotocol/servers/tree/main/src/time) + [Bazi MCP (八字 MCP)](https://github.com/cantian-ai/bazi-mcp) + [mcp-proxy](https://github.com/sparfenyuk/mcp-proxy) + [Create a web app in Azure](https://learn.microsoft.com/en-us/azure/app-service/quickstart-python?tabs=flask%2Cwindows%2Cazure-portal%2Cazure-cli-deploy%2Cdeploy-instructions-azportal%2Cterminal-bash%2Cdeploy-instructions-zip-azcli#create-a-web-app-in-azure) + [Deep Research in Azure AI Foundry Sgent Service](https://azure.microsoft.com/en-us/blog/introducing-deep-research-in-azure-ai-foundry-agent-service/) + [Announcing MCP Support in Azure AI Foundry Agent Service](https://devblogs.microsoft.com/foundry/announcing-model-context-protocol-support-preview-in-azure-ai-foundry-agent-service/) + [Announcing the Browser Automation Tool in Azure AI Foundry Agent Service](https://devblogs.microsoft.com/foundry/announcing-the-browser-automation-tool-preview-in-azure-ai-foundry-agent-service/) --- ## 一、前置需求 ### 1. 己完成下列本機環境安裝 #### Python環境 + 本機Python環境 3.10以上版本 + **驗證安裝**: ```shell python ``` #### Vistual Studio Code環境 + 本機Vistual Studio Code + 安裝以下Extension - Azure Tool - Python - Jupyter - Azure AI Foundry #### Azure CLI + 安裝[AZ Cli](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&pivots=msi) + **驗證安裝**: ```shell az login ``` #### Node.js - **版本**: 建議使用最新的 LTS 版本,如 v20.x.x - **下載地址**: [nodejs.org](https://nodejs.org/) - **驗證安裝**: ```bash node --version npm --version ``` ### 2. Download Code & Create Python venv #### **Python Sample Code** - 請下載[Sample Code](https://1drv.ms/u/c/8302862bf709a02b/EQG0QS_-jf5Mk2GCDtl0V-MBlvFXbZLHBUBDD7wbsRkwcg?e=OyxgIV) #### **Create a Virtual Environment** 切換到Sample Code資料夾 ```bash cd "您的專案資料夾路徑" ``` 建立python venv ```bash python -m venv .venv ``` - **Activate venv** ```bash # For Windows .\.venv\Scripts\activate ``` - **Install Dependency** ```bash # For Windows pip install -r requirements.txt ``` - **Quick Test** + 以VS Code開專案檔 .env填寫 **PROJECT_ENDPOINT**: 由AI Foundry overview頁面取得 ![image](https://hackmd.io/_uploads/S1xAkUYFgl.png) + 存檔後,重新啟動VS Code 重新讀取env資訊 + 執行 `00-test-ai-agent.ipynb` 確認是否可正常執行無誤 ![image](https://hackmd.io/_uploads/BJzWVz0hlx.png) ### 3. 部署o3-deep-research Model + 登入AI Foundry Portal + 點擊 `Models + enpoints` ![image](https://hackmd.io/_uploads/HkFw6VFKeg.png) + 點擊 `+ Deploy model` + 點擊 `Deploy base model` ![image](https://hackmd.io/_uploads/Syjw0NFYxx.png) + search `o3-deep-research` + 選擇後點擊 `Confirm` ![image](https://hackmd.io/_uploads/Sku2ySFtgx.png) + Deploy ![image](https://hackmd.io/_uploads/HJS7xrtFlx.png) ### 4. Vistual Code Language: 請將Language設定為English + Windows OS: Press Ctrl+Shift+P to open the Command Palette. + Type: `Configure Display Language` ![image](https://hackmd.io/_uploads/By0CTOYKxl.png) + 選擇 `English` ![image](https://hackmd.io/_uploads/Hkfp0uYtle.png) --- ## 二、Research Agent ### 1. Connect Resource - Grounding with Bing Search + Management center ![image](https://hackmd.io/_uploads/HyJfbLKYll.png) + `Connected resources` ➜ `+ New connection` ![image](https://hackmd.io/_uploads/r1cN-UYtex.png) + Grounding with Bing Search ![image](https://hackmd.io/_uploads/BJ26-UFYle.png) + Add connection ![image](https://hackmd.io/_uploads/BJ_7XUFtge.png) + Close ![image](https://hackmd.io/_uploads/HklvmUttex.png) ### 2. 必要env資訊 + **PROJECT_ENDPOINT**:由AI Foundry overview頁面取得 ![image](https://hackmd.io/_uploads/S1xAkUYFgl.png) + **AZURE_OPENAI_DEPLOYMENT**:`gpt-4.1` 或 `gpt-4o` + **BING_RESOURCE_NAME**:您的grouding bign search名稱 + **DEEP_RESEARCH_MODEL_DEPLOYMENT_NAME**:`o3-deep-research` + Save後,請重新啟動 Visual Studio Code,以讓env資訊生效 ### 3. Run Research Agent + 開啟 **01-research agent.ipynb** ![image](https://hackmd.io/_uploads/S1ak0LFtgg.png) + 可在**content**罝換任何您想進行的深度學習報告,範例: ```bash 請提供 2025 Gartner Magic Quadrant for Cloud-Native Application Platforms 的研究報告 ``` ![image](https://hackmd.io/_uploads/B1tyJvYYll.png) + Deep Research Agent將結果寫入**research_summary.md** ![image](https://hackmd.io/_uploads/ryrqkvFYle.png) + 於Following Question回覆Deep Research Agent的確認需求,例如: ```bash 請專注於具體領導廠商與挑戰者的名單與分析 ``` ⚠️ 請注意:若回覆內容與問題不符,可能會導致 Research Agent 無法正確執行任務! ![image](https://hackmd.io/_uploads/ryGmxPYKxx.png) + 於Following Question回覆 Research Agent 的確認問題, 例如: ```bash 只需領導者(Leaders)和挑戰者(Challengers) ``` + 於Following Question回覆 Research Agent 的確認問題, 例如: ```bash 重點整理並分析各入選廠商的優勢、技術特色、和存在挑戰即可 ``` + 當 Research Agent 回覆 `Starting deep research...`,表示深度研究報告已開始執行,預估所需時間約為 5 至 30 分鐘,視研究內容的複雜度而定 ![image](https://hackmd.io/_uploads/B1rkfvtFll.png) + 以2025 Gartner Magic Quadrant 研究報告為例,實際執行時間為11分14秒 內容存放至`research_summary.md` ![image](https://hackmd.io/_uploads/HJ1-QYVaex.png) ## 三、MCP Inpsector : Test Your Server ### 1. 安裝MCP函式庫 安裝必要的 Python 函式庫: ```bash pip install mcp[cli] pip install mcp-server-time ``` ### 2. 啟動 MCP Inspector cmd mode執行npx命令 ```bash npx @modelcontextprotocol/inspector ``` ![image](https://hackmd.io/_uploads/Syk1LFHKlx.png) ### 3. 測試 MCP-Server-Time + Transport Type: **STDIO** + Command: 指定本機 Python 絕對路徑。可使用 `where python` 查詢所有已安裝的 Python 路徑 + Argument: `-m mcp_server_time` + Connect ![image](https://hackmd.io/_uploads/r1jSqtBtee.png) + Tools ➜ List Tools ![image](https://hackmd.io/_uploads/HJGJ3YSYgx.png) + 測試 **get_current_time** + timezone: America/New_York + Run Tool ![image](https://hackmd.io/_uploads/SkJd2FSFgx.png) + Tool Result ![image](https://hackmd.io/_uploads/BJ5OatSFll.png) ### 4. Find More MCP Server - MCP.so + 登入 https://mcp.so/ ![image](https://hackmd.io/_uploads/ry95g9SFxx.png) + Bazi MCP [Server Config](https://github.com/cantian-ai/bazi-mcp) ![image](https://hackmd.io/_uploads/HJf4b94pel.png) + Airbnb MCP Server [Server Config](https://github.com/MCP-Mirror/openbnb-org_mcp-server-airbnb) ![image](https://hackmd.io/_uploads/HJs--9ETxl.png) ### 5. MCP Inpsector : Test Bazi MCP + Transport Type: **STDIO** + Command: 指定本機 npx 絕對路徑。可使用 `where npx` 查詢所有已安裝的 npx 路徑 + Argument: `bazi-mcp` + Connect ![image](https://hackmd.io/_uploads/HyQVmcHKgx.png) ### 6. MCP Inpsector : Test Airbnb MCP + Transport Type: **STDIO** + Command: 指定本機 npx 絕對路徑。可使用 `where npx` 查詢所有已安裝的 npx 路徑 + Argument: `@openbnb/mcp-server-airbnb` + Connect ![image](https://hackmd.io/_uploads/ryaXIqBYxg.png) --- ## 四、MCP Proxy : SSE to STDIO ### 🧩 mcp-proxy 是為了解決什麼問題? mcp-proxy 是一個 橋接工具,用來在不同的 MCP 傳輸協定(如 stdio、SSE、Streamable HTTP)之間轉換,讓不支援某些協定的客戶端或伺服器也能互通。 - 解決許多 MCP server 只支援本地 stdio、無法直接遠端連線的問題 - 透過 proxy 包裝,使之能以 SSE 形式被遠端 client 使用 ### 1. SSE to STDIO 的作法 + 啟動一個 proxy server - 外部:對外開放 SSE server (HTTP port),接受遠端請求 - 內部:啟動本地 stdio MCP server,處理實際邏輯 - Proxy 負責將 SSE 請求轉送給 stdio server,再把回應轉回 SSE ### 2. 安裝mcp-proxy函式庫 安裝必要的 Python 函式庫: ```bash pip install mcp-proxy ``` ### 3. 本機mcp proxy 模擬SSE to STDIO + 以 @openbnb/mcp-server-airbnb 為例 💡 mcp-proxy does not set CORS headers by default; you need to explicitly specify them using --allow-origin. ```bash mcp-proxy --port=8080 --host=0.0.0.0 --allow-origin "*" -- npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt ``` + sse endpoint應為 `http://localhost:8080/sse` ![image](https://hackmd.io/_uploads/B1xylirtle.png) ### 4. MCP Inpsector : 測試mcp-proxy sse + Transport Type: **SSE** + URL: `http://localhost:8080/sse` + Connection Type: Direct + Authenticaiton: Use the toggle to **disable** headers + Connect ![image](https://hackmd.io/_uploads/ryaXIqBYxg.png) + 成功模擬sse連線 ![image](https://hackmd.io/_uploads/Byz8MorKxl.png) ### 5. Multiple Named MCP Server + **啟動方式**:透過 **configuration file** 一次啟動多個 MCP Server。 ```bash { "mcpServers": { "time": { "enabled": true, "timeout": 100, "command": "python", "args": [ "-m", "mcp_server_time" ], "transportType": "stdio" }, "airbnb": { "enabled": true, "timeout": 100, "command": "npx", "args": [ "-y", "@openbnb/mcp-server-airbnb", "--ignore-robots-txt" ], "transportType": "stdio" }, "Bazi": { "enabled": true, "timeout": 100, "command": "npx", "args": [ "bazi-mcp" ], "transportType": "stdio" } } } ``` + **範例指令** ```bash mcp-proxy --port=8080 --host=0.0.0.0 --allow-origin "*" --named-server-config ./servers.json ``` + **SSE Endpoint 規則:** 每個 named server 會對應一個獨立的 SSE endpoint,格式如下: `http://localhost:8080/servers/<server_name>/sse` --- ## 五、Web App Service : Host MCP Server ### 1. Create Web Services + Azure Portal search bar 輸入 **App Services** ![image](https://hackmd.io/_uploads/Byug6-IKxx.png) + Create **+ Web App** ![image](https://hackmd.io/_uploads/BkoU6b8Kgx.png) + Resource Group: 請選擇您的resource group + Name: 輸入可識別的名稱 + Publish: `Code` + Runtime Stack: `Python 3.11` + Operation System: `Linux` + Region: 選擇同一個Region + Pricing Plan: `Free F1` (每個 Azure 訂閱僅能使用一個 Free F1 免費方案。在 workshop 活動期間,建議大家共用同一個 Web App,以節省資源。) + Review + Create ![image](https://hackmd.io/_uploads/HJ1tJMLKxx.png) + Create ![image](https://hackmd.io/_uploads/B1CgWf8Flg.png) 💡 If you got the quota issue, please file a support request under the category **Service and Subscription Limits (Quotas)** and select **Function or Web App (Windows and Linux)**. ### 2. Deploy to Web Services + 下載 [mcp-proxy](https://1drv.ms/u/c/8302862bf709a02b/EVbnFwhREDVBmSdENX4V7BQBofalVMtxANGX-hW7Xs0knQ?e=SSAuzK) web app專案 + 以Visual Studio Code開啟專案 + 在 `azure`資料夾按右鍵,點選**Deploy to web app...** ![image](https://hackmd.io/_uploads/S1L00JwKeg.png) + 選擇您的subscription名稱 ![image](https://hackmd.io/_uploads/ByG51gwtxg.png) + 選擇您剛建立的web app ![image](https://hackmd.io/_uploads/SkVaylvYxl.png) + Deploy ![image](https://hackmd.io/_uploads/SyIgxxwFeg.png) + Deploy to web app Succeeded ![image](https://hackmd.io/_uploads/rkak-ePtel.png) ### 3. 設定Startup Command + 在 Azure Portal找到剛建立的Web App + 點選 `Settings` ➜ `Configuration` ![image](https://hackmd.io/_uploads/Hy_1DxvFxl.png) + 在Startup command 輸入 ```bash cd /home/site/wwwroot/ && pip install -r requirements.txt && bash startup.sh ``` + Save ➜ Continue ![image](https://hackmd.io/_uploads/BJBQYgPFxg.png) + 點選 `Overview` 回到主畫面 + Restart ➜ Yes + 靜候3-5分鐘,web app將安裝requirements.txt並啟動mcp server ![image](https://hackmd.io/_uploads/rkfOFevYxl.png) + 點選 `Log stream` 可以看到安裝進度 + 出現類似字樣,即表示mcp server已啟動 ```bash 2025-08-23T08:22:34.8524046Z [I 2025-08-23 08:22:34,851.851 mcp_proxy.mcp_server] Serving MCP Servers via SSE: 2025-08-23T08:22:34.8524103Z [I 2025-08-23 08:22:34,851.851 mcp_proxy.mcp_server] - http://0.0.0.0:8000/servers/time/sse 2025-08-23T08:22:34.8524143Z [I 2025-08-23 08:22:34,851.851 mcp_proxy.mcp_server] - http://0.0.0.0:8000/servers/airbnb/sse 2025-08-23T08:22:34.8524584Z [I 2025-08-23 08:22:34,851.851 mcp_proxy.mcp_server] - http://0.0.0.0:8000/servers/Bazi/sse 2025-08-23T08:22:34.891232Z INFO: Started server process [2000] ![image](https://hackmd.io/_uploads/BkRDolwYlg.png) ``` ![image](https://hackmd.io/_uploads/r1U-2lwKlx.png) ### 4. Test the Web Services via MCP Inspector + 確認 Web App的Default Domain 的url + SSE Endpoint + Time : `https://<default domain>/servers/time/sse` + AirBnb: `https://<default domain>/servers/airbnb/sse` + Bazi: `https://<default domain>/servers/Bazi/sse` ![image](https://hackmd.io/_uploads/BJJUTxDKel.png) + 以sse測試Time ![image](https://hackmd.io/_uploads/r1txuBwFeg.png) + 以sse測試AirBnb ![image](https://hackmd.io/_uploads/r1-v_rPtlg.png) + 以sse測試Bazi ![image](https://hackmd.io/_uploads/Bk4TOHPtgl.png) ## 六、Native MCP Agent ### 1. 必要env資訊 將對應web services的sse url輸入下述欄位 + **TIME_URL** + **AIRBNB_URL** + **BAZI_URL** + Save後,請重新啟動 Visual Studio Code,以讓env資訊生效 ### 2. Run Native MCP Agent + 開啟 **02-native-mcp.ipynb** + 於Creating a User Message Thread可定義user_prompt, 例如: + ```bash 請確認最近一週({today}-{next_week}) 哪一天適合出遊,並依據當天農民曆的吉方位,推薦一個由台北出發、沿該方位前往的國家中,目前可預訂且預算為 100 美金的最佳旅館,並提供該地目前的當地時間 ``` ![image](https://hackmd.io/_uploads/H1l98KFYel.png) + **Final Messages**: native-mcp-agent 成功串接 Bazi MCP,取得當日黃曆資訊以判斷是否適合出遊,並獲得最佳方位建議。接著依據方位推薦旅遊國家,並透過 Airbnb MCP 查詢符合預算且可預訂的飯店。最後,使用 Time MCP 取得該國當地時間 ![image](https://hackmd.io/_uploads/r1SZPtKKxg.png) ## 七、Browser Automation Agent ### 1. Create Playwright workspace resouce + 登入Azure Portal + search並選擇 `playwright workspaces` ![image](https://hackmd.io/_uploads/rygZctKKgx.png) + Create ![image](https://hackmd.io/_uploads/SydUqYKYlx.png) + Resource Group: 選擇你的資源群組 + workspace Name: 輸入任一名稱 + Region: 選擇相同的Region + Review + Create ![image](https://hackmd.io/_uploads/Hyv3qtFtle.png) + Create ![image](https://hackmd.io/_uploads/ByjmjKKKeg.png) + Go to resource ![image](https://hackmd.io/_uploads/Sk_TotFYge.png) ### 2. Generate Playwright Access Token + Settings ➜ Access Management ➜ Playwright Service Access Token ➜ Enable ![image](https://hackmd.io/_uploads/HJ-H3KtKel.png) + Generate Token ![image](https://hackmd.io/_uploads/B1UxpFKtge.png) + Access token name: 輸入任一名稱 + Expired Date: 選擇有效期限 + Generate Token ![image](https://hackmd.io/_uploads/ByuqaYFtge.png) + 請Copy Token並妥善保存,後續場景將使用 ![image](https://hackmd.io/_uploads/HJ4QCKKtee.png) ### 3. Assign Permission to AI Project + 點選 Access Control(IAM) ➜ add role assignment ![image](https://hackmd.io/_uploads/Hk1-Z9FYge.png) + 點選 Privileged administrator roles ➜ `Contributor` ➜ Next ![image](https://hackmd.io/_uploads/By9ubqFtgx.png) + 點選 manage identity ➜ select member ➜ 選擇您的Azure AI Foundry ➜ 點擊 **Select** ➜ Next ![image](https://hackmd.io/_uploads/rklSM5tYgg.png) + Review + assign ![image](https://hackmd.io/_uploads/HkppM9FKge.png) ### 4. Connect Playwright to AI Foundry + Management center ![image](https://hackmd.io/_uploads/HyJfbLKYll.png) + `Connected resources` ➜ `+ New connection` ![image](https://hackmd.io/_uploads/r1cN-UYtex.png) + Serverless Model ![image](https://hackmd.io/_uploads/HJ8hQcFYlg.png) + Target URI: 請copy `Browser endpoint` ![image](https://hackmd.io/_uploads/BkTc4cKFgg.png) + key: 請輸入 Playwright Access Token + Connection name: 請輸入任一名稱 + Add connection ![image](https://hackmd.io/_uploads/SJmvHcKKel.png) ### 5. 必要env資訊 + **PLAYWRIGHT_RESOURCE_NAME**: 請輸入您的playwright名稱 + Save後,請重新啟動 Visual Studio Code,以讓env資訊生效 ### 6. Run Browser Automation Agent + 開啟 **03-simple-browser-automation-agent.ipynb** + 於Creating a User Message Thread可定義user_prompt, 例如: ```bash 請造訪 DevDays Asia 2025 官方網站: https://www.digitimes.com.tw/Seminar/DevDaysAsia2025/index_en.html 接著請點選「Agenda」頁面,並參考第一天(9月23日)下午場次,請列出完整議程內容與講者。 ``` ![image](https://hackmd.io/_uploads/BySXO5FFgl.png) + **Final Messages**: browser-automation-agent 成功操作網頁,點選不同日期及Track,找到所有資訊 ![image](https://hackmd.io/_uploads/rkTwo9FYel.png) ---