feat: add support for showing tool call results in agent execution#5388
feat: add support for showing tool call results in agent execution#5388
Conversation
Summary of ChangesHello @Soulter, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the agent execution experience by introducing the ability to display the results of tool calls directly within the output. This provides users with greater insight into the agent's decision-making process and the outcomes of its interactions with external tools. The feature is controlled by a new configuration setting, allowing for flexible adoption based on user preference. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - 我在这里给出了一些高层次的反馈:
- 在
_build_tool_result_status_message中,你从tool_name_by_call_id中使用pop取出了 tool 名称,这意味着对于给定的id,只有第一个tool_call_result能拿到解析后的名称;如果同一个工具调用可能会发出多条结果消息,请考虑改用get而不是pop,或者只在确定所有分片都处理完之后再清理这张映射表。 - 新增的状态消息(
_build_tool_call_status_message/_build_tool_result_status_message)里直接写入了硬编码的中文文本;如果这段代码会在多语言环境中使用,建议通过现有的 i18n 机制来管理这些字符串,或者至少与其他状态消息的本地化方式保持一致。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_build_tool_result_status_message` you `pop` the tool name from `tool_name_by_call_id`, which means only the first `tool_call_result` for a given `id` will have a resolved name; if tools can emit multiple result messages per call, consider using `get` instead of `pop` or only clearing the mapping when you're sure all chunks are processed.
- The new status messages (`_build_tool_call_status_message` / `_build_tool_result_status_message`) embed hard-coded Chinese text; if this code is used in multi-language environments, consider routing these strings through the existing i18n mechanism or at least aligning with how other status messages are localized.帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've left some high level feedback:
- In
_build_tool_result_status_messageyoupopthe tool name fromtool_name_by_call_id, which means only the firsttool_call_resultfor a givenidwill have a resolved name; if tools can emit multiple result messages per call, consider usinggetinstead ofpopor only clearing the mapping when you're sure all chunks are processed. - The new status messages (
_build_tool_call_status_message/_build_tool_result_status_message) embed hard-coded Chinese text; if this code is used in multi-language environments, consider routing these strings through the existing i18n mechanism or at least aligning with how other status messages are localized.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `_build_tool_result_status_message` you `pop` the tool name from `tool_name_by_call_id`, which means only the first `tool_call_result` for a given `id` will have a resolved name; if tools can emit multiple result messages per call, consider using `get` instead of `pop` or only clearing the mapping when you're sure all chunks are processed.
- The new status messages (`_build_tool_call_status_message` / `_build_tool_result_status_message`) embed hard-coded Chinese text; if this code is used in multi-language environments, consider routing these strings through the existing i18n mechanism or at least aligning with how other status messages are localized.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Related Documentation 1 document(s) may need updating based on files changed in this PR: AstrBotTeam's Space pr4697的改动View Suggested Changes@@ -58,6 +58,30 @@
- 后台任务:创建 `MainAgentBuildConfig` 时,`streaming_response` 参数同样从系统配置获取
确保子代理在前台和后台任务执行时都遵循全局流式响应配置,而非使用硬编码的默认值。
+
+##### 工具调用结果显示配置(PR #5388)
+
+PR #5388 新增了 `show_tool_call_result` 配置选项,支持在 Agent 执行过程中显示工具调用的返回结果([Issue #5329](https://github.com/AstrBotDevs/AstrBot/issues/5329))。
+
+**配置项:show_tool_call_result**
+
+- **类型**:布尔值(Boolean)
+- **默认值**:`false`
+- **描述**:输出函数调用返回结果
+- **前置条件**:该选项仅在以下两个条件**同时满足**时生效:
+ 1. `show_tool_use_status` 已启用(设置为 `true`)
+ 2. `agent_runner_type` 设置为 `"local"`(使用内置 Agent Runner)
+- **行为**:启用后,在 Agent 执行工具调用时,会显示工具返回结果的前 70 个字符
+- **显示格式**:
+ - `🔨 调用工具: {工具名称}`
+ - `📎 返回结果: {截断的结果内容}`
+
+**使用说明**:
+
+- 用户必须先启用 `show_tool_use_status` 配置项,`show_tool_call_result` 才能生效
+- 该功能仅适用于本地 Agent Runner,第三方 Agent Runner(如 Dify、Coze)不支持
+- 工具返回结果会自动截断为前 70 个字符,避免输出过长影响用户体验
+- 当启用 `show_tool_call_result` 时,工具调用状态通知会延迟到工具执行完成后,与返回结果一同显示
工具分配可通过 UI 或配置文件完成。相关配置项说明已在配置文件注释中明确。
Note: You must be authenticated to accept/decline updates. |
| if show_tool_call_result and isinstance(tool_info, dict): | ||
| # Delay tool status notification until tool_call_result. | ||
| continue |
There was a problem hiding this comment.
在开启 show_tool_call_result 时,代码选择跳过发送即时的“正在调用工具”状态消息(第 181 行 continue),直到工具执行完毕并返回结果时才统一发送。这在执行耗时较长的工具(如联网搜索、复杂数据处理等)时,会导致用户侧长时间没有任何反馈,可能让用户误以为机器人卡死或无响应。建议即使开启了结果显示,也保留即时的调用反馈,以提升交互的即时性。虽然这会导致在结果返回时多发一条消息,但对于长耗时任务的交互体验至关重要。
chain = MessageChain(type="tool_call").message(
_build_tool_call_status_message(tool_info)
)
await astr_event.send(chain)
closes: #5329
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
在智能体执行和实时模式中,新增可配置支持,用于在现有工具使用状态消息的基础上显示截断的工具调用结果。
新功能:
改进:
Original summary in English
Summary by Sourcery
Add configurable support for displaying truncated tool call results during agent execution and live mode, alongside existing tool usage status messages.
New Features:
Enhancements: