> 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).

# 长期记忆使用示例

将 Unreal 长期记忆模式应用于回归学习者、共享设备、首次会话和全新开始的重置流程。

在 [长期记忆快速入门](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/long-term-memory-quick-start.md) 正常工作后，使用以下模式。每个示例都侧重于在调用聊天机器人组件的 `StartSession`之前要设置哪些身份值。有关设置步骤，请参阅 [最终用户身份](https://docs.convai.com/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 Create Speaker ID** ，并将 **Speaker Name** 设为显示名称。
2. 在 **成功时**，保存返回的 `SpeakerID`.
3. 将两个组件的 `EndUserID` 设为已保存的值。
4. 调用 `StartSession`.

。完整的创建流程请参阅 [说话人 ID 管理](https://docs.convai.com/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 List Speaker IDs**.
2. 找到测试用的 `SpeakerID`.
3. 调用 **Convai Delete Speaker ID** 并传入该值。
4. 清除本地保存的 `SpeakerID`.

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

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

### 后续步骤

{% content-ref url="/pages/49e163546e7059153712733c44aa93aee597bbbe" %}
[终端用户身份](https://docs.convai.com/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" %}
[说话者 ID 管理](https://docs.convai.com/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" %}
[排查长期记忆问题](https://docs.convai.com/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 参考](https://docs.convai.com/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
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>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
