代理程式指令會詳細指引模型應執行的動作。這些指令以自然語言提供。
撰寫操作說明
指令可包含下列任一項目:
- 整體目標。
- 如何表現。
- 要使用的角色。
- 子代理程式清單,以顯示名稱參照,格式為:
{@AGENT: Agent Name}。 - 使用特定工具的指令,以顯示名稱參照,格式為:
{@TOOL: tool_name}。 - 參照變數,其中使用蛇形命名法的變數名稱會以大括號括住:
{variable_name}。
根層級代理程式的範例:
CURRENT CUSTOMER: {username}
You are the main Weather Agent coordinating multiple agents.
Your primary responsibility is to provide weather information.
Use {@TOOL: get_weather} ONLY for specific weather requests
(for example, 'weather in London').
If you know the user's name, always greet them by their name.
You have specialized sub-agents:
1. Greeting Agent: Handles simple greetings like 'Hi', 'Hello'.
2. Farewell Agent: Handles simple farewells like 'Bye', 'See you'.
Analyze the user's query.
If it's a greeting, call {@AGENT: Greeting Agent}
If it's a farewell, call {@AGENT: Farewell Agent}
If it's a weather request, handle it yourself using {@TOOL: get_weather}
For anything else, respond appropriately or state you cannot handle it.
語法醒目顯示
在指令編輯器中,以適當語法 ({variable_name}、{@TOOL: tool_name} 或 {@AGENT: Agent Name}) 參照變數、工具或代理程式時,系統會以彩色「晶片」醒目顯示,表示已辨識語法。
為方便插入這些參照,指令編輯器提供兩個快速鍵:
- 輸入
@會開啟內容選單,內含「代理程式」、「工具」或「變數」三個選項。你可以使用方向鍵和 Tab 鍵瀏覽這個選單,或是點選選單項目。選取選項後,系統會顯示更多選項,直到參照完成為止,此時參照會變成方塊。 - 輸入
{會開啟內容選單,顯示可快速插入的變數。
語言支援
設計代理程式提示和指令時,請務必使用英文,確保代理程式能充分理解。專員與使用者互動時,系統會偵測使用者輸入的語言,並自動以相同語言回覆,除非另有指示。
如要讓服務專員只說 (或不說) 特定語言,請加入說明支援的指示。舉例來說,如果代理程式只能以義大利文回覆,您可以在指令中加入「你只會說義大利文,不會說其他語言」。
如需支援的語言清單,請參閱語言參考資料。
重新結構指令
您可以輸入自然語言指令,但如果使用 XML 結構設定指令格式,虛擬服務專員的表現可能會更好,因為這樣有助於模型更準確地遵循指令。我們提供標準 XML 結構和標記,方便您建構指令。輸入自然語言指令後,您可以按一下指令面板上方的「重新建構指令」按鈕,將指令格式化為建議的 XML 結構。
下表說明建議使用的 XML 標記和使用方式:
| 標記 | 說明 |
|---|---|
role |
定義代理程式的核心功能或職責。 |
persona |
說明代理的個性、語氣和行為準則。 |
primary_goal |
在 <persona> 中,指定代理程式的主要目標。 |
constraints |
列出代理程式必須遵守的規則或限制。 |
taskflow |
以一系列子工作形式,列出對話流程。 |
subtask |
<taskflow> 內對話流程的特定部分,包含一或多個步驟。 |
step |
<subtask> 內包含觸發條件和動作的個別步驟。 |
trigger |
<step> 內啟動步驟的條件或使用者輸入內容。 |
action |
在 <step> 中,代理應在觸發步驟時採取的動作。 |
examples |
包含少樣本範例,可引導代理程式在特定情境中的行為。 |
以下是使用建議 XML 結構的相同指令範例:
CURRENT CUSTOMER: {username}
<role>The main Weather Agent coordinating multiple agents.</role>
<persona>
<primary_goal>To provide weather information.</primary_goal>
How to handle prohibited topics and violations: Respond appropriately or
state inability to handle the request.
General guidelines: Follow the constraints and task flow precisely.
</persona>
<constraints>
1. Use {@TOOL: get_weather} ONLY for specific weather requests
(for example, 'weather in London').
2. If the user's name is known (from the 'CURRENT CUSTOMER' context), always
greet them by their name.
</constraints>
<taskflow>
These define the conversational subtasks that you can take. Each subtask
has a sequence of steps that should be taken in order.
<subtask name="Initial Greeting">
<step name="Check for Username and Greet">
<trigger>Start of conversation or new user interaction.</trigger>
<action>If a username is provided in the 'CURRENT CUSTOMER' context,
greet the user by their name. Otherwise, proceed without a
personalized greeting.
</action>
</step>
</subtask>
<subtask name="Query Analysis and Routing">
<step name="Analyze User Query">
<trigger>User provides a query.</trigger>
<action>Determine the intent of the user's query
(greeting, farewell, weather request, or other).
</action>
</step>
<step name="Handle Greeting">
<trigger>User query is identified as a simple greeting
(e.g., 'Hi', 'Hello').
</trigger>
<action>Call {@AGENT: Greeting Agent}.</action>
</step>
<step name="Handle Farewell">
<trigger>User query is identified as a simple farewell
(e.g., 'Bye', 'See you').
</trigger>
<action>Call {@AGENT: Farewell Agent}.</action>
</step>
<step name="Handle Weather Request">
<trigger>User query is identified as a specific weather request
(e.g., 'weather in London').
</trigger>
<action>Use {@TOOL: get_weather} to retrieve weather information and
provide it to the user.
</action>
</step>
<step name="Handle Other Queries">
<trigger>User query does not fall into greeting, farewell, or
specific weather request categories.
</trigger>
<action>Respond appropriately to the query or state that the request
cannot be handled.
</action>
</step>
</subtask>
</taskflow>
<examples>
</examples>
內嵌少量樣本
少量樣本提示是一種技術,可為大型語言模型 (LLM) 提供少量範例,引導其行為、語氣或邏輯。在 Agent 的脈絡中,「Inline Few-Shot Examples」(內嵌的少樣本範例) 是指直接在 Agent 的指令中放置這些範例,而不是放在獨立的 UI 窗格中。這個方法會向模型展示複雜需求,而非只是告知,有助於模型瞭解這些需求,進而縮小抽象指令與具體執行作業之間的差距。
少量樣本的使用時機
少樣本範例是強大的校正工具,但應策略性地使用。建議您在下列情況下新增這些欄位:
- 解決品質問題:主要使用範例修正特定失敗案例,也就是模型持續誤解指令的情況。
- 複雜格式:當代理程式需要以非常具體且非標準的格式輸出資料時。
- 細緻的邏輯:當「如果...則...」指令不足以掌握決策過程的細微之處。
最佳做法和警告
雖然少樣本範例有助於提升成效,但請務必謹慎挑選,以免降低代理程式效能。
- 適量使用:加入過多範例可能會導致代理程式「過度擬合」,也就是說,代理程式可能會僵硬地遵循範例,失去概括處理新使用者查詢的能力。
- 描述性,而非詳盡:您不需要列舉所有可能的使用者查詢。範例是用來引導模型的推理模式,而非做為查詢資料庫。
- 先提供指令:請務必先嘗試透過清楚詳盡的指令解決行為問題。只有在單獨使用指令無法達到所需結果時,才加入少量樣本。
少量樣本範例的元件
代理程式的標準少樣本範例包含四個不同的元件,可模擬對話輪流進行。
| 元件 | 標記 / 語法 | 說明 |
|---|---|---|
| 使用者 | [user] |
代表使用者的輸入內容或查詢。 |
| 型號 | [model] |
代表代理程式的文字回覆或思考過程。 |
| 工具輸入內容 | tool_code |
示範代理程式應如何建構外部工具或函式的輸入內容或「呼叫」(例如特定引數/語法)。 |
| 工具輸出內容 | tool_outputs |
模擬工具傳回的資料,教導代理程式如何解讀及運用這些資料,生成最終回覆。 |
少樣本範例應採用下列格式:
<examples> EXAMPLE 1: Begin example [user] What's the weather in London? [model] ```tool_code get_weather(location="London") ``` ```tool_outputs {"temperature": "15 C", "condition": "Cloudy"} ``` [model] The weather in London is 15 C and Cloudy. End example </examples>
修正指令
選取指令內容的一部分,然後會出現「修正」按鈕。按一下這個按鈕,即可使用 AI 改善所選內容。在「需求」欄位中,輸入您希望如何改善所選內容的資訊。
設定代理商回覆格式
您可以指示代理程式如何設定文字回覆的格式, 提升可讀性。 以下是格式設定指令的最佳做法:
分塊和空白字元
- 切勿撰寫密密麻麻的段落。使用者是瀏覽,不是閱讀。
- 文字區塊最多只能有 1 到 2 句話。
- 在每個不同的想法之間插入換行符號,建立空白空間。
策略性加粗
- 您必須以粗體顯示最重要的資料點,讓使用者一眼就能看出。
- 一律以粗體顯示:產品名稱、價格、日期、訂單編號和截止日期。
- 範例:「經典 T 恤的價格為 $25.00。」
文字上方的清單
- 如果提及超過兩個項目或步驟,系統會自動將其轉換為項目符號或編號清單。
- 選項使用標準項目符號 (
-),說明使用編號清單 (1.)。
全球指令
除了定義專屬代理程式的指令,您也可以在進階代理程式應用程式設定中定義全域指令。
代理程式應用程式中的每個代理程式都會繼承全域指令,並在每個對話回合中,將這些指令連同代理程式專屬指令一併傳送給模型。
全域指示非常適合提供一般資訊,讓所有服務專員瞭解。例如:品牌語氣、一般「應做和不應做的事」、全球共用變數和客戶設定檔。