> 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/database/link-chatbots-groups.md).

# 關聯 Agent 與群組權限

本篇將介紹如何將資料庫關聯至 Agent，以及如何透過群組權限控制資料庫的存取範圍

建立資料庫並設定好資料表後，您需要將資料庫**關聯至 Agent**，Agent 才能使用 Text to SQL 功能查詢資料。

## 關聯 Agent <a href="#link-ai-agent" id="link-ai-agent"></a>

### 操作步驟 <a href="#steps" id="steps"></a>

1. 進入資料庫設定頁面，切換至「<mark style="color:blue;">關聯 AI 助理</mark>」頁籤
2. 頁面左側顯示 <mark style="color:blue;">可選 AI 助理</mark>，右側顯示 <mark style="color:blue;">已選 AI 助理</mark>
3. 在左側勾選要關聯的 Agent，點擊「<mark style="color:blue;">新增 AI 助理</mark>」移至右側；要取消關聯時，在右側勾選後點擊「<mark style="color:blue;">移除 AI 助理</mark>」
4. 完成後點擊「<mark style="color:blue;">儲存</mark>」，右上角會顯示「已關聯 N 個助理」

{% hint style="info" %}
您可以使用搜尋欄位快速找到特定的 Agent。當 Agent 數量較多時，列表會分頁顯示。
{% endhint %}

{% hint style="warning" %}
請確保 Agent 的回答模式已切換至 **Agent 模式**，否則無法使用 Text to SQL 功能。

回答模式詳細說明請參考：[建立 Agent](/build/agent/setup.md)
{% endhint %}

### 多資料庫查詢 <a href="#multi-database-query" id="multi-database-query"></a>

一個 Agent 可以關聯多個資料庫。當使用者提問時，Agent 會根據問題內容自動判斷應該查詢哪個資料庫：

```
使用者：「上個月的銷售額是多少？」
→ AI 助理自動查詢「銷售資料庫」

使用者：「行銷部目前有幾位員工？」
→ AI 助理自動查詢「人事資料庫」
```

{% hint style="info" %}
為了讓 Agent 能準確區分不同資料庫，建議為每個資料庫取一個清楚描述其用途的名稱，並填寫詳細的描述及欄位描述。
{% endhint %}

## 角色權限管理 <a href="#group-permission-management" id="group-permission-management"></a>

資料庫設定頁的 「<mark style="color:blue;">角色權限</mark>」 頁籤（也就是群組權限）讓您控制組織中不同角色對資料庫的存取範圍，確保每個團隊只能看到與自己相關的資料庫。

### 設定角色權限 <a href="#configure-group-permission" id="configure-group-permission"></a>

1. 進入資料庫設定頁面，切換至「<mark style="color:blue;">角色權限</mark>」頁籤
2. 在左側 <mark style="color:blue;">可選角色</mark> 勾選要授權的角色，點擊「<mark style="color:blue;">新增角色</mark>」移至右側 <mark style="color:blue;">已選角色</mark>
3. 完成後點擊「<mark style="color:blue;">儲存</mark>」

{% hint style="info" %}
角色權限與「關聯 AI 助理」是獨立的設定。即使資料庫已關聯至某個 Agent，如果使用者所屬的角色沒有該資料庫的存取權限，使用者仍然無法查詢該資料庫。
{% endhint %}

### 權限層級 <a href="#permission-levels" id="permission-levels"></a>

資料庫的存取權限由以下條件共同決定：

```
使用者能否透過 AI 助理查詢資料庫？

✅ 資料庫已啟用
  └── ✅ 資料庫已關聯至該 AI 助理
       └── ✅ 使用者所屬角色擁有該資料庫的存取權限
            └── ✅ 可以查詢
```

* **資料庫擁有者**（建立者）可以存取自己建立的所有資料庫，不受角色權限限制
* **非擁有者**需要透過角色權限才能存取資料庫


---

# 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/database/link-chatbots-groups.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.
