本文展示如何使用 Mosaic AI 代理框架創建用於結構化數據檢索的 AI 代理工具 。 若要允許代理程式查詢結構化資料來源 (例如 SQL 資料表),您可以使用下列其中一種方法:
- SQL Unity 目錄函式:使用代理程式可以填入的參數來定義 SQL 查詢。 當查詢具有已知的固定格式時,請使用此方法。
使用 Unity 目錄 SQL 函式工具查詢資料
當查詢提前已知且代理程式提供參數時,使用 Unity 目錄 SQL 函式建立結構化擷取工具。
下列範例會建立名為 lookup_customer_info的 Unity 目錄函式,可讓 AI 代理程式從假設 customer_data 資料表擷取結構化資料。
在 SQL 編輯器中執行下列程式代碼。
CREATE OR REPLACE FUNCTION main.default.lookup_customer_info(
customer_name STRING COMMENT 'Name of the customer whose info to look up'
)
RETURNS STRING
COMMENT 'Returns metadata about a particular customer, given the customer's name, including the customer's email and ID. The
customer ID can be used for other queries.'
RETURN SELECT CONCAT(
'Customer ID: ', customer_id, ', ',
'Customer Email: ', customer_email
)
FROM main.default.customer_data
WHERE customer_name = customer_name
LIMIT 1;
建立 Unity 目錄工具之後,請將它新增至您的代理程式。 請參閱 建立代理程式工具。
Genie 多智能體系統
這很重要
這項功能目前處於 公開預覽版。
當您不知道代理需要回答哪種查詢,並且需要查詢多個表的靈活性時,創建一個包含 Genie 代理的多代理系統。
如需詳細資訊,請參閱在 多代理程式系統中使用 Genie。