代理指令可为模型提供有关其应执行的操作的详细指导。这些指令以自然语言提供。
撰写说明
指令可以包含以下任何内容:
- 总体目标。
- 如何表现。
- 要使用的角色。
- 子代理的列表,按显示名称引用,格式为:
{@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})引用变量、工具或代理时,系统会使用彩色“块”突出显示相应内容,表示语法已被识别。
为了更轻松地插入这些参考,指令编辑器提供了两个快捷方式:
- 输入
@会打开一个上下文菜单,其中包含三个选项:Agent、Tool 或 Variable。您可以使用方向键和 Tab 键或通过点击来浏览此菜单。选择一个选项后,系统会显示更多选项,直到参考完成为止,届时该选项会变成一个 chip。 - 输入
{会打开一个上下文菜单,其中显示可供快速插入的变量。
语言支持
在设计代理提示和指令时,请务必使用英语,以便代理能够以最高质量理解这些提示和指令。 当代理与用户互动时,能够检测最终用户输入的语言,并自动使用相同的语言进行回复,除非另有明确指示。
如果您希望代理仅使用(或不使用)特定语言,则应添加说明来描述支持情况。 例如,如果您的代理只能用意大利语回答,您可以在指令中添加“你只会说意大利语,不会说其他语言”。
如需查看受支持的语言列表,请参阅语言参考。
重组说明
您可以输入自然语言指令,但如果使用 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) 提供少量示例来引导其行为、语气或逻辑。在代理的上下文中,“内嵌少样本示例”是指将这些示例直接放在代理的指令中,而不是放在单独的界面窗格中。这种方法通过展示而非仅仅告知来帮助模型理解复杂的要求,从而弥合抽象指令与具体执行之间的差距。
何时使用少样本示例
少样本示例是强大的校准工具,但应有策略地使用。在以下情况下,请考虑添加这些信息:
- 解决质量问题:主要使用示例来修复模型始终误解指令的特定失败情况。
- 复杂格式:当代理需要以非常特定的非标准格式输出数据时。
- 细致的逻辑:当“if-then”指令不足以捕捉决策过程的细微之处时。
最佳实践和警告
虽然少样本示例很有效,但应仔细挑选,以免降低代理的性能。
- 谨慎使用:添加过多的示例可能会导致代理“过拟合”,这意味着代理可能会严格遵循示例,而失去泛化到新的、未见过的用户查询的能力。
- 描述性,而非详尽无遗:您无需列出所有可能的用户查询。示例旨在为模型的推理模式提供指导,而不是作为查找数据库。
- 先下达指令:始终先尝试通过清晰的描述性指令来解决行为问题。只有在仅使用指令无法获得所需结果时,才添加 few-shot。
少样本示例的组成部分
代理的标准少样本示例包含四个不同的组件,用于模拟对话回合。
| 组件 | 标记 / 语法 | 说明 |
|---|---|---|
| 用户 | [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.) 表示说明。
全球说明
除了定义代理专属指令之外,您还可以在高级代理应用设置中定义全局指令。
代理应用中的每个代理都会继承全局指令,并且在每轮对话中,这些指令都会与代理专用指令一起发送给模型。
全局指令非常适合用于每个代理都需要了解的通用信息。例如:品牌基调、一般“注意事项”,全局共享变量和客户资料。