Skip to content

Matrix 渠道未记录非@提及消息的聊天历史

问题

将 Agent 绑定到 Matrix 房间后,未直接 @ 机器人的消息不会被添加到 Agent 的上下文中。Agent 只能"看见"明确 @ 它的消息,无法感知对话背景,导致它在大多数群聊场景下形同"失聪"。

根本原因

Matrix 渠道只在非提及消息的 historyLimit 大于 0 时,才会将这些消息保存为待处理上下文(pending context)。

新安装的 OpenClaw 中,channels.matrix.historyLimitmessages.groupChat.historyLimit未设置(默认为 0),因此未被 @ 的消息全部被跳过,不会出现在 Agent 的后续对话上下文中。

解决方案

openclaw.json 中设置 channels.matrix.historyLimit(推荐 50-150 条):

json5
{
  channels: {
    matrix: {
      enabled: true,
      homeserver: "https://your-homeserver.com",
      userId: "@bot@your-homeserver.com",
      // 其他配置...
      historyLimit: 100,  // 👈 新增这一行
    },
  },
}

或者设置全局的群聊历史上限:

json5
{
  messages: {
    groupChat: {
      historyLimit: 100,
    },
  },
}

配置后重启 Gateway:

bash
openclaw gateway restart

说明:如果设置了非零值后仍然不生效,可能是更深层的 bug(不是配置问题)。建议升级到最新版本并在官方 issue #61000 中跟踪进展。

推荐值:historyLimit: 50 对大多数群组聊天场景足够,同时不会过度占用 Agent 上下文窗口。