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

默认的 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. Toggle **长期记忆** 到 **开启**.
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 Editor 中运行你的场景。与角色开始对话，并分享角色应该记住的信息——例如：

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

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

{% step %}

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

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

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

角色应该能认出你的名字和角色，而无需你重复说明。
{% endstep %}
{% endstepper %}

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

***

### 编辑器中的身份工作方式

SDK 的默认 `DeviceEndUserIdProvider` 会自动处理身份。在 Play Mode 中，它会读取或创建一个持久化 GUID，存储在 `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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` 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>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
