> 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 角色启用长期记忆，并验证在 Unity Editor 中跨独立会话的回忆仍然有效。

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

### 前置条件

开始之前，请确认：

* [ ] 一个 `ConvaiCharacter` 已在场景中，并在 Inspector 中设置了其 Character ID
* [ ] 已在 Convai 控制面板中为你的角色启用了长期记忆 [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. 选中 **记忆** 选项卡，在角色设置侧边栏中。
3. 切换 **长期记忆** 为 **开**.
4. 保存角色。

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

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FOe3vEtLIt9dOZ91miZ9q%2Fimage.png?alt=media&amp;token=b12824ed-acdf-4e68-b341-faf642a75d9a" alt="Long-Term Memory toggle enabled in the Convai dashboard"><figcaption><p>Convai 控制面板中已启用长期记忆开关。</p></figcaption></figure>
{% endstep %}

{% step %}

#### 在 Play Mode 中开始对话

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

> “我的名字是 Jordan，我是夜班的安全官。”

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

{% step %}

#### 重新进入 Play Mode 并验证回忆

再次进入 Play Mode，并让角色引用它学到的内容：

> “你还记得我是谁吗？”

角色应该在你不重复姓名和角色的情况下认出它们。
{% endstep %}
{% endstepper %}

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

***

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

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

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

***

### 玩家构建中的身份

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

| 上下文             | 身份来源                                |
| --------------- | ----------------------------------- |
| Unity 编辑器       | `PlayerPrefs` GUID——每个项目稳定          |
| 玩家构建（设备 ID 可用）  | `SystemInfo.deviceUniqueIdentifier` |
| 玩家构建（设备 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 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-unity-sdk/features/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.
