> 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 控制面板](https://convai.com)

中为角色启用长期记忆 `默认的长期记忆体验无需编写任何代码。SDK 的` DeviceEndUserIdProvider [会自动生成稳定的标识符。如果你有身份验证系统并且需要提供自己的用户 ID，请参阅](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-identity.md) 终端用户身份

***

### 为角色启用记忆

{% 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 中，它会读取或创建一个持久化 GUID，并将其存储在 `PlayerPrefs` 中，使用的键为 `"convai.end_user_id"`。同一台计算机上的每次 Play Mode 会话都会使用同一个 GUID，因此记忆会跨会话累积，效果与真实用户的情况完全相同。停止 Play Mode 后，Convai 会处理对话，并将提取的信息保存为 `MemoryRecord` 条目。下次会话开始时，这些记录会注入角色的上下文，然后角色才会生成第一条回复。

只要 `PlayerPrefs` 不会被清除。清除 `PlayerPrefs` 或重新安装应用会生成新的 GUID，服务器会将其视为新用户，因此不会继承任何记忆。请参阅 [终端用户身份](https://docs.convai.com/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 无法在用户更换设备后继续跟随该用户。请参阅 [终端用户身份](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-identity.md) 了解实现详情。

***

### 后续步骤

{% content-ref url="/pages/c12fc9539ece3543a049cf5c334655c9bb0a6a3c" %}
[终端用户身份](https://docs.convai.com/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" %}
[为角色配置记忆](https://docs.convai.com/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" %}
[长期记忆的工作原理](https://docs.convai.com/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.
