> 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/configure-memory-for-a-character.md).

# 为角色配置记忆

介绍如何通过控制面板或脚本为角色开启或关闭长期记忆，以及全局作用范围对共享角色意味着什么。

长期记忆默认处于禁用状态（`MemorySettings.IsEnabled = false`）。在你明确启用之前，不会提取或存储任何事实。你可以通过 Convai 控制台启用或禁用记忆，也可以通过以下方式以编程方式操作： `client.Characters`.

{% hint style="danger" %}
**记忆设置会全局应用于该角色。** 为某个角色启用长期记忆会影响所有连接到该角色 ID 的应用程序、SDK 版本和部署。如果你在开发、预发布和生产环境中共用同一个角色，那么在其中一个环境中启用记忆后，所有环境都会启用。启用共享角色的记忆前，请先与团队协调。
{% endhint %}

***

### 启用或禁用记忆

{% tabs %}
{% tab title="控制台" %}
对于大多数团队，建议采用此方法。更改会立即生效，无需更新代码或重新部署。

1. 登录 [convai.com](https://convai.com).
2. 打开要配置的角色。
3. 在角色设置侧边栏中选择 **记忆** 选项卡。
4. 将 **长期记忆** 切换为 **开启**.
5. 点击 **保存**.

如需禁用，请重复相同步骤，并将 **长期记忆** 切换为 **关闭**.
{% endtab %}

{% tab title="脚本" %}
如果你需要以编程方式控制（例如在自动化测试环境、构建流水线或运行时管理面板中），请使用 `client.Characters` 。 `ConvaiRestClient.Characters` 已标记为 `[Obsolete]` ，推荐改用 `ConvaiCharacterApiClient`，因此这段代码编译时会出现 `CS0618` 警告；目前它仍是读取和写入此设置的唯一强类型访问器。

**检查当前状态**

```csharp
using Convai.RestAPI;
using UnityEngine;

public class MemoryAdmin : MonoBehaviour
{
    private async void Start()
    {
        using var client = new ConvaiRestClient(ConvaiSettings.Instance.ApiKey);

        bool isEnabled = await client.Characters.GetMemoryEnabledAsync("your-character-id");
        Debug.Log($"LTM enabled: {isEnabled}");
    }
}
```

**启用记忆**

```csharp
using Convai.RestAPI;
using UnityEngine;

public class MemoryAdmin : MonoBehaviour
{
    private async void Start()
    {
        using var client = new ConvaiRestClient(ConvaiSettings.Instance.ApiKey);

        await client.Characters.SetMemoryEnabledAsync("your-character-id", true);
        Debug.Log("Long-term memory enabled.");
    }
}
```

**禁用记忆**

```csharp
await client.Characters.SetMemoryEnabledAsync("your-character-id", false);
```

{% endtab %}
{% endtabs %}

***

### 禁用记忆但不删除记录

{% hint style="warning" %}
禁用长期记忆会停止提取新的记忆，但 **不会删除现有记忆记录**。已存储的事实仍会保留在 Convai 中；如果之后重新启用长期记忆，这些事实将再次注入。

如果你想禁用长期记忆并移除所有已存储的记忆，请先删除记忆，再禁用。
{% endhint %}

如需在禁用前清除某个用户与角色组合的所有记忆，请使用 `client.Memory.DeleteAllAsync` ，然后调用 `SetMemoryEnabledAsync`. `DeleteAllAsync` 会删除某个特定用户与角色组合的记忆。若要改为删除所有角色下的全部终端用户记录，请使用 `client.EndUsers.DeleteAsync(endUserId)`。请参阅 [管理终端用户记录](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-management.md).

请参阅 [长期记忆使用示例](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/usage-examples.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/49cef55d22f33c0ffdf4893701cd5a6686bd7590" %}
[管理终端用户记录](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-management.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/configure-memory-for-a-character.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.
