Skip to content

Comments

feat: add support for showing tool call results in agent execution#5388

Merged
Soulter merged 1 commit intomasterfrom
feat/tool-call-supports-output-result
Feb 23, 2026
Merged

feat: add support for showing tool call results in agent execution#5388
Soulter merged 1 commit intomasterfrom
feat/tool-call-supports-output-result

Conversation

@Soulter
Copy link
Member

@Soulter Soulter commented Feb 23, 2026

closes: #5329

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

在智能体执行和实时模式中,新增可配置支持,用于在现有工具使用状态消息的基础上显示截断的工具调用结果。

新功能:

  • 引入一个选项,用于在智能体运行和实时智能体运行中显示工具调用结果,包括将工具调用 ID 映射到名称,并显示简要的结果摘要。
  • 为本地智能体运行器新增配置标志,用于启用工具调用结果显示,并包含仪表盘元数据和条件可见性控制。

改进:

  • 重构智能体工具调用处理逻辑,复用用于提取工具元数据和构建状态消息的辅助函数,从而改进轨迹记录和消息格式化。
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:

  • Introduce an option to show tool call results in agent and live agent runs, including mapping tool call IDs to names and displaying a brief result summary.
  • Add new configuration flags to enable tool call result display for local agent runners, with dashboard metadata and conditional visibility.

Enhancements:

  • Refactor agent tool call handling to reuse helper functions for extracting tool metadata and building status messages, improving trace recording and message formatting.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 23, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • New Feature: Tool Call Result Display: Introduced a new capability to display the results of tool calls during agent execution, providing more transparency into the agent's actions.
  • Configurable Option: Added a new boolean configuration option, show_tool_call_result, allowing users to enable or disable the display of tool call results. This option is dependent on show_tool_use_status being enabled.
  • Core Logic for Tool Result Processing: Implemented several helper functions (_truncate_tool_result, _extract_chain_json_data, _record_tool_call_name, _build_tool_call_status_message, _build_tool_result_status_message) to parse, store, and format tool call information and their results.
  • Integration into Agent Execution Flow: Modified the run_agent, run_live_agent, and _run_agent_feeder functions to accept and utilize the new show_tool_call_result parameter, ensuring the feature is integrated across different agent execution modes.
  • Localization and UI Updates: Updated configuration schemas and internationalization files (English and Chinese) to include descriptions and hints for the new show_tool_call_result setting in the user interface.
Changelog
  • astrbot/core/astr_agent_run_util.py
    • Added _truncate_tool_result function to limit the length of displayed tool results.
    • Added _extract_chain_json_data function to safely extract JSON data from message chains.
    • Added _record_tool_call_name function to map tool call IDs to tool names.
    • Added _build_tool_call_status_message function to format tool call status messages.
    • Added _build_tool_result_status_message function to format tool result status messages, including truncation.
    • Modified run_agent to accept show_tool_call_result and integrate new helper functions for displaying tool results.
    • Modified run_live_agent to accept show_tool_call_result parameter.
    • Modified _run_agent_feeder to accept show_tool_call_result parameter.
  • astrbot/core/config/default.py
    • Added show_tool_call_result with a default value of False to the agent settings.
    • Updated ChatProviderTemplate schema to include show_tool_call_result as a boolean type.
    • Added configuration metadata for provider_settings.show_tool_call_result, including description, hint, and condition for its display.
  • astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py
    • Initialized self.show_tool_call_result from settings within the initialize method.
    • Passed self.show_tool_call_result to run_live_agent, run_agent, and _run_agent_feeder calls.
  • dashboard/src/i18n/locales/en-US/features/config-metadata.json
    • Added English localization for the show_tool_call_result description and hint.
  • dashboard/src/i18n/locales/zh-CN/features/config-metadata.json
    • Added Chinese localization for the show_tool_call_result description and hint.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 - 我在这里给出了一些高层次的反馈:

  • _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.

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

Hey - I've left some high level feedback:

  • 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.
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.

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 Feb 23, 2026
@dosubot
Copy link

dosubot bot commented Feb 23, 2026

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 或配置文件完成。相关配置项说明已在配置文件注释中明确。
 

[Accept] [Decline]

Note: You must be authenticated to accept/decline updates.

How did I do? Any feedback?  Join Discord

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 为智能体执行新增了显示工具调用结果的功能,并提供了相应的配置项和国际化支持。通过引入辅助函数重构了工具调用信息的提取与格式化逻辑,代码结构清晰且具有良好的鲁棒性。主要的反馈集中在开启结果显示时的用户交互体验优化,建议避免因延迟发送状态消息而导致用户在工具执行期间感知不到进度。

Comment on lines +179 to +181
if show_tool_call_result and isinstance(tool_info, dict):
# Delay tool status notification until tool_call_result.
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在开启 show_tool_call_result 时,代码选择跳过发送即时的“正在调用工具”状态消息(第 181 行 continue),直到工具执行完毕并返回结果时才统一发送。这在执行耗时较长的工具(如联网搜索、复杂数据处理等)时,会导致用户侧长时间没有任何反馈,可能让用户误以为机器人卡死或无响应。建议即使开启了结果显示,也保留即时的调用反馈,以提升交互的即时性。虽然这会导致在结果返回时多发一条消息,但对于长耗时任务的交互体验至关重要。

                        chain = MessageChain(type="tool_call").message(
                            _build_tool_call_status_message(tool_info)
                        )
                        await astr_event.send(chain)

@Soulter Soulter merged commit 80fd511 into master Feb 23, 2026
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 希望能够有更加详细的工具调用显示

1 participant