Skip to content

fix: waking bot with a reply component and empty user prompt#8461

Merged
Soulter merged 5 commits into
AstrBotDevs:masterfrom
lingyun14beta:fix/quoted-message-trigger-llm
Jun 1, 2026
Merged

fix: waking bot with a reply component and empty user prompt#8461
Soulter merged 5 commits into
AstrBotDevs:masterfrom
lingyun14beta:fix/quoted-message-trigger-llm

Conversation

@lingyun14beta
Copy link
Copy Markdown
Contributor

@lingyun14beta lingyun14beta commented May 31, 2026

fix #8368
当用户引用任意消息并 @ Bot 但不附加文字时,消息链为 [Reply, At]message_str 为空,导致以下两个问题:

  1. internal.pymessage_str 为空时直接跳过 LLM 请求,即使消息链中包含 Reply 组件。
  2. astr_main_agent.py_decorate_llm_request 执行之前就检查内容是否为空,此时引用消息文字尚未注入 extra_user_content_parts,导致 build_main_agent 返回 None

Modifications / 改动点

  • astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py:新增 has_reply 判断,消息链含 Reply 组件时不跳过 LLM 请求。
  • astrbot/core/astr_main_agent.py:将空内容检查移至 _decorate_llm_request 之后,确保引用消息内容已注入后再判断;同时去掉群聊限制条件 not event.get_group_id()
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

image 正常回复

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Ensure LLM requests are triggered when users reply to a message and mention the bot without additional text.

Bug Fixes:

  • Prevent LLM requests from being skipped when the message contains only a reply and an @bot mention with no extra text.
  • Allow empty prompts to be replaced with a placeholder when there is a reply or extra user content, instead of aborting the main agent build.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels May 31, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In internal.py, the new has_reply condition will cause any reply-only message (even when the replied content is empty or non-user generated) to proceed to LLM; consider whether you should additionally check the replied message type/source to avoid unnecessary LLM invocations.
  • After moving _decorate_llm_request before the emptiness check in build_main_agent, verify that _decorate_llm_request is safe to call when req is initially empty and that it cannot introduce side effects (e.g., long-running operations) that should only occur when a real LLM request will be sent.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `internal.py`, the new `has_reply` condition will cause any reply-only message (even when the replied content is empty or non-user generated) to proceed to LLM; consider whether you should additionally check the replied message type/source to avoid unnecessary LLM invocations.
- After moving `_decorate_llm_request` before the emptiness check in `build_main_agent`, verify that `_decorate_llm_request` is safe to call when `req` is initially empty and that it cannot introduce side effects (e.g., long-running operations) that should only occur when a real LLM request will be sent.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for handling reply messages in the LLM request pipeline and adjusts the logic for detecting empty messages. However, moving _decorate_llm_request before the empty prompt check introduces a bug where system reminders are appended to extra_user_content_parts, causing empty messages to erroneously trigger LLM requests. It is recommended to keep the original execution order and instead check for Reply components directly during the empty prompt validation.

Comment thread astrbot/core/astr_main_agent.py Outdated
@lingyun14beta
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for handling message replies in the main agent and pipeline stages. A critical bug was identified in astrbot/core/astr_main_agent.py where replacing the check for req.extra_user_content_parts with has_reply would cause the bot to ignore other attachments like files or videos when there is no reply. The reviewer suggested combining both conditions and adding unit tests.

Comment thread astrbot/core/astr_main_agent.py Outdated
@lingyun14beta
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for handling Reply message components. It ensures that messages containing replies are not skipped as empty messages and sets the prompt to <attachment> when appropriate. There are no review comments, and I have no additional feedback to provide.

@Blueteemo
Copy link
Copy Markdown
Contributor

@sourcery-ai review

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 31, 2026

Hi @Blueteemo! 👋

Only authors and team members can run @sourcery-ai commands on public repos.

@zouyonghe
Copy link
Copy Markdown
Member

@sourcery-ai review

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The has_reply detection logic is now duplicated in both astr_main_agent.build_main_agent and internal.process; consider extracting a shared helper (e.g., message_has_reply(event.message_obj.message)) so future changes to what counts as a non-empty message (like additional reply-like components) stay consistent across the pipeline.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `has_reply` detection logic is now duplicated in both `astr_main_agent.build_main_agent` and `internal.process`; consider extracting a shared helper (e.g., `message_has_reply(event.message_obj.message)`) so future changes to what counts as a non-empty message (like additional reply-like components) stay consistent across the pipeline.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 1, 2026
@Soulter Soulter changed the title fix: 修复引用消息+@Bot无附加文字时无法触发LLM的问题 fix: waking bot with a reply component and empty user prompt Jun 1, 2026
@Soulter Soulter merged commit e4044cc into AstrBotDevs:master Jun 1, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]不响应@回复

4 participants