---
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:

+ AI Foundry Portal:

---
## 二、Create AI Agent - AzureInsight Agent
### 1. 登入 AI Foundry
+ 登入 `https://ai.azure.com/` 點選 **Agents**

### 2. Deploy Model
+ 選取 **gpt-4.1**
+ Confirm

+ Deploy

### 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`

### 4. 設置 Grounding with Bing Custom Search
+ 登入Azure Portal
+ 選擇您建立的Grounding with Bing Custom Search
+ Create new configuration

+ `+ Create new configuration`

+ 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`

+ Create new configuration

### 5. Use Grounding with Bing Custom Search
+ Knowledge -- `+ Add`

+ Grounding with Bing Custom Search

+ Create Connection

+ Add Connection

+ Select an existing configuration: 選擇方才建立的configuration
+ Connect

+ 選取`...`
+ Manage

+ Next

+ Count: 搜尋結果數量,請輸入 `10`
+ Freshness: 網頁發佈日期範圍,請輸入 `2025-08-01..2025-12-31`
+ Next

+ Connect

### 7. Bing Custom Search Tool 測試
+ Try in playground

+ 測試Query
```shell
Search the new article about Azure Cloud & AI platform
```
+ 發佈日期皆為最近
+ 來源資料皆為指定網站

### 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`

+ 點選 **Azure Logic Apps**

+ Send Email using Outlook

+ Your action name: 任一可識別的logic app名稱
+ Your action description: 輸入相關描述
+ Next

+ 點選 **Connect** 輸入您的M365 Outlook帳號

+ 完成相關驗證,Next

+ 勾選 ‵I acknowledge....`
+ Next

+ Schema說明: `RequestBody` 為 Agent 傳入的參數,包含以下欄位:
- **`email_to`**:收件人電子信箱
- **`email_subject`**:郵件主旨
- **`email_body`**:郵件內容
+ Create

### 9. Send Email Tool 測試
+ 測試Query
```shell
請將結果寄給 `your email address`
```

+ email 內容

---
## 三、 Create a time-based Logic App trigger
### 1. Create Azure Logic Apps
+ create trigger

+ 選擇 Consumption
+ Select

+ Resource Group: 選擇你的資源群組
+ Logic App Name: 輸入任一名稱
+ Region: 選擇相同的Region
+ Review + Create

+ Create

+ Go to resource

### 2. Assign permission to access AI Foundry
+ 點擊 **identity**
+ status 選擇 **on**
+ save

+ Azure Portal 選擇 **Azure AI Foundry**

+ 在 AI Foundry選擇您建立的project

+ 點選 Access Control(IAM)
+ add role assignment

+ 選擇 Azure AI User
+ Next

+ 點選 manage identity
+ select member
+ 選擇剛所建立的logic apps
+ 點擊 **Select**
+ Next

+ 點擊 **Review + assign**

### 3. Setting Recurrence
+ Edit

+ 點擊 Add a trigger
+ 選擇 Schedule

+ Recurrence

+ 依據您的需求設定Scheule時間
+ 點擊 `+`
+ Add an action

### 4. Configure Connect to AI Foundry
+ search bar: 輸入 `Azure AI Foundry`
+ 選擇 `Create Thread`

+ create connection: 輸入可識別的名稱
+ connection name:
Azure AI Project Endpoint:

+ connection name: 輸入Azure AI Project Endpoint
- 至您建立的AI Foundry Project 在 **overview**頁面 獲取此資訊

- 點選 **create new**
+ 點擊 **Show all**
+ Advanced Parameters 勾選**+ Add new item**

+ 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

+ Create Run

+ 點擊 閃電 可叫出Expression

+ The ID of the thread to create a message for: 選擇Create Thread的id

+ assistant_id: 請到Azure AI Foundry 複製您的 `Agent ID`
+ temperature: 輸入 **0.01**

+ 點擊 `+`
+ Add an action
+ 選擇 Delay: 用來等待 Run 完成

+ Count: 60
+ UnitL Second

+ 點擊 `+`
+ Add an action
+ 選擇 Get Run: 得到 Run 結果

+ The ID of the thread to create a message for: 選擇`Create Thread`的id
+ The ID of the run: 選擇`Create Run`的id

+ 點擊 `+`
+ Add an action
+ 選擇 List Messages: 得到這個thread的所有messages

+ The ID of the thread to create a message for: 選擇`Create Thread`的id

+ 點擊 `+`
+ Add an action
+ Compose: 輸出最後一個Message

+ 把第一筆訊息的文字內容 抽出來
+ Inputs請輸入
```
body('List_Messages')['data'][0]['content'][0]['text']['value']
```

+ Save
+ Run: 測試是否在您的信箱可收到結果

---
## 四、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.
```

### 2. Use Code Interpreter
+ Actions --> `+ Add`

+ 點選 **Code Interpreter**

+ 下載測試Excel: [2024-死因統計](https://1drv.ms/x/c/8302862bf709a02b/EWfU4YxmldNMnrJFiROtAKgByM41k7jc-KjIlQW7f8HXNg?e=lHcT9E)
+ 儲存至您的本機路徑
+ `select local file` 選取測試Excel的本機路徑

+ update and save

### 3. Data Analysis 測試
+ 測試Query
```shell
請找出25-44歲年齡層中,男性死亡率最高的前六大死因(排除「所有死亡原因」總計)
```
**Step 0:列出執行計劃**
- Agent 先整理並確認整體處理步驟。
**Step 1:定位相關 Worksheet**
- 根據問題,找出最相關的工作表。

**Step 2:載入對應 Worksheet**
- 確認並讀取目標工作表。
**Step 3:欄位分析與重新定義**
- 判斷欄位意義與資料分布,重新命名欄位以利後續處理。

**Step 4:篩選與排序(男性資料)**
- 挑選與男性相關的欄位,排除「所有死亡原因」。
- 僅保留「死亡率」欄位為數值的資料,強制轉換為 `float`。
- 依死亡率由高到低排序,取前 6 筆。

**Step 5:資料清理與最終排序**
- 移除非字串資料(如 NaN),再次確認死亡率欄位型態。

### 4. Data Analysis 圖表能力測試
+ 測試Query
```
請以bar chart圖呈現這個結果
```

+ 確認當前環境是否有安裝中文字型
```
請寫出一個程式,列出當前環境所有已安裝字型且可支援中文的程式 (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 先提供欄位的中英文對照表。

**Step 2:完成圖表**
