使用 playbook 构建和测试衬衫订购智能体。使用代理询问店面位置、获取营业时间或订购衬衫。
准备工作
如果您尚未按照设置说明操作,请执行此操作。
关于 playbook
一个智能体由一个或多个 playbook 组成。每个 playbook 都有明确定义且有限的范围。下表介绍了 playbook 中的数据:
| X | 项 |
|---|---|
| 名称 | 用于标识 playbook 的名称。 |
| 目标 | 目标是对 playbook 应实现的功能进行概括性描述。 |
| 说明 | 指令是为实现 playbook 的目标而应采取的简要步骤。 |
| 示例 | 示例是最终用户与智能体之间的对话样本。这些示例实际上是 LLM 的少样本提示词示例。 |
创建代理
如需创建代理,请执行以下操作:
- 前往 https://conversational-agents.cloud.google.com。
- 如果您尚未选择或创建项目,请先选择或创建一个。
- 点击 Create agent。
- 点击自行构建。
- 输入“Shirt Ordering - Playbooks”作为代理名称。
- 输入位置。
- 输入时区。
- 输入默认语言。
- 对于对话发起选项,选择 Playbook。
- 点击创建。
- 界面会将您转到名为默认生成式 AI 行动指南 的默认 playbook。
- 点击返回,返回到 playbook 列表。
创建订单 playbook
Order playbook 负责处理衬衫订单。
如需创建 playbook,请执行以下操作:
- 点击创建。
- 选择任务 playbook 选项。
- 输入 playbook 名称:
Order。 输入以下目标:
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.输入以下指令:
- 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.点击保存。
点击返回,返回到 playbook 列表。
创建信息 playbook
信息 playbook 用于处理有关商店的问题。
如需创建 playbook,请执行以下操作:
- 点击创建。
- 选择任务 playbook 选项。
- 输入 playbook 名称:
Information。 输入以下目标:
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.输入以下指令:
- 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.点击保存。
点击返回,返回到 playbook 列表。
更新默认 playbook
首次创建代理时,系统会为您创建一个默认 playbook。此 playbook 会将对话引导至具有特定目标的适当 playbook。您可以在以下说明中了解默认 playbook 如何引用其他 playbook。
如需更新 playbook,请执行以下操作:
- 点击默认 playbook(标有星号)。
输入以下目标:
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.输入以下指令:
- 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}点击保存。
请注意,由于尚无示例,因此 playbook 引用会突出显示;您将在下一部分中添加这些示例。
点击返回,返回到 playbook 列表。
举例说明
该 playbook 可以正常运行,但提供示例可确保回答质量。
您可以在 playbook 打开时从示例标签页中提供示例;不过,与智能体进行对话并将对话保存为示例通常更容易。
默认 playbook 对话很简短。此 playbook 需要将对话定向到另一个 playbook。
如需与默认 playbook 进行对话,请执行以下操作:
- 关闭或取消屏幕右侧可能存在的任何面板。
- 点按顶部导航栏中的模拟器 按钮。
- 对于资源,请选择默认 playbook。
- 使用默认模型或选择其他模型。
- 在输入用户输入字段中,输入
Hello,然后按 Enter 键。 - Playbook 会给出问候语。
如需将此对话保存为示例,请执行以下操作:
- 在调用列表中选择默认 playbook。
- 点击另存为示例。
- 在示例编辑器面板中,添加、修改、删除操作或对操作重新排序。
- 输入
Greeting作为示例名称。 - 根据需要更新 playbook 回答。
- 在以输出信息结束示例部分,在摘要字段中输入
The user is greeted.。 - 点击保存。
为信息 playbook 添加位置信息示例:
- 关闭或取消屏幕右侧的任何面板。
- 如有必要,请使用重置 restart_alt 按钮重置对话。
- 在模拟器的启动资源菜单中选择信息 playbook。
- 输入
Where are you located?,然后按 Enter 键。 - 在调用菜单中选择信息 playbook。
- 点击另存为示例。
- 输入
Location作为示例名称。 - 删除包含
Where are you located?的操作,因为只有默认 playbook 示例可以从用户操作开始。 - 展开上述对话的摘要部分,然后在以输入信息开始示例字段中输入
The customer asked "Where are you located?"。 - 展开 playbook 执行摘要部分,然后在包含输出信息的结束示例字段中输入
The store is located at 1007 Mountain Drive, Gotham City, NJ.。 - 点击保存。
为信息 playbook 添加营业时间示例:
- 在模拟器中选择信息 playbook。
- 输入消息
What are your hours?。 - 将对话保存为名为
Hours的示例。
按照以下步骤为订单 playbook 添加选择示例:
- 将示例命名为
Selection。 - 选择订单 playbook。
- 发送以下消息:
I want to buy a shirtLargeGreenYes
测试代理
您的代理现在可以进行测试了。打开模拟器面板,与智能体对话。您可以进行与前面所述不同的对话。例如,您可以询问此代理衬衫有哪些颜色。如果您没有获得所需的结果, 优化或添加样本将改进回答
使用 API 与智能体互动
如需详细了解如何与 API 交互,请参阅与 API 交互。