Skip to content

[Bug] Cron 场景下 send_message_to_user 容易因 session 参数格式被 LLM 填错而发送失败 #7907

@Aolinlu

Description

@Aolinlu

What happened / 发生了什么

在主动任务(cron)场景下,机器人会调用 send_message_to_user 发送消息。
当 LLM 显式传入了不完整的 session(例如只传 oc_xxx)时,工具会直接报错,导致消息无法发到目标群聊。
目前需要在提示词中强行约束“不要传 session 字段”才能稳定发送,这对用户来说不够友好,也不够鲁棒。

Reproduce / 如何复现?

创建一个群聊 cron 任务,让机器人定时发送消息。
观察某些执行中,LLM 调用 send_message_to_user 时会传 session=oc_xxx(而不是完整三段 session)。
工具返回错误,消息发送失败。

注,我是在飞书平台中测试的,在发布此 issue 两周前,机器人就开始无法由 cron 任务触发消息推送了。

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

AstrBot 版本:4.23.6
部署方式:命令行,通过 uv 安装后,通过命令行输入 astrbot run 运行

OS

Windows

Logs / 报错日志

[10:00:37.361] [Core] [INFO] [runners.tool_loop_agent_runner:975]: Agent 使用工具: ['send_message_to_user']
[10:00:37.361] [Core] [INFO] [runners.tool_loop_agent_runner:1025]: 使用工具:send_message_to_user,参数:{'messages': [...], 'session': 'oc_9xxxxxxxxxxxxxxxxxxxxxxx9a5'}
[10:00:37.363] [Core] [INFO] [runners.tool_loop_agent_runner:1222]: Tool 'send_message_to_user' Result: error: invalid session: not enough values to unpack (expected 3, got 1)

核心就是上面这几行,LLM 在调用 send_message_to_user 工具时,塞入了错误的 session,但是我在 cron 任务配置时,在 ”会话ID“ 字段,填写的是正确的,三段式的 ID(即 “platform_id: message_type:session_id” 格式),但是 LLM 调用时,仅将 session_id 部分塞到了 session 字段中,抛弃了前两段,导致报错。

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

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions