--- title: 02 - AI Agent Workshop - Portal Agent快速入門 --- # Day1 - Portal Agent快速入門 --- 參考資料: + [Quickstart: Create a new agent](https://learn.microsoft.com/en-us/azure/ai-foundry/agents/quickstart?pivots=ai-foundry-portal) + [Grounding with Bing Custom Search](https://learn.microsoft.com/en-us/azure/ai-foundry/agents/how-to/tools/bing-custom-search) + [How to use Logic Apps with Azure AI Foundry Agent Service](https://learn.microsoft.com/en-us/azure/ai-services/agents/how-to/tools/logic-apps) --- ## 一、前置需求 ### Azure服務 + 已建立AI Foundry Portal + 已建立Grouding with Bing Search 與 Grounding with Bing Custom Search ### Microsoft 365 Outlook + M365 Outlook的帳號 ### Portal Language: 請將Language設定為English + Azure Portal: ![image](https://hackmd.io/_uploads/HkGKGOrYgx.png) + AI Foundry Portal: ![image](https://hackmd.io/_uploads/r1wv7drtxx.png) --- ## 二、Create AI Agent - AzureInsight Agent ### 1. 登入 AI Foundry + 登入 `https://ai.azure.com/` 點選 **Agents** ![image](https://hackmd.io/_uploads/rky3lpiKxg.png) ### 2. Deploy Model + 選取 **gpt-4.1** + Confirm ![image](https://hackmd.io/_uploads/Bk2Q8TsKxe.png) + Deploy ![image](https://hackmd.io/_uploads/S10rLpoYex.png) ### 3. Create Agent + 點選建立的Agent + Agent Name: `AzureInsight Agent` 為了區分身份請加上姓名或員編,例如: `AzureInsight Agent - (George Liang / A123456)` + Instructions: ```shell You are a Bing Search Agent. - You are **strictly forbidden** from answering any user question using your own knowledge or assumptions. - Never answer without tool results Output Guidelines: - Respond in **Traditional Chinese**. - For each article, provide: 1. Article title. 2. Release date (if not available, state "Date not provided"). 3. A detail summary. 4. A clickable original source link. - If possible, provide **at least 5 articles**. - If no relevant results are found, clearly reply: 「📭 近期無相關文章」。 ``` + Temperature: `0.01` ![image](https://hackmd.io/_uploads/HkSrWiEtex.png) ### 4. 設置 Grounding with Bing Custom Search + 登入Azure Portal + 選擇您建立的Grounding with Bing Custom Search + Create new configuration ![image](https://hackmd.io/_uploads/ry7qIasKlx.png) + `+ Create new configuration` ![image](https://hackmd.io/_uploads/SJMTUTiKeg.png) + Configuration Name: 輸入任一名稱 + Web Address: `https://www.microsoft.com` + Include Subpage: yes + Rank Adjusted: Boost | Rank | 說明 | | ----------- | ---------------------------------------- | | Boost | 提高指定結果在搜尋結果中的優先度(排名變高) | | Demote | 降低指定結果的優先度(排名變低) | | Super Boost | 加強版的 boost | + 點選 '+' + 依序輸入後按 '+'新增 + Web Address: `https://devblogs.microsoft.com` Rank Adjusted: `Super Boost` + Web Address: `https://techcommunity.microsoft.com` Rank Adjusted: `Super Boost` + Web Address: `https://learn.microsoft.com` Rank Adjusted: `Boost` ![image](https://hackmd.io/_uploads/B1EXBYNKxx.png) + Create new configuration ![image](https://hackmd.io/_uploads/rJB9bJ2Kee.png) ### 5. Use Grounding with Bing Custom Search + Knowledge -- `+ Add` ![image](https://hackmd.io/_uploads/SyfT-khtgl.png) + Grounding with Bing Custom Search ![image](https://hackmd.io/_uploads/BkXR-khKxl.png) + Create Connection ![image](https://hackmd.io/_uploads/S16kGJ2Fgx.png) + Add Connection ![image](https://hackmd.io/_uploads/r1zZMJhKxg.png) + Select an existing configuration: 選擇方才建立的configuration + Connect ![image](https://hackmd.io/_uploads/SkN62KEFee.png) + 選取`...` + Manage ![image](https://hackmd.io/_uploads/SkolptVKle.png) + Next ![image](https://hackmd.io/_uploads/SyYL6KVKgx.png) + Count: 搜尋結果數量,請輸入 `10` + Freshness: 網頁發佈日期範圍,請輸入 `2025-08-01..2025-12-31` + Next ![image](https://hackmd.io/_uploads/BkisaFEFlg.png) + Connect ![image](https://hackmd.io/_uploads/HyBV1cVFgl.png) ### 7. Bing Custom Search Tool 測試 + Try in playground ![image](https://hackmd.io/_uploads/B1Yxe9EKgg.png) + 測試Query ```shell Search the new article about Azure Cloud & AI platform ``` + 發佈日期皆為最近 + 來源資料皆為指定網站 ![image](https://hackmd.io/_uploads/H1yHBjNKgg.png) ### 8. Use Azure Logic Apps - Send Email + 請將以下 Prompts **Append** 至現有的 Instructions: ```shell - Only when sending emails: - Write the entire email content in Traditional Chinese. - Format the email body in HTML so that line breaks and layout are correctly displayed in Microsoft Outlook. - Please directly sending to email without asking for approval. ``` + Actions --> `+ Add` ![image](https://hackmd.io/_uploads/Skkrfy2Ylx.png) + 點選 **Azure Logic Apps** ![image](https://hackmd.io/_uploads/ryVLM13txl.png) + Send Email using Outlook ![image](https://hackmd.io/_uploads/r1_vMyhYlg.png) + Your action name: 任一可識別的logic app名稱 + Your action description: 輸入相關描述 + Next ![image](https://hackmd.io/_uploads/ByRdG1hKll.png) + 點選 **Connect** 輸入您的M365 Outlook帳號 ![image](https://hackmd.io/_uploads/SkC5zk2Kle.png) + 完成相關驗證,Next ![image](https://hackmd.io/_uploads/ryopzy3Yeg.png) + 勾選 ‵I acknowledge....` + Next ![image](https://hackmd.io/_uploads/BklJXk2Yxl.png) + Schema說明: `RequestBody` 為 Agent 傳入的參數,包含以下欄位: - **`email_to`**:收件人電子信箱 - **`email_subject`**:郵件主旨 - **`email_body`**:郵件內容 + Create ![image](https://hackmd.io/_uploads/BJ4eQkhFgl.png) ### 9. Send Email Tool 測試 + 測試Query ```shell 請將結果寄給 `your email address` ``` ![image](https://hackmd.io/_uploads/SkDSLo4Fll.png) + email 內容 ![image](https://hackmd.io/_uploads/HkB08j4Kxl.png) --- ## 三、 Create a time-based Logic App trigger ### 1. Create Azure Logic Apps + create trigger ![image](https://hackmd.io/_uploads/HJVPMLrKll.png) + 選擇 Consumption + Select ![image](https://hackmd.io/_uploads/Sy7ZQIBFxe.png) + Resource Group: 選擇你的資源群組 + Logic App Name: 輸入任一名稱 + Region: 選擇相同的Region + Review + Create ![image](https://hackmd.io/_uploads/H1g_mUHtxg.png) + Create ![image](https://hackmd.io/_uploads/H1pz4IHYxl.png) + Go to resource ![image](https://hackmd.io/_uploads/H1DwEUSFxg.png) ### 2. Assign permission to access AI Foundry + 點擊 **identity** + status 選擇 **on** + save ![image](https://hackmd.io/_uploads/HJs1j8BYee.png) + Azure Portal 選擇 **Azure AI Foundry** ![image](https://hackmd.io/_uploads/HykjjN-4gx.png) + 在 AI Foundry選擇您建立的project ![image](https://hackmd.io/_uploads/H1_Kh4-Nxg.png) + 點選 Access Control(IAM) + add role assignment ![image](https://hackmd.io/_uploads/r1xWTN-Ngl.png) + 選擇 Azure AI User + Next ![image](https://hackmd.io/_uploads/rJsvTN-4gx.png) + 點選 manage identity + select member + 選擇剛所建立的logic apps + 點擊 **Select** + Next ![image](https://hackmd.io/_uploads/Bk9_oLSKeg.png) + 點擊 **Review + assign** ![image](https://hackmd.io/_uploads/SJdqiISKle.png) ### 3. Setting Recurrence + Edit ![image](https://hackmd.io/_uploads/B1tWH8SFxx.png) + 點擊 Add a trigger + 選擇 Schedule ![image](https://hackmd.io/_uploads/Hk8LrLHYlg.png) + Recurrence ![image](https://hackmd.io/_uploads/rJU9B8SFlg.png) + 依據您的需求設定Scheule時間 + 點擊 `+` + Add an action ![image](https://hackmd.io/_uploads/HyTiUUSYxl.png) ### 4. Configure Connect to AI Foundry + search bar: 輸入 `Azure AI Foundry` + 選擇 `Create Thread` ![image](https://hackmd.io/_uploads/BJbrwUHFgg.png) + create connection: 輸入可識別的名稱 + connection name: Azure AI Project Endpoint: ![image](https://hackmd.io/_uploads/Hk4SAUrtlx.png) + connection name: 輸入Azure AI Project Endpoint - 至您建立的AI Foundry Project 在 **overview**頁面 獲取此資訊 ![image](https://hackmd.io/_uploads/r18iFE-Ege.png) - 點選 **create new** + 點擊 **Show all** + Advanced Parameters 勾選**+ Add new item** ![image](https://hackmd.io/_uploads/ry5YJPBKee.png) + Role-1: 輸入 `user` + Content-1: 輸入user query, 例如: ```shell 1.Search the new article about Azure Cloud & AI platform 2.Send the report to email geoliang@microsoft.com (請置換為您的郵件信箱) ``` + 點擊 `+` + Add an action ![image](https://hackmd.io/_uploads/HyenbPrKgx.png) + Create Run ![image](https://hackmd.io/_uploads/BkPZGvStxg.png) + 點擊 閃電 可叫出Expression ![image](https://hackmd.io/_uploads/S1wYwPHKxg.png) + The ID of the thread to create a message for: 選擇Create Thread的id ![image](https://hackmd.io/_uploads/HyUQVwBtxg.png) + assistant_id: 請到Azure AI Foundry 複製您的 `Agent ID` + temperature: 輸入 **0.01** ![image](https://hackmd.io/_uploads/Hyj5mwStxg.png) + 點擊 `+` + Add an action + 選擇 Delay: 用來等待 Run 完成 ![image](https://hackmd.io/_uploads/HJCrBDHYle.png) + Count: 60 + UnitL Second ![image](https://hackmd.io/_uploads/S1AdrDSKxl.png) + 點擊 `+` + Add an action + 選擇 Get Run: 得到 Run 結果 ![image](https://hackmd.io/_uploads/Sk4zLvHFgl.png) + The ID of the thread to create a message for: 選擇`Create Thread`的id + The ID of the run: 選擇`Create Run`的id ![image](https://hackmd.io/_uploads/HkUzDDBFee.png) + 點擊 `+` + Add an action + 選擇 List Messages: 得到這個thread的所有messages ![image](https://hackmd.io/_uploads/Sk-UuPHtee.png) + The ID of the thread to create a message for: 選擇`Create Thread`的id ![image](https://hackmd.io/_uploads/rJ2tdwSYeg.png) + 點擊 `+` + Add an action + Compose: 輸出最後一個Message ![image](https://hackmd.io/_uploads/B1lNKvBKlx.png) + 把第一筆訊息的文字內容 抽出來 + Inputs請輸入 ``` body('List_Messages')['data'][0]['content'][0]['text']['value'] ``` ![image](https://hackmd.io/_uploads/BkewKPBtge.png) + Save + Run: 測試是否在您的信箱可收到結果 ![image](https://hackmd.io/_uploads/H1f2YDrFge.png) --- ## 四、Create AI Agent - DataAnalysis Agent ### 1. Create Agent + 點選建立的Agent + Agent Name: `DataAnalysis Agent` 為了區分身份請加上姓名或員編,例如: `DataAnalysis Agent - (George Liang / A123456)` + Instructions: ```shell You are a data analysis assistant. - You MUST always answer the user’s question only using knowledge deriv ed from the Code Interpreter tool. - Do NOT use your own prior knowledge. ## Excel File Handling - The uploaded Excel file may contain multiple worksheets. - First, determine which worksheet(s) are relevant by either: - Scanning all worksheet names, OR - If a worksheet named "目錄" exists, inspecting its content. ## Data Extraction & Preparation - Once the relevant worksheet(s) have been identified: - Always generate a full pre-formatted Markdown table for clarity, instead of previews or raw dataframe output. - Always expand merged cells (using forward-fill) so that each row has complete context. - If the data has duplicated column names, convert the column names into a flat string format. - When extracting subsets of data: - Never rely on fixed column index positions. - Always identify the correct columns based on their header names or the semantic meaning shown in the table. - If necessary, explicitly output the full list of column headers before selecting which to use. ``` ![image](https://hackmd.io/_uploads/SJZnmJ3Ygg.png) ### 2. Use Code Interpreter + Actions --> `+ Add` ![image](https://hackmd.io/_uploads/HkWaQJnFel.png) + 點選 **Code Interpreter** ![image](https://hackmd.io/_uploads/SycCXyntex.png) + 下載測試Excel: [2024-死因統計](https://1drv.ms/x/c/8302862bf709a02b/EWfU4YxmldNMnrJFiROtAKgByM41k7jc-KjIlQW7f8HXNg?e=lHcT9E) + 儲存至您的本機路徑 + `select local file` 選取測試Excel的本機路徑 ![image](https://hackmd.io/_uploads/HkkeNk2Fxg.png) + update and save ![image](https://hackmd.io/_uploads/SJXbEy2Fee.png) ### 3. Data Analysis 測試 + 測試Query ```shell 請找出25-44歲年齡層中,男性死亡率最高的前六大死因(排除「所有死亡原因」總計) ``` **Step 0:列出執行計劃** - Agent 先整理並確認整體處理步驟。 **Step 1:定位相關 Worksheet** - 根據問題,找出最相關的工作表。 ![image](https://hackmd.io/_uploads/ByAzE1hKgg.png) **Step 2:載入對應 Worksheet** - 確認並讀取目標工作表。 **Step 3:欄位分析與重新定義** - 判斷欄位意義與資料分布,重新命名欄位以利後續處理。 ![image](https://hackmd.io/_uploads/Hk344khKlx.png) **Step 4:篩選與排序(男性資料)** - 挑選與男性相關的欄位,排除「所有死亡原因」。 - 僅保留「死亡率」欄位為數值的資料,強制轉換為 `float`。 - 依死亡率由高到低排序,取前 6 筆。 ![image](https://hackmd.io/_uploads/BydINyhYle.png) **Step 5:資料清理與最終排序** - 移除非字串資料(如 NaN),再次確認死亡率欄位型態。 ![image](https://hackmd.io/_uploads/SJJ_Ek3txx.png) ### 4. Data Analysis 圖表能力測試 + 測試Query ``` 請以bar chart圖呈現這個結果 ``` ![image](https://hackmd.io/_uploads/SJOGvKV6gl.png) + 確認當前環境是否有安裝中文字型 ``` 請寫出一個程式,列出當前環境所有已安裝字型且可支援中文的程式 (chinese_text = "中文測試"),並執行後告知結果 ``` + 請將以下 Prompts **Append** 至現有的 Instructions: ```shell ## Charts & Visualizations - Only when generating charts or visualizations: - Before showing the chart, always output a bilingual mapping of field names (original Chinese column names alongside their English translations). - Always use English for axis labels, titles, and legends. - Additionally, translate all categorical data shown on the axes into English, so that the chart is fully readable in English. - Always display numerical values directly on the chart. ## Language of Explanations - You may still explain results in Chinese text outside the chart. ``` + 再次測試 ``` 請以bar chart圖呈現這個結果 ``` **Step 1:產生中英文對照** - Agent 先提供欄位的中英文對照表。 ![image](https://hackmd.io/_uploads/BymGtvR9ll.png) **Step 2:完成圖表** ![image](https://hackmd.io/_uploads/rJA6hDRcle.png)