使用 Playbook 构建代理

本指南介绍了如何使用 playbook 构建和测试简单的衬衫订购代理。 与此代理互动时,您可以查询商店位置、获取商店营业时间或创建衬衫订单。

准备工作

在阅读本指南之前,请先完成以下事项:

  1. 如果您尚未进行初始配置,请按照设置说明操作。

关于 playbook

代理由一个或多个 playbook 组成。 每个 playbook 都有明确定义的有限范围。操作手册包含以下数据:

X
名称 用于标识 playbook 的名称。
目标 目标是对 playbook 应实现的目标的简要说明。
说明 说明是为实现剧本目标而应采取的高级步骤。
示例 示例是指最终用户与代理之间的对话示例。这些示例实际上是 LLM 的少样本提示示例。

创建代理

如需创建代理,请执行以下操作:

  1. 前往 Conversational Agents 控制台:

    对话智能体控制台

  2. 如果您尚未选择或创建项目,请选择或创建一个项目。

  3. 点击 Create agent

  4. 点击自行构建

  5. 为代理名称提供“Shirt Ordering - Playbooks”。

  6. 提供位置

  7. 提供时区。

  8. 提供默认语言

  9. 对话发起选项选择 Playbook

  10. 点击创建

  11. 界面会将您带到名为 Default Generative Playbook 的默认 playbook。

  12. 点击返回按钮,查看 playbook 列表。

创建订单 playbook

Order playbook 用于处理衬衫订单。如需创建此 playbook,请执行以下操作:

  1. 点击创建
  2. 选择任务策略方案选项。
  3. 输入 playbook 名称:Order
  4. 输入以下目标:

    You are a shirt store ordering assistant. Help customers purchase shirts.
    Help the customer choose a size and color.
    The shirts come in small, medium, and large.
    The shirts can be red, green, or blue.
    
  5. 输入以下指令:

    - If the customer has not provided a size, ask them to choose a size.
    - If the customer has not provided a color, ask them to choose a color.
    - Once the customer has selected a size and color for the shirt,
      repeat the selection to the customer, and ask them to confirm the selection.
    - Once the customer has confirmed their selection,
      let them know that the shirt is now ordered.
    - Do not provide prices or collect payment.
    - Do not collect the customer's name or address.
    
  6. 点击保存

  7. 点击返回按钮,返回到剧本列表。

创建信息 playbook

信息 playbook 用于处理有关商店的问题。如需创建此 playbook,请执行以下操作:

  1. 点击创建
  2. 选择任务策略方案选项。
  3. 输入 playbook 名称:Information
  4. 输入以下目标:

    You provide information about a shirt store.
    The store is open between 8 AM and 6 PM every day.
    The store is located at 1007 Mountain Drive, Gotham City, NJ.
    
  5. 输入以下指令:

    - If the customer asks for the store location, provide them with the address.
    - If the customer asks for the store hours, provide them with the hours.
    
  6. 点击保存

  7. 点击返回按钮,返回到剧本列表。

更新默认 playbook

您首次创建应用时,系统会为您创建默认剧本。此 playbook 应将对话引导至具有特定目标的相应 playbook。 在下面的说明中,您可以看到默认 playbook 如何引用其他 playbook。如需更新本指南,请执行以下操作:

  1. 点击默认 playbook。此 playbook 带有突出显示的星标。
  2. 输入以下目标:

    You are an assistant for a shirt store.
    Your name is "Samantha".
    Your job is to direct customers to other playbooks based on the customer's questions.
    
  3. 输入以下指令:

    - If the customer hasn't been greeted yet, greet the customer,
      introduce yourself, and ask the user how you can help.
    - If the customer wants information about the store,
      route them to ${PLAYBOOK: Information}
    - If the customer wants to purchase a shirt,
      route them to ${PLAYBOOK: Order}
    
  4. 点击保存

  5. 请注意,由于目前还没有示例,因此 playbook 参考突出显示。我们将在下一部分中添加这些内容。

  6. 点击返回按钮,返回到剧本列表。

举例说明

至此,您的剧本已可正常运行。 不过,您必须提供示例,才能确保回答质量。

当您打开 playbook 时,可以从示例标签页中手动提供示例。 不过,通常情况下,与正常运行的 playbook 进行对话并保存对话内容作为示例会更简单。

使用默认剧本的对话示例很简短。此 playbook 只需要引导您前往另一个 playbook。 如需与默认 playbook 对话,请执行以下操作:

  1. 关闭或取消屏幕右侧可能显示的任何面板。
  2. 点击顶部导航栏中的模拟器 按钮。
  3. 对于资源,请选择默认 playbook。
  4. 使用默认模型或选择其他模型。
  5. 在显示输入用户输入内容的文本框中,输入 Hello,然后按 Enter 键。
  6. 剧本会以问候语做出响应。

如需将此对话保存为示例,请执行以下操作:

  1. 调用下拉菜单中选择默认 playbook。
  2. 点击界面右上角附近的另存为示例按钮。
  3. 系统随即会打开示例编辑器面板。 您可以使用此编辑器添加、修改、删除或重新排序操作。
  4. 提供示例名称:Greeting
  5. 根据需要更新 playbook 响应。
  6. 向下滚动到包含输出信息的结束示例,然后在摘要部分中输入 The user is greeted.
  7. 点击“保存”图标。

为信息剧本添加位置信息示例:

  1. 关闭或取消屏幕右侧可能显示的任何面板。
  2. 如有必要,请使用重置 restart_alt 按钮重置对话。
  3. 在模拟器的初始资源下拉菜单中选择信息 playbook。
  4. 输入消息:Where are you located?
  5. 剧本会返回一个位置。
  6. 调用下拉菜单中选择信息 playbook。
  7. 点击另存为示例按钮。
  8. 提供示例名称:Location
  9. 在将此对话保存为示例之前,您必须删除包含“您位于何处”的操作。只有默认的 playbook 示例才能通过用户操作启动。
  10. 如需为示例提供启动对话的上下文,请展开前次对话的摘要... 部分,然后在以输入信息开始示例字段中输入以下内容:The customer asked "Where are you located?"
  11. 为了提供可完成对话的上下文示例,请展开 playbook 执行摘要...部分,然后在以输出信息结束示例字段中输入以下内容:The store is located at 1007 Mountain Drive, Gotham City, NJ.
  12. 点击“保存”图标。

为信息剧本添加了小时数示例:

  1. 与上述步骤类似,但输入消息:What are your hours?,并将示例命名为:Hours

为订单 playbook 添加选择示例:

  1. 与上述步骤类似,但将示例命名为 Selection,选择订单剧本,并发送以下消息:

    • I want to buy a shirt
    • Large
    • Green
    • Yes

测试代理

您的代理现在可以进行测试了。 打开模拟器面板,然后与智能体对话。您无需进行与上述相同的对话。 例如,您可以询问此代理衬衫有哪些颜色可供选择。如果您未获得所需的效果,请优化示例并创建新示例,以改进回答。

使用 API 与代理互动

请参阅通过 API 进行互动