fix: waking bot with a reply component and empty user prompt#8461
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
internal.py, the newhas_replycondition 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_requestbefore the emptiness check inbuild_main_agent, verify that_decorate_llm_requestis safe to call whenreqis 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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.
|
/gemini review |
There was a problem hiding this comment.
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.
|
/gemini review |
There was a problem hiding this comment.
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.
|
@sourcery-ai review |
|
Hi @Blueteemo! 👋 Only authors and team members can run @sourcery-ai commands on public repos. |
|
@sourcery-ai review |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
has_replydetection logic is now duplicated in bothastr_main_agent.build_main_agentandinternal.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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
fix #8368
当用户引用任意消息并 @ Bot 但不附加文字时,消息链为
[Reply, At],message_str为空,导致以下两个问题:internal.py在message_str为空时直接跳过 LLM 请求,即使消息链中包含Reply组件。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()。Screenshots or Test Results / 运行截图或测试结果
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.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.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: