使用 Playbook 构建代理

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

准备工作

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

  1. 如果您尚未完成,请按照设置说明操作。

Playbook 简介

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

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

创建代理

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

  1. 前往对话式 AI 助理控制台:

    对话代理控制台

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

  3. 点击创建代理

  4. 点击构建您自己的报告

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

  6. 提供位置

  7. 提供时区。

  8. 提供默认语言

  9. 对话开始选项选择Playbook

  10. 点击创建

  11. 界面会将您定向至名为 Default Generative Playbook 的默认 Playbook。

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

创建有序 Playbook

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

  1. 点击创建
  2. 输入 Playbook 名称:Order
  3. 输入以下目标:

    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.
    
  4. 输入以下说明:

    - 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.
    
  5. 点击保存

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

创建信息手册

信息手册可帮助您解决与商店相关的问题。 如需创建此 Playbook,请执行以下操作:

  1. 点击创建
  2. 输入 Playbook 名称:Information
  3. 输入以下目标:

    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.
    
  4. 输入以下说明:

    - 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.
    
  5. 点击保存

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

更新默认 Playbook

在您首次创建应用时,系统会为您创建一个默认的 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 的对话示例很短。 本手册只需将您定向到其他手册即可。如需与默认的 Playbook 对话,请执行以下操作:

  1. 关闭或取消屏幕右侧可能显示的任何面板。
  2. 点击顶行导航栏中的模拟器 按钮。
  3. 在“资源”中,选择默认的 Playbook。
  4. 使用默认模型或选择替代模型。
  5. 在标有输入用户输入内容的文本框中,输入 Hello,然后按 Enter 键。
  6. 该 Playbook 会回复问候语。

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

  1. 在模拟器面板的左侧,选择默认的 Playbook。
  2. 点击界面右上角附近的保存示例 按钮。
  3. 系统随即会打开示例编辑器面板。 您可以使用此编辑器添加、修改、删除或重新排列操作。
  4. 提供示例名称:Greeting
  5. 根据需要更新手册回复。
  6. 点击创建

为信息手册添加位置示例:

  1. 关闭或取消屏幕右侧可能显示的任何面板。
  2. 如有必要,请使用重置 restart_alt 按钮重置对话。
  3. 在模拟器中选择信息 Playbook。
  4. 输入消息:Where are you located?
  5. 该 Playbook 会响应一个位置。
  6. 在将此对话保存为示例之前,您必须删除包含“您在哪里”的操作。只有默认的 Playbook 示例可以从用户操作开始。
  7. 如需为示例提供发起对话的上下文,请展开输入和输出字段,然后在使用输入信息启动示例字段中输入以下内容:The customer asked "Where are you located?"
  8. 如需为示例提供完成对话的上下文,请在 End example with output information 字段中输入以下内容:The store is located at 1007 Mountain Drive, Gotham City, NJ.
  9. 提供示例名称:Location
  10. 点击创建

为信息手册添加营业时间示例:

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

为有序 playbook 添加一个选择示例:

  1. 类似于上述步骤,但将示例命名为 Selection,选择有序剧本,然后发送以下消息:

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

测试代理

您的客服人员现在可以进行测试了。打开模拟器面板,然后与客服人员对话。您无需与上述对话内容相同。例如,您可以询问此客服人员衬衫有哪些颜色。如果您未获得预期行为,请优化示例并创建新示例,以便获得更理想的回答。

使用 API 与代理互动

请参阅通过 API 进行互动