> 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-unity-sdk/features/long-term-memory/quick-start.md).

# 长期记忆快速入门

长期记忆在满足两个条件后会自动工作：在 Convai 仪表板上为你的角色启用记忆，并且 SDK 正在发送稳定的用户标识符。本指南将逐步说明这两个条件，并展示如何确认它们正在工作。

### 先决条件

开始前，请确认：

* [ ] A `ConvaiCharacter` 已在场景中，并且其 Character ID 已在检视器中设置
* [ ] 你的角色的长期记忆已在 [Convai 仪表板](https://convai.com)

对于默认的 LTM 体验，你无需编写任何代码。SDK 的 `DeviceEndUserIdProvider` 会自动生成一个稳定的标识符。参见 [终端用户身份](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-identity.md) 如果你有身份验证系统，并且需要提供自己的用户 ID。

***

### 为角色启用记忆

{% stepper %}
{% step %}

#### 在仪表板上启用记忆

1. 登录到 [convai.com](https://convai.com) 并打开你想要使用的角色。
2. 选择 **Memory** 角色设置侧边栏中的选项卡。
3. 切换 **长期记忆** 到 **在**.
4. 保存角色。

{% hint style="warning" %}
此设置会全局应用于该角色。任何连接到此角色 ID 的应用程序、SDK 版本和部署都会发送并接收记忆。在为共享角色启用之前，请先与你的团队协调。
{% endhint %}

<figure><img src="/files/0819dbfa38f741d656e8dbec8bb5e8219541f541" alt="Long-Term Memory toggle enabled in the Convai dashboard"><figcaption><p>Convai 仪表板中的长期记忆开关已启用。</p></figcaption></figure>
{% endstep %}

{% step %}

#### 在 Play 模式中开始对话

在 Unity 编辑器中运行你的场景。与角色开始对话，并分享角色应记住的信息——例如：

> "我叫 Jordan，我是夜班的安全主管。"

让对话自然结束，然后 **停止 Play 模式**。会话结束会触发 Convai 提取并存储你分享的事实。
{% endstep %}

{% step %}

#### 重新进入 Play 模式并验证回忆

再次进入 Play 模式，并让角色提及它学到的内容：

> "你还记得我是谁吗？"

角色应能识别你的姓名和角色，而无需你重复。
{% endstep %}
{% endstepper %}

{% hint style="success" %}
如果角色提到了上一会话中的细节，则长期记忆工作正常。
{% endhint %}

***

### 编辑器中的身份识别如何工作

SDK 的默认设置 `DeviceEndUserIdProvider` 会自动处理身份。在 Play 模式下，它会读取或创建一个持久化 GUID，存储在 `PlayerPrefs` 中的 GUID，键为 `"convai.end_user_id"`。同一台机器上的每个 Play 模式会话都使用相同的 GUID，因此记忆会像真实用户一样在会话之间累积。当你停止 Play 模式时，Convai 会处理对话并提取事实，作为 `MemoryRecord` 条目。下一次会话中，这些记录会在角色生成第一条回复之前被注入到其上下文中。

GUID 会一直保留，只要 `PlayerPrefs` 未被清除。清除 `PlayerPrefs` 或重新安装应用程序会生成一个新的 GUID，服务器会将其视为新用户——不会继承任何记忆。参见 [终端用户身份](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-identity.md) 有关在重新安装后仍然有效的策略。

***

### Player 构建中的身份识别

在 Player 构建中， `DeviceEndUserIdProvider` 首先尝试 `SystemInfo.deviceUniqueIdentifier`。如果该值不可用或无效，则回退到相同的 `PlayerPrefs` 在编辑器中使用的 GUID 方案。

| 上下文                  | 身份来源                                |
| -------------------- | ----------------------------------- |
| Unity 编辑器            | `PlayerPrefs` GUID——每个项目稳定          |
| Player 构建（设备 ID 可用）  | `SystemInfo.deviceUniqueIdentifier` |
| Player 构建（设备 ID 不可用） | `PlayerPrefs` GUID——在重新安装前保持稳定      |

对于用户通过账户登录的应用，请将 `DeviceEndUserIdProvider` 替换为一个返回你的账户 ID 的自定义提供程序。基于设备的 ID 无法跟随更换设备的用户。参见 [终端用户身份](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-identity.md) 了解实现细节。

***

### 下一步

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

{% content-ref url="/pages/b54beab8714c42a31356b3abe240c02692f3d79b" %}
[为角色配置记忆](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/configure-memory-for-a-character.md)
{% endcontent-ref %}

{% content-ref url="/pages/cb4d859b279841fc234bec92056ed917a73b519b" %}
[长期记忆的工作原理](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/how-long-term-memory-works.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-unity-sdk/features/long-term-memory/quick-start.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.
