> 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/custom-max-tokens.md).

# 自訂最大輸出 Tokens

### 功能簡介 <a href="#feature-introduction" id="feature-introduction"></a>

自訂輸出 Token 上限功能讓您能精確控制 AI 助理每次回覆的最大長度。透過調整此設定,您可以根據不同應用情境,讓 AI 助理產生簡短摘要或詳細說明,同時有效控制 Token 消耗成本。

{% hint style="info" %}
**Token 說明**

Token 是 AI 模型處理文字的基本單位。一般而言:

* 中文:1 個字約等於 1.5-2 個 Tokens
* 英文:1 個單字約等於 1-1.5 個 Tokens
* 標點符號也會計入 Token 數量
  {% endhint %}

***

### 設定輸出 Token 上限 <a href="#configure-token-output-limit" id="configure-token-output-limit"></a>

#### 進入設定頁面 <a href="#navigate-to-settings" id="navigate-to-settings"></a>

1. 點選左側選單「<mark style="color:blue;">AI 助理</mark>」
2. 選擇要設定的 AI 助理
3. 點選「<mark style="color:blue;">設定</mark>」按鈕
4. 切換至「<mark style="color:blue;">進階設定</mark>」頁籤

#### 調整 Token 上限 <a href="#adjust-token-limit" id="adjust-token-limit"></a>

1. **選擇 Token 上限模式**
   * 「<mark style="color:blue;">使用模型最大值</mark>」：直接套用所選模型支援的最大輸出 Token 數（預設）
   * 「<mark style="color:blue;">自訂數量</mark>」：自行指定上限
2. **輸入自訂數值（選擇「自訂數量」時）**
   * 在數字輸入框輸入目標數值
   * 可輸入範圍依所選模型而定，畫面會即時顯示該模型允許的範圍（如下圖的「範圍：512 - 64000 tokens」）
3. **儲存設定**
   * 點選「<mark style="color:blue;">儲存</mark>」按鈕
   * 設定立即生效,無需重啟 AI 助理

<figure><img src="/files/ZAr3E7ujbFUQbtRQnXoS" alt="進階設定：最大輸出 Token 數"><figcaption><p>AI 助理進階設定頁面：可選擇「使用模型最大值」或「自訂數量」來控制輸出 Token 上限</p></figcaption></figure>

{% hint style="warning" %}
**注意事項**

* 設定過低可能導致回覆被截斷,影響完整性
* 設定過高會增加 Token 消耗成本
* 建議依實際需求調整,並透過測試找到最佳平衡點
  {% endhint %}

***

### 建議設定值 <a href="#recommended-settings" id="recommended-settings"></a>

根據不同應用情境,以下是推薦的 Token 上限設定:

<table><thead><tr><th width="200">應用情境</th><th width="150">建議 Token 數</th><th>說明</th></tr></thead><tbody><tr><td><strong>簡短問答</strong></td><td>256 - 512</td><td>適合快速回答,如 FAQ 機器人<br>約 100-200 中文字</td></tr><tr><td><strong>一般客服</strong></td><td>512 - 1024</td><td>平衡詳細度與成本<br>約 200-400 中文字</td></tr><tr><td><strong>專業諮詢</strong></td><td>1024 - 2048</td><td>提供詳細說明與解決方案<br>約 400-800 中文字</td></tr><tr><td><strong>內容生成</strong></td><td>2048 - 4096</td><td>生成長篇文章或報告<br>約 800-1600 中文字</td></tr><tr><td><strong>程式碼生成</strong></td><td>1024 - 2048</td><td>產生完整的程式碼片段<br>含註解與說明</td></tr></tbody></table>

***

### 應用情境範例 <a href="#use-case-examples" id="use-case-examples"></a>

#### 情境一:FAQ 快速回答機器人 <a href="#scenario-1-faq-quick-response-bot" id="scenario-1-faq-quick-response-bot"></a>

**需求**:客戶常問的問題需要簡短明確的回答,避免冗長說明

**設定方式**:

* 輸出 Token 上限:256-512
* 角色指令:「請用簡短明確的方式回答問題,不超過 3 句話」
* 預期效果:快速回應,降低 Token 消耗

**範例對話**:

```
使用者:營業時間是幾點到幾點？
AI:我們的營業時間是週一至週五上午 9:00 至下午 6:00,
週六上午 10:00 至下午 5:00,週日公休。
```

#### 情境二:技術支援詳細說明 <a href="#scenario-2-technical-support-detailed-explanation" id="scenario-2-technical-support-detailed-explanation"></a>

**需求**:使用者遇到技術問題,需要詳細的步驟說明

**設定方式**:

* 輸出 Token 上限:1024-2048
* 角色指令:「請提供詳細的步驟說明,確保使用者能夠按步驟操作」
* 預期效果:完整的問題解決指引

**範例對話**:

```
使用者:軟體無法啟動怎麼辦？
AI:請依照以下步驟排除問題:

1. 確認系統需求
   - 作業系統: Windows 10 以上
   - 記憶體: 至少 4GB
   - 硬碟空間: 至少 2GB

2. 重新安裝軟體
   - 移除現有版本（控制台 > 程式集）
   - 下載最新版本 [連結]
   - 以管理員身分執行安裝程式

3. 檢查防火牆設定
   - 將軟體加入例外清單
   - 允許軟體存取網路

如以上步驟無法解決,請提供錯誤訊息截圖,我們將進一步協助。
```

#### 情境三:內容摘要生成 <a href="#scenario-3-content-summary-generation" id="scenario-3-content-summary-generation"></a>

**需求**:從長篇文章中提取重點摘要

**設定方式**:

* 輸出 Token 上限:512-768
* 角色指令:「請將重點整理為 3-5 個要點,每點不超過 2 句話」
* 預期效果:簡潔的摘要,易於快速理解

***

### 與其他設定的關係 <a href="#relationship-with-other-settings" id="relationship-with-other-settings"></a>

#### 角色指令 (System Prompt) <a href="#system-prompt-settings" id="system-prompt-settings"></a>

即使設定高 Token 上限,角色指令仍可約束回覆長度:

```
良好範例:
「請用簡潔的方式回答,除非使用者要求詳細說明」

不良範例:
「請儘可能詳細回答每個問題」（可能導致過長回覆）
```

#### 模型選擇 <a href="#model-selection" id="model-selection"></a>

不同模型支援的最大輸出 Token 數不同。當您切換 AI 助理使用的模型時,可自訂的範圍會隨之改變,畫面上的範圍提示即為目前所選模型的上下限。選擇「使用模型最大值」時,系統會自動套用該模型的最大值。

***

### 成本優化建議 <a href="#cost-optimization-recommendations" id="cost-optimization-recommendations"></a>

#### 計算 Token 消耗 <a href="#calculate-token-consumption" id="calculate-token-consumption"></a>

一次對話的 Token 消耗包含:

* **輸入 Tokens**:使用者問題 + 歷史對話 + 角色指令
* **輸出 Tokens**:AI 回覆（受此設定限制）

**範例計算**:

```
輸入:使用者問題 50 Tokens + 歷史對話 200 Tokens + 角色指令 100 Tokens = 350 Tokens
輸出:AI 回覆（上限設為 512 Tokens）
總計:350 + 512 = 862 Tokens（最多）
```

#### 優化策略 <a href="#optimization-strategies" id="optimization-strategies"></a>

1. **依情境調整**
   * 簡單問題用低 Token 上限
   * 複雜問題才提高上限
2. **避免不必要的長回覆**
   * 在角色指令中明確要求簡潔
   * 使用多輪對話取代單次長回覆
3. **定期檢視使用狀況**
   * 使用「使用分析」分頁查看對話字數等用量趨勢
   * 調整設定以優化成本

{% hint style="info" %}
詳細的成本計算與優化建議,請參考 [用量計算](/others/usage.md)。
{% endhint %}

***

### 常見問題 <a href="#faq" id="faq"></a>

#### Q:設定 Token 上限後,AI 回覆會被強制截斷嗎？ <a href="#q-will-ai-response-be-cut-off-after-setting-token-limit" id="q-will-ai-response-be-cut-off-after-setting-token-limit"></a>

**A**:是的。當 AI 生成的回覆達到 Token 上限時,會在該位置停止,可能導致句子不完整。建議:

* 設定適當的上限（不要過低）
* 在角色指令中要求「在達到字數限制前自然結束」

#### Q:如何知道我的 AI 助理平均使用多少 Tokens？ <a href="#q-how-to-check-average-token-usage" id="q-how-to-check-average-token-usage"></a>

**A**:進入 AI 助理「<mark style="color:blue;">設定</mark>」頁的「<mark style="color:blue;">使用分析</mark>」分頁,可依日期區間查看「<mark style="color:blue;">對話字數</mark>」「對話次數」「訊息次數」「平均對話互動次數」「使用者滿意度」等趨勢圖。其中「對話字數」為該助理累計產生的字數,字數與 Token 數量呈正相關,可作為 Token 消耗的參考依據。

<figure><img src="/files/Y4zGBLw1nQqMy9UuhVd5" alt="使用分析分頁"><figcaption><p>AI 助理「使用分析」分頁：可依日期區間查看對話字數、對話次數、訊息次數、平均對話互動次數與使用者滿意度等趨勢圖</p></figcaption></figure>

#### Q:設定較高的 Token 上限會降低回覆速度嗎？ <a href="#q-does-higher-token-limit-slow-down-responses" id="q-does-higher-token-limit-slow-down-responses"></a>

**A**:會有輕微影響。更長的回覆需要更多生成時間,但通常差異不大（數秒內）。主要影響因素仍是:

* 模型選擇
* 網路連線速度
* 伺服器負載

#### Q:不同語言需要不同的 Token 上限設定嗎？ <a href="#q-different-languages-need-different-token-limits" id="q-different-languages-need-different-token-limits"></a>

**A**:建議適度調整:

* **中文**:同樣字數消耗較多 Tokens,可略為提高上限
* **英文**:Token 效率較高,可使用較低上限
* **多語言環境**:建議設定較高上限以確保彈性

#### Q:Token 上限會影響知識庫檢索結果嗎？ <a href="#q-does-token-limit-affect-knowledge-base-retrieval" id="q-does-token-limit-affect-knowledge-base-retrieval"></a>

**A**:不會直接影響檢索,但會影響如何呈現檢索結果:

* **高 Token 上限**:可引用更多知識庫片段
* **低 Token 上限**:只引用最相關的片段

***

### 測試與調整 <a href="#testing-and-adjustment" id="testing-and-adjustment"></a>

#### 測試流程 <a href="#testing-process" id="testing-process"></a>

1. **設定初始值**
   * 從建議值開始（如 1024）
2. **進行測試對話**
   * 輸入典型的使用者問題
   * 觀察回覆長度與完整性
3. **評估結果**
   * 回覆是否完整？
   * 是否有不必要的冗長內容？
   * Token 消耗是否合理？
4. **逐步調整**
   * 過長→降低 Token 上限
   * 過短/截斷→提高 Token 上限
5. **持續監控**
   * 定期檢視使用狀況
   * 根據實際需求微調

#### 測試範例 <a href="#testing-examples" id="testing-examples"></a>

```
測試 1:Token 上限 256
使用者:請介紹一下你們公司
AI:我們是一家專注於 AI 技術的公司,提供企業級對話機器人解決方案。[回覆被截斷]
評估:太短,需提高

測試 2:Token 上限 1024
使用者:請介紹一下你們公司
AI:我們是一家專注於 AI 技術的公司...[完整詳細介紹]...歡迎聯繫我們了解更多。
評估:適中,採用
```

***

### 相關功能 <a href="#related-features" id="related-features"></a>

{% hint style="info" %}
**延伸功能**

* [建立 AI 助理](/build/setup.md)
* [角色指令設計指南](/build/system-prompt.md)
* [用量計算](/others/usage.md)
* [使用分析](/org/usage.md)
  {% endhint %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.maiagent.ai/build/custom-max-tokens.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
