> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/build/agent/add-system-prompt.md).

# 為 Agent 加入角色指令

把設計好的角色指令（System Prompt）填入 Agent 設定：進入 Agent 編輯頁、貼上角色指令並儲存的操作步驟，以及依對話平台寫不同回覆規則的方法。

角色指令設計完成後，您可以在 MaiAgent 的 Agent 設定中加入角色指令：

## 加入角色指令 <a href="#add-system-prompt" id="add-system-prompt"></a>

### 1. 進入 Agent 設定頁面 <a href="#step-1-navigate-to-ai-agent-settings" id="step-1-navigate-to-ai-agent-settings"></a>

於左側選單點選 <mark style="color:blue;">AI 功能</mark> > <mark style="color:blue;">AI 助理</mark>，在列表中找到您要設定的 Agent，點按該列 <mark style="color:blue;">操作</mark> 欄的 <mark style="color:blue;">編輯</mark> 圖示。

<figure><img src="https://1593648278-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fmzb5NG9GDzFP2YDKeYVl%2Fuploads%2Fgit-blob-4d2b79176a41568cb0cd9e0dc9e201b5671a6a6a%2Fai-agent-list-edit-button.png?alt=media" alt="Agent 列表，操作欄的編輯圖示已標示"><figcaption><p>點按操作欄的編輯圖示進入 Agent 設定</p></figcaption></figure>

### 2. 切換至回答模式設定頁面 <a href="#step-2-switch-to-answer-mode-settings" id="step-2-switch-to-answer-mode-settings"></a>

在 <mark style="color:blue;">設定</mark> 分頁左側的設定選單中，點選 <mark style="color:blue;">回答模式設定</mark>。

將 <mark style="color:blue;">回答模式</mark> 設置為 <mark style="color:blue;">RAG 問答</mark>、<mark style="color:blue;">Agent 模式</mark>，或展開 <mark style="color:blue;">其他模式</mark> 選擇 <mark style="color:blue;">混合</mark>：

{% hint style="warning" %}
「模板」模式（位於 <mark style="color:blue;">其他模式</mark> 內）無法設置角色指令
{% endhint %}

<figure><img src="https://1593648278-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fmzb5NG9GDzFP2YDKeYVl%2Fuploads%2Fgit-blob-b814b654848f855a4cfe488c9517e7388c11cb3a%2Fai-agent-reply-mode-settings.png?alt=media" alt="設定分頁的回答模式設定，顯示 RAG 問答、Agent 模式與其他模式選項"><figcaption><p>於回答模式設定中選擇回答模式</p></figcaption></figure>

### 3. 在角色指令區段加入文字 <a href="#step-3-enter-text-in-system-prompt-section" id="step-3-enter-text-in-system-prompt-section"></a>

在同一頁下方的 <mark style="color:blue;">角色指令</mark> 區段輸入角色指令內容，完成後點按右下角的 <mark style="color:blue;">儲存</mark>。

<figure><img src="https://1593648278-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fmzb5NG9GDzFP2YDKeYVl%2Fuploads%2Fgit-blob-f56ca83283c5e1689fde5ff2f3808aa9ac70d906%2Fai-agent-instructions-field.png?alt=media" alt="角色指令區段，含使用提示、快速插入提示詞與輸入框"><figcaption><p>在角色指令區段輸入內容</p></figcaption></figure>

如此一來，Agent 就會根據您所定義的角色指令行動，成為您專屬的 Agent。

## 依對話平台寫規則 <a href="#channel-specific-rules" id="channel-specific-rules"></a>

同一個 Agent 可以同時串接網頁聊天、LINE、WhatsApp 等多個對話平台。Agent 每次回覆時，系統都會告訴它這段對話是在哪個平台進行，所以您可以在角色指令裡依平台寫不同的規則，例如網頁聊天可以用條列與粗體，WhatsApp 只回純文字。這項資訊由系統自動帶入，不需要另外開啟設定。

### 使用情境 <a href="#channel-rules-scenario" id="channel-rules-scenario"></a>

一家家電公司的客服主管把同一個客服 Agent 串上官網的網頁聊天和 LINE 官方帳號。她希望官網的回覆排版完整、方便閱讀，LINE 上則是一眼看完的簡短純文字。她在角色指令加上一段「依對話平台調整回覆」：Web 可以用條列與粗體，LINE 和 WhatsApp 只用純文字、回覆不超過 60 字。儲存後，她到後台測試對話問了一題，網頁上的回覆照規則用了條列，最後還附上規定的署名。同一份角色指令就能管好兩個平台，不必為每個平台另外建一個 Agent。

### 撰寫方式 <a href="#write-channel-rules" id="write-channel-rules"></a>

在 <mark style="color:blue;">角色指令</mark> 區段另起一段，用「對話平台是 ○○ 時：……」的句型逐條寫出各平台的規則，再點按右下角的 <mark style="color:blue;">儲存</mark>。例如：

```
【依對話平台調整回覆】
- 對話平台是 Web 時：可以使用條列與粗體，回覆最後一行加上「— 示範生活家電網頁客服」。
- 對話平台是 LINE 或 WhatsApp 時：只用純文字，不使用 Markdown、表格或卡片，回覆不超過 60 字。
```

<figure><img src="https://1593648278-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fmzb5NG9GDzFP2YDKeYVl%2Fuploads%2Fgit-blob-eabd8c7a4cbf6ed2e2153dda54933ba9f096b314%2Fai-agent-instructions-channel-rules.png?alt=media" alt="角色指令輸入框，內容含「依對話平台調整回覆」段落，分別寫出 Web 與 LINE、WhatsApp 的回覆規則"><figcaption><p>在角色指令中依對話平台寫出回覆規則</p></figcaption></figure>

Agent 收到的平台名稱是下列英文名稱，規則裡直接寫這些名稱最不容易對不上：

| 對話平台                         | Agent 收到的名稱  |
| ---------------------------- | ------------ |
| 網頁聊天（Web Chat）、後台測試對話、API 串接 | `Web`        |
| LINE 官方帳號                    | `LINE`       |
| LINE WORKS                   | `LINE WORKS` |
| WhatsApp                     | `WhatsApp`   |
| Facebook Messenger           | `Messenger`  |
| Instagram                    | `Instagram`  |
| Telegram                     | `Telegram`   |
| Microsoft Teams              | `Teams`      |
| Slack                        | `Slack`      |
| Email                        | `Email`      |
| Team+                        | `Team+`      |
| Viber                        | `Viber`      |

### 確認回覆結果 <a href="#verify-channel-rules" id="verify-channel-rules"></a>

儲存後，在 Agent 列表點按該列 <mark style="color:blue;">操作</mark> 欄的 <mark style="color:blue;">前往對話</mark>，用後台測試對話問一個問題。後台測試對話屬於 `Web`，回覆應符合您為 Web 寫的規則。其他平台的規則，請從該平台實際傳一則訊息確認。

<figure><img src="https://1593648278-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fmzb5NG9GDzFP2YDKeYVl%2Fuploads%2Fgit-blob-95235f7f4b3614c8737ac71fc28f67d4c010b968%2Fai-agent-channel-rules-web-reply.png?alt=media" alt="後台測試對話中，Agent 以條列回覆冷氣省電技巧，最後一行為「— 示範生活家電網頁客服」"><figcaption><p>後台測試對話屬於 Web，回覆依 Web 規則使用條列並附上署名</p></figcaption></figure>

{% hint style="info" %}

* 使用者沒有問的話，Agent 不會在回覆中主動提到對話平台的名稱。
* 平台資訊只讓 Agent 知道目前的平台，系統不會依平台自動拿掉卡片或其他回覆形式。某個平台顯示不了的格式，請在角色指令裡寫明不要使用。
  {% endhint %}

## 角色指令的編輯紀錄 <a href="#instruction-edit-history" id="instruction-edit-history"></a>

角色指令每次儲存都會留下一個版本。點 <mark style="color:blue;">角色指令</mark> 區段的 「<mark style="color:blue;">編輯紀錄</mark>」，會以時間軸列出歷次儲存的時間與完整內容（最新的在最上面，往下捲動會載入更早的版本）。將滑鼠移到某個版本上會出現兩個按鈕：

| 按鈕                                      | 作用                                                                                              |
| --------------------------------------- | ----------------------------------------------------------------------------------------------- |
| <mark style="color:blue;">套用</mark>     | 把該版本的內容填回角色指令欄位並關閉視窗。要生效仍需按右下角的 <mark style="color:blue;">儲存</mark>，所以可以先比對內容、不滿意再改回來           |
| <mark style="color:blue;">檢視訊息紀錄</mark> | 開啟「使用該版本角色指令期間」的對話紀錄清單，每筆可點 「<mark style="color:blue;">查看回覆品質控管詳情</mark>」 看完整問答；用來對照哪一版的回覆品質比較好 |

建議大幅修改前先開 「編輯紀錄」 確認目前版本；改壞了隨時可以套用舊版再儲存。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.maiagent.ai/build/agent/add-system-prompt.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
