Skip to content

Conversation

@Soulter
Copy link
Member

@Soulter Soulter commented Oct 4, 2025

fixes: #2940


Motivation / 动机

修复 on_tool_end无法获得工具返回的结果的问题。这是由于参数传递错误导致的。

Modifications / 改动点

Verification Steps / 验证步骤

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

Compatibility & Breaking Changes / 兼容性与破坏性变更

  • 这是一个破坏性变更 (Breaking Change)。/ This is a breaking change.
  • 这不是一个破坏性变更。/ This is NOT a breaking change.

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.

@auto-assign auto-assign bot requested review from Raven95676 and anka-afk October 4, 2025 16:36
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.

你好 - 我已审阅了你的更改 - 以下是一些反馈:

  • 如果工具没有产生 CallToolResult,新的 _final_resp 变量可能仍为 None,因此在调用 on_tool_end 之前明确处理或保护该情况,以避免意外传递 None。
  • 考虑提取一个辅助函数来追加 ToolCallMessageSegment 块,以减少 resp 处理分支中的重复并提高可读性。
  • 避免在执行器循环上使用通用的 '# type: ignore';而是完善执行器的类型注释以保持类型安全。
供 AI 代理使用的提示
请处理此代码审查中的评论:

## 总体评论
- 如果工具没有产生 CallToolResult,新的 _final_resp 变量可能仍为 None,因此在调用 on_tool_end 之前明确处理或保护该情况,以避免意外传递 None。
- 考虑提取一个辅助函数来追加 ToolCallMessageSegment 块,以减少 resp 处理分支中的重复并提高可读性。
- 避免在执行器循环上使用通用的 '# type: ignore';而是完善执行器的类型注释以保持类型安全。

Sourcery 对开源免费 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English

Hey there - I've reviewed your changes - here's some feedback:

  • The new _final_resp variable may remain None if the tool yields no CallToolResult, so explicitly handle or guard that case before calling on_tool_end to avoid passing None unexpectedly.
  • Consider extracting a helper function for appending ToolCallMessageSegment blocks to reduce duplication in the resp handling branches and improve readability.
  • Avoid using a blanket '# type: ignore' on the executor loop; refine the executor’s type annotations instead to maintain type safety.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new _final_resp variable may remain None if the tool yields no CallToolResult, so explicitly handle or guard that case before calling on_tool_end to avoid passing None unexpectedly.
- Consider extracting a helper function for appending ToolCallMessageSegment blocks to reduce duplication in the resp handling branches and improve readability.
- Avoid using a blanket '# type: ignore' on the executor loop; refine the executor’s type annotations instead to maintain type safety.

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.

@Soulter Soulter merged commit cc6fe57 into master Oct 4, 2025
5 checks passed
@Soulter Soulter deleted the fix/2940 branch October 18, 2025 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] on_tool_end无法获得工具返回的结果

2 participants