AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug]send_message_to_user 工具调用不触发合并转发消息

Open lingyun14beta opened this issue 5 months ago • 3 comments

What happened / 发生了什么

当 LLM 通过普通文本回复时,若回复字数超过 platform_settings.forward_threshold(默认 1500 字),AstrBot 会自动将消息包装为 QQ 合并转发消息(send_group_forward_msg)以防止刷屏。

但当 LLM 调用内置工具 send_message_to_user 发送消息时,无论内容多长,都不会触发合并转发,消息会以普通消息形式直接发出。

Reproduce / 如何复现?

  1. 使用 aiocqhttp(OneBot V11)平台适配器
  2. 将 platform_settings.forward_threshold 设置为较小的值(如 100)
  3. 让 LLM 调用 send_message_to_user 工具发送超过阈值字数的纯文本内容
  4. 观察消息以普通消息发出,而非合并转发

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

winnnn

OS

Windows

Logs / 报错日志

none

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • [ ] Yes!

Code of Conduct

lingyun14beta avatar Jun 08 '26 11:06 lingyun14beta

确认这是一个已知的架构问题。

根本原因:send_message_to_user 工具通过 Context.send_message() → platform.send_by_session() 直接调用平台适配器发送消息,完全绕过了事件处理管线(Pipeline),而 forward_threshold 的检查逻辑位于管线中的 ResultDecorateStage 阶段 [1]。

两条发送路径对比:

  • 普通 LLM 回复:经过完整管线 → ResultDecorateStage 检测字数 → 超阈值时包装为 Node → aiocqhttp 适配器调用 send_group_forward_msg [2]
  • send_message_to_user:Context.send_message() [3] → 直接调用 AiocqhttpMessageEvent.send_message() → bot.send_group_msg() / bot.send_private_msg(),跳过所有管线阶段

这意味着不仅 forward_threshold 被绕过,速率限制、内容安全检查等管线阶段也同样不会对主动消息生效 [4]。

可能的修复方向:在 Context.send_message() 或 send_message_to_user 工具内部,对 aiocqhttp 平台手动添加 forward_threshold 检查逻辑(将超长消息包装为 Node),或者让主动消息也走部分管线阶段。

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about AstrBot with Dosu Add Dosu to your team

dosubot[bot] avatar Jun 08 '26 11:06 dosubot[bot]

让我试试修复这个bug

Dr1985 avatar Jun 09 '26 05:06 Dr1985

让我试试修复这个bug

请提交pr

NayukiChiba avatar Jun 19 '26 12:06 NayukiChiba