Skip to content

[Bug] qq_offical 定时任务中 send_message_to_user 工具调用失败:"请求参数msg_id无效或越权" #6599

@naer-lily

Description

@naer-lily

What happened / 发生了什么

在定时任务(cron job)环境中调用 send_message_to_user 工具时,工具执行失败并抛出 botpy.errors.ServerError: 请求参数msg_id无效或越权 异常。该错误发生在 qq_offical 的消息发送流程中。

我注意到在 http://localhost:6185/#/cron页面右上角有提示 主动发送结果仅支持以下您已配置的平台:qq_official(QQ) / webchat(webchat),这似乎是说 qq_offical 本身是支持这个功能的?但文档 https://docs.astrbot.app/use/proactive-agent.html 中又并没有提到qq_offical……

Reproduce / 如何复现?

  1. 让AI 2分钟后连续调用2次send_message_to_user工具
  2. 2分钟后,观察到没有任何输出
  3. 检查控制台日志,发现上述报错

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

4.20.1 Docker Deepseek/deepseek-reasoner qq_offical

OS

Linux

Logs / 报错日志

[2026-03-19 12:32:41.708] [Core] [INFO] [runners.tool_loop_agent_runner:657]: Agent 使用工具: ['create_future_task']

[2026-03-19 12:32:41.709] [Core] [INFO] [runners.tool_loop_agent_runner:703]: 使用工具:create_future_task,参数:{'run_at': '2026-03-19T12:34:00+08:00', 'note': '2分钟后连续调用2次send_message_to_user工具测试。\n\n执行以下操作:\n1. 调用send_message_to_user工具,发送消息:"第一条测试消息:定时任务执行时间 2026-03-19 12:34:00"\n2. 再次调用send_message_to_user工具,发送消息:"第二条测试消息:连续调用测试完成"\n\n确保两条消息都能发送成功。', 'name': '连续调用send_message_to_user测试', 'run_once': True}

[2026-03-19 12:32:42.100] [Core] [INFO] [runners.tool_loop_agent_runner:881]: Tool `create_future_task` Result: Scheduled future task 67533b27-696c-4aeb-ae77-2d433c65e15a (连续调用send_message_to_user测试) one-time at 2026-03-19 12:34:00+08:00.

[2026-03-19 12:32:51.889] [Core] [INFO] [runners.tool_loop_agent_runner:657]: Agent 使用工具: ['send_message_to_user']

[2026-03-19 12:32:51.890] [Core] [INFO] [runners.tool_loop_agent_runner:703]: 使用工具:send_message_to_user,参数:{'messages': [{'type': 'plain', 'text': '那尔ちゃん,我已经设置好了定时任务。\n\n**任务详情:**\n- **任务ID**: 67533b27-696c-4aeb-ae77-2d433c65e15a\n- **执行时间**: 2分钟后(2026-03-19 12:34:00 CST)\n- **执行内容**: 连续调用2次send_message_to_user工具\n- **任务类型**: 一次性执行(run_once=true)\n\n(轻声)我会在12:34准时执行测试,然后向你汇报结果。如果到时没有收到消息,可能工具确实有问题,我们就能进一步排查了。'}]}

[2026-03-19 12:32:54.899] [Core] [INFO] [runners.tool_loop_agent_runner:881]: Tool `send_message_to_user` Result: Message sent to session QQ:FriendMessage:1F92E5124D83FC64DFE2A0EC30FA5EA1

[2026-03-19 12:33:09.136] [Core] [INFO] [result_decorate.stage:189]: 流式输出已启用,跳过结果装饰阶段

[2026-03-19 12:34:08.159] [Core] [INFO] [runners.tool_loop_agent_runner:657]: Agent 使用工具: ['send_message_to_user']

[2026-03-19 12:34:08.159] [Core] [INFO] [runners.tool_loop_agent_runner:703]: 使用工具:send_message_to_user,参数:{'messages': [{'type': 'plain', 'text': '第一条测试消息:定时任务执行时间 2026-03-19 12:34:00'}]}

[2026-03-19 12:34:08.354] [Core] [WARN] [v4.20.1] [runners.tool_loop_agent_runner:858]: Traceback (most recent call last):
  File "/AstrBot/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 757, in _handle_function_tools
    async for resp in executor:  # type: ignore
  File "/AstrBot/astrbot/core/astr_agent_tool_exec.py", line 175, in execute
    async for r in cls._execute_local(tool, run_context, **tool_args):
  File "/AstrBot/astrbot/core/astr_agent_tool_exec.py", line 596, in _execute_local
    resp = await asyncio.wait_for(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/AstrBot/astrbot/core/astr_agent_tool_exec.py", line 737, in call_local_llm_tool
    ret = await ready_to_call
          ^^^^^^^^^^^^^^^^^^^
  File "/AstrBot/astrbot/core/astr_main_agent_resources.py", line 385, in call
    await context.context.context.send_message(
  File "/AstrBot/astrbot/core/star/context.py", line 456, in send_message
    await platform.send_by_session(session, message_chain)
  File "/AstrBot/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py", line 144, in send_by_session
    await self._send_by_session_common(session, message_chain)
  File "/AstrBot/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py", line 287, in _send_by_session_common
    ret = await QQOfficialMessageEvent.post_c2c_message(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/AstrBot/astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py", line 566, in post_c2c_message
    result = await self.bot.api._http.request(route, json=payload)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/botpy/http.py", line 190, in request
    return await _handle_response(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/botpy/http.py", line 85, in _handle_response
    raise ServerError(message) from None  # adding from None to prevent chain exception being raised
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
botpy.errors.ServerError: 请求参数msg_id无效或越权

[2026-03-19 12:34:08.355] [Core] [INFO] [runners.tool_loop_agent_runner:881]: Tool `send_message_to_user` Result: error: 请求参数msg_id无效或越权

[2026-03-19 12:34:13.214] [Core] [INFO] [runners.tool_loop_agent_runner:657]: Agent 使用工具: ['send_message_to_user']

[2026-03-19 12:34:13.214] [Core] [INFO] [runners.tool_loop_agent_runner:703]: 使用工具:send_message_to_user,参数:{'messages': [{'type': 'plain', 'text': '第二条测试消息:连续调用测试完成'}]}

[2026-03-19 12:34:13.744] [Core] [WARN] [v4.20.1] [runners.tool_loop_agent_runner:858]: Traceback (most recent call last):
  File "/AstrBot/astrbot/core/agent/runners/tool_loop_agent_runner.py", line 757, in _handle_function_tools
    async for resp in executor:  # type: ignore
  File "/AstrBot/astrbot/core/astr_agent_tool_exec.py", line 175, in execute
    async for r in cls._execute_local(tool, run_context, **tool_args):
  File "/AstrBot/astrbot/core/astr_agent_tool_exec.py", line 596, in _execute_local
    resp = await asyncio.wait_for(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/AstrBot/astrbot/core/astr_agent_tool_exec.py", line 737, in call_local_llm_tool
    ret = await ready_to_call
          ^^^^^^^^^^^^^^^^^^^
  File "/AstrBot/astrbot/core/astr_main_agent_resources.py", line 385, in call
    await context.context.context.send_message(
  File "/AstrBot/astrbot/core/star/context.py", line 456, in send_message
    await platform.send_by_session(session, message_chain)
  File "/AstrBot/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py", line 144, in send_by_session
    await self._send_by_session_common(session, message_chain)
  File "/AstrBot/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py", line 287, in _send_by_session_common
    ret = await QQOfficialMessageEvent.post_c2c_message(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/AstrBot/astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py", line 566, in post_c2c_message
    result = await self.bot.api._http.request(route, json=payload)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/botpy/http.py", line 190, in request
    return await _handle_response(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/botpy/http.py", line 85, in _handle_response
    raise ServerError(message) from None  # adding from None to prevent chain exception being raised
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
botpy.errors.ServerError: 请求参数msg_id无效或越权

[2026-03-19 12:34:13.745] [Core] [INFO] [runners.tool_loop_agent_runner:881]: Tool `send_message_to_user` Result: error: 请求参数msg_id无效或越权

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

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:platformThe bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions