Skip to content

Conversation

@Soulter
Copy link
Member

@Soulter Soulter commented Dec 26, 2025

Modifications / 改动点

  • 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

Enhancements:

  • Add a custom serializer for assistant messages that drops tool call fields when they are not set to reduce payload size and overhead.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Dec 26, 2025
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.

Hey - 我在这里给出了一些整体性的反馈:

  • 自定义的 serialize 方法目前只会去掉 tool_callstool_call_id;如果你的意图是为了性能普遍避免发送值为 None 的字段,可以考虑配置 exclude_none,或者遍历所有字段来删除 None 值,而不是只对这两个字段做硬编码处理。
  • 如果基础的 Message 类定义了自己的 model_serializer,当前的重写会绕过任何共享的序列化逻辑;可以考虑显式地委托给父类,或者统一整合相关逻辑,以避免出现行为上的分歧。
给 AI 代理的提示(Prompt for AI Agents)
Please address the comments from this code review:

## Overall Comments
- 自定义的 `serialize` 方法目前只会去掉 `tool_calls``tool_call_id`;如果你的意图是为了性能普遍避免发送值为 `None` 的字段,可以考虑配置 `exclude_none`,或者遍历所有字段来删除 `None` 值,而不是只对这两个字段做硬编码处理。
- 如果基础的 `Message` 类定义了自己的 `model_serializer`,当前的重写会绕过任何共享的序列化逻辑;可以考虑显式地委托给父类,或者统一整合相关逻辑,以避免出现行为上的分歧。

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

Hey - I've left some high level feedback:

  • The custom serialize method only strips tool_calls and tool_call_id; if the intent is to generally avoid sending None fields for performance, consider configuring exclude_none or iterating over all fields to drop None values instead of hardcoding just these two.
  • If the base Message class defines its own model_serializer, this override will bypass any shared serialization behavior; consider explicitly delegating to the parent or consolidating the logic to avoid divergence.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The custom `serialize` method only strips `tool_calls` and `tool_call_id`; if the intent is to generally avoid sending `None` fields for performance, consider configuring `exclude_none` or iterating over all fields to drop `None` values instead of hardcoding just these two.
- If the base `Message` class defines its own `model_serializer`, this override will bypass any shared serialization behavior; consider explicitly delegating to the parent or consolidating the logic to avoid divergence.

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 Dec 26, 2025
@Soulter Soulter merged commit bd1b0a2 into master Dec 26, 2025
6 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 size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants