> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/long-term-memory-usage-examples.md).

# 长期记忆使用示例

在……之后使用这些模式 [长期记忆快速入门](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/long-term-memory-quick-start.md) 正在工作。每个示例都侧重于在……之前应在聊天机器人组件上设置哪些身份值 `StartSession`。有关分配步骤，请参阅 [最终用户身份](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/end-user-identity.md).

### 培训模拟中的回访学员

安全培训模拟应记住，学员已经完成了阀门检查模块。

**设置：**

* 已为培训角色启用 LTM。
* 该学员已保存 `SpeakerID`.

**蓝图流程：**

1. 从 `SpeakerID` 学员的 `SaveGame` 或账户配置文件中加载。
2. 设置 `UConvaiChatbotComponent.EndUserID` 和 `UConvaiPlayerComponent.EndUserID` 为保存的值。
3. 调用 `StartSession` 在聊天机器人组件上。

**预期结果：** 该角色可以引用针对同一学员和角色在早期会话中学到的事实。

### 首次玩家配置文件

新玩家启动应用时，没有存储的身份。

**设置：**

* 项目已收集到一个显示名称，例如 `Alex`.
* 没有保存的 `SpeakerID` 存在于该配置文件中。

**蓝图流程：**

1. 调用 **Convai 创建 Speaker ID** 与 **Speaker 名称** 设置为显示名称。
2. 在 **成功时**，保存返回的 `SpeakerID`.
3. 将两个组件的 `EndUserID` 为保存的值。
4. 调用 `StartSession`.

完整创建工作流请参阅 [Speaker ID 管理](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/speaker-id-management.md).

**预期结果：** Convai 会为这个玩家和角色对创建一个独立的记忆范围。后续启动应复用已保存的 `SpeakerID`.

### 共享教室设备

多个学员在指导练习期间使用同一台机器。设备回退会合并他们的记忆，因此每个学员都需要明确的身份。

**设置：**

* 每个学员在与角色交互之前选择或登录一个配置文件。
* 每个配置文件都会存储自己的 `SpeakerID`.

**蓝图流程：**

1. 在选择配置文件时，加载该配置文件的 `SpeakerID`.
2. 将聊天机器人和玩家的 `EndUserID` 值设置为 `StartSession`.
3. 将每个配置文件的 `SpeakerID` 与同一设备上的其他配置文件分开保存。

**预期结果：** 即使所有学员都使用同一设备，角色也会分别记住每个学员。

### 基于账户的身份

企业入职应用已经有用户账户 ID，因此不需要 Speaker ID 记录。

**设置：**

* 账户系统提供稳定的用户 ID，例如 `employee-1042`.
* 账户 ID 在不同设备上不会改变。

**蓝图流程：**

1. 加载已登录用户的账户 ID。
2. 设置 `UConvaiChatbotComponent.EndUserID` 和 `UConvaiPlayerComponent.EndUserID` 为账户 ID。
3. 可选地将 `EndUserMetadata` 以相同的 JSON 字符串设置到两个组件上：

```json
{"name": "Jordan Kim", "department": "Facilities"}
```

4. 调用 `StartSession`.

**预期结果：** 记忆会跟随账户身份，而不是本地设备。

### 针对新场景尝试的全新开始

学员重复进行一次评估，应从全新的对话开始，同时保持相同的长期身份。

**设置：**

* 学员保留相同的 `SpeakerID` 或账户 ID。
* 项目不应恢复之前的会话。

**蓝图流程：**

{% tabs %}
{% tab title="蓝图" %}
调用 **重置对话** 在 **Convai 聊天机器人** 组件，然后调用 `StartSession`.
{% endtab %}

{% tab title="C++" %}

```cpp
// 示意——请将 ChatbotComponent 替换为你项目中的聊天机器人引用。
ChatbotComponent->ResetConversation();
ChatbotComponent->StartSession();
```

{% endtab %}
{% endtabs %}

**预期结果：** 下一次连接将从一个新的本地对话链接开始。玩家的身份保持不变，因此角色级长期记忆可以继续为该用户累积。

### 移除测试身份

在开发期间，删除通过反复 Speaker ID 实验创建的测试身份。

**蓝图流程：**

1. 调用 **Convai 列出 Speaker ID**.
2. 找到测试 `SpeakerID`.
3. 调用 **Convai 删除 Speaker ID** 以及该值。
4. 清除本地保存的 `SpeakerID`.

{% hint style="danger" %}
删除 Speaker ID 会移除该用户记录，以及该用户在所有角色中的相关长期记忆记录。可用于已确认的测试数据或用户请求删除流程。
{% endhint %}

**预期结果：** 该测试 `SpeakerID` 已从 Convai 中移除，且本地保存的身份已清除。

### 下一步

{% content-ref url="/pages/49e163546e7059153712733c44aa93aee597bbbe" %}
[最终用户身份](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/end-user-identity.md)
{% endcontent-ref %}

{% content-ref url="/pages/490cd1c53fd291cb3dcb57f385b0eee013c3ae74" %}
[Speaker ID 管理](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/speaker-id-management.md)
{% endcontent-ref %}

{% content-ref url="/pages/1207dad324341231dae358387602c84854559b9c" %}
[排查长期记忆问题](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/troubleshoot-long-term-memory.md)
{% endcontent-ref %}

{% content-ref url="/pages/d52ddbffaafeb3f6c5f97016d40633bc7ea09f16" %}
[LTM Blueprint 参考](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/ltm-blueprint-reference.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/long-term-memory-usage-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
