使用 Playbook 构建代理

使用 playbook 构建和测试衬衫订购代理。使用该代理查询商店位置、获取商店营业时间或下衬衫订单。

准备工作

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

关于 playbook

一个代理由一个或多个 playbook 组成。每个 playbook 都有明确定义的有限范围。下表介绍了 playbook 中的数据:

X 推荐项
名称 用于标识 playbook 的名称。
目标 目标是对 playbook 应实现的功能进行概括性描述。
说明 说明是为实现 playbook 的目标而应采取的概要步骤。
示例 示例是最终用户与代理之间的对话示例。这些示例实际上是大语言模型的少样本提示示例。

创建代理

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

  1. 前往 https://conversational-agents.cloud.google.com。
  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. 选择任务 playbook 选项。
  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

Information playbook 用于处理有关商店的问题。

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

  1. 点击创建
  2. 选择任务 playbook 选项。
  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。您可以按照以下说明查看默认 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 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。

如需与默认 playbook 进行对话,请执行以下操作:

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

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

  1. 调用 列表中选择默认 playbook。
  2. 点击另存为示例
  3. 在示例编辑器面板中,添加、修改、删除或重新排序操作。
  4. 输入 Greeting 作为示例名称。
  5. 根据需要更新 playbook 响应。
  6. 以输出信息结束示例 部分中,在摘要 字段中输入 The user is greeted.
  7. 点击保存

为信息 playbook 添加位置示例:

  1. 关闭或取消屏幕右侧的任何面板。
  2. 如有必要,请使用 reset restart_alt 按钮重置对话。
  3. 在模拟器的开始资源 菜单中选择信息 playbook。
  4. 输入 Where are you located?,然后按 Enter 键。
  5. 调用 菜单中选择信息 playbook。
  6. 点击另存为示例
  7. 输入 Location 作为示例名称。
  8. 删除包含 Where are you located? 的操作,因为只有默认 playbook 示例可以以用户操作开头。
  9. 展开 先前对话的摘要 部分,然后在 以输入信息开始示例 字段中输入 The customer asked "Where are you located?"
  10. 展开 playbook 执行摘要 部分,然后在 以输出信息结束示例 字段中输入 The store is located at 1007 Mountain Drive, Gotham City, NJ.
  11. 点击保存

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

  1. 在模拟器中选择信息 playbook。
  2. 输入消息 What are your hours?
  3. 将对话保存为名为 Hours 的示例。

按照以下步骤为订单 playbook 添加选择示例:

  1. 将示例命名为 Selection
  2. 选择订单 playbook。
  3. 发送以下消息:
    • I want to buy a shirt
    • Large
    • Green
    • Yes

测试代理

您的代理现已准备就绪,可以进行测试。打开模拟器面板,与代理进行对话。您可以进行与前面描述的对话不同的对话。例如,您可以询问此代理衬衫有哪些颜色可供选择。如果您没有获得所需的结果,则优化或添加示例将有助于改进响应。

使用 API 与代理互动

如需详细了解如何与 API 互动,请参阅 与 API 的互动