> 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-quick-start.md).

# 长期记忆快速开始

为 Unreal 角色设置长期记忆，分配稳定的玩家身份，并确认在 Play In Editor 会话之间的回忆。

为一个可正常运行的 Convai 角色设置长期记忆，然后在之后的“在编辑器中运行”会话中确认该角色能回忆起同一位玩家。

### 前提条件

* Convai Unreal Engine 插件版本 <code class="expression">space.vars.unreal\_plugin\_version</code> 已安装并配置了 API 密钥。请参阅 [安装 Convai Unreal Engine 插件](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/getting-started/install-the-convai-plugin.md).
* 关卡中包含一个 `UConvaiChatbotComponent` ，挂载在 AI 角色上；还包含一个 `UConvaiPlayerComponent` ，挂载在玩家 Actor 上。
* 聊天机器人组件具有有效的 `CharacterID` ，该 ID 来自 Convai 控制面板。

{% hint style="info" %}
本教程使用 Speaker ID 工作流。有关账号 ID 或设备回退策略，请参阅 [终端用户身份](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/end-user-identity.md)。Convai 控制面板中的新角色默认禁用记忆功能——测试回忆能力前请先启用该功能。
{% endhint %}

### 启用记忆并使用身份进行连接

{% stepper %}
{% step %}

#### 为角色启用 LTM

在开发用蓝图中，添加 **Convai Set LTM Status** ，该节点位于 `Convai|LTM` 类别中。

将 **Character ID** 设为 Convai 控制面板中的角色 ID。将 **B Enable** 设为 `true`。将 **On Success** 连接到一个 **Print String** 节点，以便确认请求已完成。

如需持续验证，请使用 **Convai Get LTM Status** 并传入相同的 **Character ID**.
{% endstep %}

{% step %}

#### 获取稳定的 EndUserID

在玩家首次使用项目时调用 **Convai Create Speaker ID** 。在 **On Success**时，将返回的 `SpeakerID` 从 `FConvaiSpeakerInfo` 保存到 `SaveGame` 或账号资料中。

之后再次启动时，加载已保存的 `SpeakerID` 而不是创建新记录。有关完整的创建、列出和删除工作流，请参阅 [说话人 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).
{% endstep %}

{% step %}

#### 分配身份并启动会话

调用 `StartSession`之前，将已保存的 `SpeakerID` 设为 `EndUserID` ，并在两个组件上都进行设置：

* 在 `EndUserID` 上设置 **Convai 聊天机器人** 组件，可在 Details 面板中设置，也可通过蓝图设置。
* 在 `EndUserID` 上设置 **Convai 玩家** 组件，可在 Details 面板中设置，也可通过蓝图设置。

聊天机器人的 `EndUserID` 是连接时发送给 Convai 的值。设置好这两个值后，在聊天机器人组件上调用 `StartSession` 。
{% endstep %}
{% endstepper %}

{% hint style="success" %}
满足以下条件时，设置即已就绪： **Convai Get LTM Status** 返回 `true` ，且在每次调用 `EndUserID` 之前，聊天机器人的 `StartSession`.
{% endhint %}

### 验证跨会话记忆

1. 按下 **播放**.
2. 告诉角色一条需要长期记住的信息，例如： `My name is Alex, and I inspect safety valves.`
3. 让对话继续一段时间，以便角色作出回应。
4. 停止在编辑器中播放。
5. 再次按下 **播放** 。
6. 在聊天机器人和玩家组件上恢复相同的 `EndUserID` ，然后再调用 `StartSession`.
7. 询问： `Do you remember what I inspect?`

角色应基于之前的信息作出回应。如果它重新开始，请参阅 [排查长期记忆问题](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).

### 后续步骤

{% content-ref url="/pages/9df4cda7b4a29ebef0a84953231ee1b61e2d4c9f" %}
[长期记忆的工作原理](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/how-long-term-memory-works.md)
{% endcontent-ref %}

{% 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/02906b279025410eed0c91dd64f1012b0304b626" %}
[为角色配置记忆](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/configure-memory-for-a-character.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-quick-start.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.
