> 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.md).

# Agent

Agent 是什麼：在 MaiAgent 建立的 AI 對話角色，由回答模式、角色指令、語言模型、知識庫與工具組成，以及建立 Agent 前要先決定的事。

## 這是什麼？ <a href="#what-is-this" id="what-is-this"></a>

Agent 是你在 MaiAgent 上建立的 AI 對話角色。每一個 Agent 都是一個獨立的對話機器人，有自己的身分、個性、知識和能力。

你可以把 Agent 想成一位新進員工——你需要告訴它：

* **你是誰**（角色指令 / System Prompt）
* **你知道什麼**（知識庫、資料庫）
* **你能做什麼**（工具、技能）

設定完成後，Agent 就能在各種對話平台上為使用者服務。

## 核心概念 <a href="#core-concepts" id="core-concepts"></a>

### 語言模型（LLM） <a href="#language-model-llm" id="language-model-llm"></a>

Agent 的理解和回覆能力來自背後的大型語言模型（LLM）。你可以把 LLM 想成 Agent 的「腦力」——不同的模型在理解力、回覆品質、速度和成本上各有差異。

建立 Agent 時，你可以選擇適合場景的模型。MaiAgent 支援多種模型，包括 Claude、GPT 等，不需要自己管理模型，平台會幫你處理。

> **簡單判斷**：需要精準回覆、複雜推理 → 選較強的模型；高頻簡單問答、控制成本 → 選較快較輕的模型。

### 角色指令（System Prompt） <a href="#system-prompt" id="system-prompt"></a>

角色指令決定了 Agent 的行為方式。例如：

* 「你是一位親切的客服人員，用繁體中文回覆，語氣專業但不生硬。」
* 「你是一位財務分析助理，只回答與財務相關的問題，遇到不確定的數據請明確告知。」

好的角色指令會讓 Agent 的回覆品質大幅提升。

### 回覆模式 <a href="#response-mode" id="response-mode"></a>

在 Agent 設定頁的「回答模式設定」選擇回覆方式，新建立的 Agent 預設為 Agent 模式：

* **Agent 模式**（預設）：適合需要多步驟推理的場景，Agent 會自行判斷要查什麼資料、用什麼工具
* **RAG 問答**：適合一般問答，直接依知識庫內容回覆
* **模板**、**混合**（收在「其他模式」底下）：模板依知識庫與 FAQ 以分類方式回覆，不由模型自由生成；混合則部分內容用模板格式、其餘自由回答

各模式的差異與設定方式，請看 [建立 Agent](/build/agent/setup.md#select-answer-mode-to-build-prompt)。

### 記憶 <a href="#memory" id="memory"></a>

Agent 具備記憶能力：

* **對話記憶**：在同一段對話中記得前面聊過的內容；開啟「向量記憶」後，較早的訊息也能以語意檢索找回來
* **跨對話檢索**：回答時搜尋同一位聯絡人近期的其他對話，不用每次重新介紹
* **持久記憶**：從對話中提取事實與偏好長期保存，在同一位聯絡人的不同對話中沿用

> **進階說明**：這些設定都在 Agent 設定頁的「進階設定」：「對話記憶設定」管向量記憶、跨對話檢索與可回溯天數，以及對話記憶用的 Embedding／Reranker 模型；「持久記憶」顯示跨對話記憶的開關狀態與記憶列表。詳見 [跨對話檢索](/build/agent/cross-conversation-search.md)（含[其他選項](/build/agent/cross-conversation-search.md#other-memory-settings)）與 [持久記憶](/build/agent/persistent-memory.md)。

## 我需要做什麼？ <a href="#what-do-i-need-to-do" id="what-do-i-need-to-do"></a>

1. **建立 Agent** — 取名、選擇語言模型
2. **寫角色指令** — 定義 Agent 的角色和回覆風格
3. **掛載能力** — 連結知識庫、工具、技能（視需求）
4. **測試對話** — 在內建的聊天視窗中測試效果
5. **串接平台上線** — 部署到 Web Chat、LINE 等對話平台

## 延伸閱讀 <a href="#further-reading" id="further-reading"></a>

* [Agent 的功能](/build/agent/explain.md)
* [建立 Agent](/build/agent/setup.md)
* [角色指令設計指南](/build/agent/system-prompt.md)
* [為 Agent 加入角色指令](/build/agent/add-system-prompt.md)


---

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