Skip to content

Conversation

@advent259141
Copy link
Member

@advent259141 advent259141 commented Jan 6, 2026

Motivation / 动机

修复了在 OnLLMResponseEvent 钩子中调用 stop_event() 后,本轮对话仍会被保存到上下文的问题。

之前的行为:当插件在 OnLLMResponseEvent 钩子中调用 event.stop_event() 时,虽然本次回复不会输出给用户,但对话历史(包括用户消息和 LLM 响应)仍然会被保存到会话上下文中,导致后续对话会包含这次被"停止"的对话内容。

期望行为:调用 stop_event() 后,本轮对话既不输出,也不保存到上下文。

Modifications / 改动点

核心文件修改:*

  • astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py

    • 在调用 _save_to_history() 前增加 event.is_stopped() 检查
    • 只有在事件未被停止时才保存对话历史到会话上下文
  • This is NOT a breaking change. / 这不是一个破坏性变更。

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


Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

错误修复:

  • 当事件已被标记为停止时,跳过保存会话历史,确保已停止的回复既不会被输出,也不会存储在上下文中。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Skip saving conversation history when an event has been marked as stopped, ensuring stopped responses are neither output nor stored in context.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jan 6, 2026
Copy link
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.

你好——我已经审查了你的更改,一切看起来都很棒!


Sourcery 对开源项目是免费的——如果你觉得我们的审查有帮助,请考虑分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的审查。
Original comment in English

Hey - I've reviewed your changes and they look great!


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 area:core The bug / feature is about astrbot's core, backend label Jan 6, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 7, 2026
@Soulter Soulter merged commit eefa3f2 into AstrBotDevs:master Jan 7, 2026
6 checks passed
@Soulter Soulter changed the title fix: 修复 stop_event 后对话仍保存到上下文的问题 fix: conversation was still saved to the context after stop_event Jan 7, 2026
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.

2 participants