Skip to content

Comments

feat: add image urls / paths support for subagents#5348

Merged
Soulter merged 4 commits intoAstrBotDevs:masterfrom
a61995987:master
Feb 23, 2026
Merged

feat: add image urls / paths support for subagents#5348
Soulter merged 4 commits intoAstrBotDevs:masterfrom
a61995987:master

Conversation

@a61995987
Copy link
Contributor

@a61995987 a61995987 commented Feb 22, 2026

feat:为子代理增加远程图片URL参数支持
fix:修复5081号PR在子代理执行后台任务时,未正确使用系统配置的流式/非流请求的问题(#5081)

Modifications / 改动点

修改了astrbot\core\astr_agent_tool_exec.py文件
1.在调用ctx.tool_loop_agent时传入stream时 使用ctx.get_config().get("provider_settings", {}).get("stream", False)获取系统配置
2.在_wake_main_agent_for_background_result方法中 使用config = MainAgentBuildConfig(tool_call_timeout=3600, streaming_response=ctx.get_config().get("provider_settings", {}).get("stream", False))获取系统配置
3.为_execute_handoff方法添加image_urls = tool_args.get("image_urls")以获取传递的图片url
4.为await ctx.tool_loop_agent调用增加image_urls参数的传递

修改了D:\Codes\astrbot\astrbot\core\agent\handoff.py文件
1.为default_parameters方法添加image_urls参数及说明信息

  • 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

确保后台工具执行流程在调用子代理以及唤醒主代理以处理后台结果时,遵守系统的流式传输配置。

Bug Fixes:

  • 修复子代理工具执行逻辑,使其在调用 ctx.tool_loop_agent 时使用系统配置的“流式/非流式”设置。
  • 修复主代理在处理后台结果时的唤醒逻辑,使其遵守全局响应流式传输配置。
Original summary in English

Summary by Sourcery

Ensure background tool-execution flows respect the system’s streaming configuration when invoking sub-agents and waking the main agent for background results.

Bug Fixes:

  • Fix sub-agent tool execution so it uses the system-configured streaming/non-streaming setting when calling ctx.tool_loop_agent.
  • Fix main agent wake-up for background results to honor the global streaming configuration for responses.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Feb 22, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @a61995987, 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!

此拉取请求旨在修复一个问题,即子代理在执行后台任务时未能正确使用系统配置的流式或非流式请求设置。通过在关键的代理调用和配置构建中显式地从系统配置中获取并应用 stream 参数,本更改确保了代理行为与全局流式偏好保持一致,从而提升了系统在处理流式请求时的准确性和一致性。

Highlights

  • 子代理流式配置修正: 在子代理执行工具时,确保 ctx.tool_loop_agent 调用正确地从系统配置中获取并应用流式(stream)设置,解决了之前可能未遵循系统配置的问题。
  • 后台任务流式响应同步: 在处理后台任务结果时,_wake_main_agent_for_background_result 方法中的 MainAgentBuildConfig 现在会从系统配置中获取 streaming_response 设置,保证主代理在处理后台结果时也遵循流式配置。
Changelog
  • astrbot/core/astr_agent_tool_exec.py
    • _execute_handoff 函数中,为 tool_loop_agent 调用添加了 stream 参数,使其从系统配置中获取流式设置。
    • _wake_main_agent_for_background_result 函数中,更新了 MainAgentBuildConfigstreaming_response 参数,使其同样从系统配置中获取流式设置。
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 - 我在这里给出了一些总体反馈:

  • 你现在在多个地方调用 ctx.get_config().get("provider_settings", {}).get("stream", False);建议把这一调用结果存到一个局部变量(或抽成一个小的辅助函数),这样行为就集中在一处,如果配置结构以后有变更也更容易调整。
  • 请确认 provider_settings.stream 始终是一个布尔值;如果存在它可能是其它类型的情况(例如来自环境变量的字符串),那么在将其传给 stream / streaming_response 之前先做归一化处理会更安全,以避免一些细微的运行时问题。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- You’re now calling `ctx.get_config().get("provider_settings", {}).get("stream", False)` in multiple places; consider storing this in a local variable (or a small helper) so the behavior is centralized and easier to adjust if the config structure changes.
- Confirm that `provider_settings.stream` is always a boolean; if there’s any chance it can be another type (e.g., string from env), it may be safer to normalize it before passing to `stream` / `streaming_response` to avoid subtle runtime issues.

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

Hey - I've left some high level feedback:

  • You’re now calling ctx.get_config().get("provider_settings", {}).get("stream", False) in multiple places; consider storing this in a local variable (or a small helper) so the behavior is centralized and easier to adjust if the config structure changes.
  • Confirm that provider_settings.stream is always a boolean; if there’s any chance it can be another type (e.g., string from env), it may be safer to normalize it before passing to stream / streaming_response to avoid subtle runtime issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You’re now calling `ctx.get_config().get("provider_settings", {}).get("stream", False)` in multiple places; consider storing this in a local variable (or a small helper) so the behavior is centralized and easier to adjust if the config structure changes.
- Confirm that `provider_settings.stream` is always a boolean; if there’s any chance it can be another type (e.g., string from env), it may be safer to normalize it before passing to `stream` / `streaming_response` to avoid subtle runtime issues.

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
Copy link

dosubot bot commented Feb 22, 2026

Documentation Updates

1 document(s) were updated by changes in this PR:

pr4697的改动
View Changes
@@ -1,20 +1,22 @@
 ## 主动代理(Proactive Agent)系统增强使用说明
-本说明基于 [PR #4697](https://github.com/AstrBotDevs/AstrBot/pull/4697) 的更新,涵盖 AstrBot 主动代理系统的最新特性,包括 SubAgent 架构、FutureTask(定时任务)机制、send_message_to_user 工具、工具注册与配置、以及 UI/API 支持等。
+本说明基于 [PR #4697](https://github.com/AstrBotDevs/AstrBot/pull/4697) 的更新,涵盖 AstrBot 主动代理系统的最新特性,包括 SubAgent 架构、FutureTask(定时任务)机制、send_message_to_user 工具、工具注册与配置、以及 UI/API 支持等。[PR #5348](https://github.com/AstrBotDevs/AstrBot/pull/5348) 进一步增强了子代理的多模态任务支持和流式响应配置。
 
 ---
 
 ### 1. SubAgent(子代理)架构
 
 #### 架构说明
-主代理可以通过 `transfer_to_<subagent>` 工具将任务转交给指定子代理。现在该工具新增了 `background_task` 参数:
-
+主代理可以通过 `transfer_to_<subagent>` 工具将任务转交给指定子代理。该工具支持以下参数:
+
+- `input`: 转交给子代理的输入内容,应为清晰简洁的请求或任务描述。
+- `image_urls`(可选,[PR #5348](https://github.com/AstrBotDevs/AstrBot/pull/5348)): 字符串数组,包含图片源(公开 HTTP URL 或本地文件路径),用作多模态任务(如视频生成)的参考图片。
 - `background_task`: 若设置为 `true`,任务将以后台模式异步执行,主代理会立即返回任务 ID,任务完成后通过后台任务唤醒机制通知用户结果。适用于长时间或非紧急任务。
 
 任务流转支持同步和异步两种模式:
 - 同步模式(默认):主代理等待子代理完成任务后返回结果。
 - 异步模式(background_task=true):主代理立即返回任务 ID,子代理后台执行,完成后自动通知用户。
 
-这样,主代理既可以自主处理,也可以灵活委派任务,并支持异步任务流转。
+这样,主代理既可以自主处理,也可以灵活委派任务,并支持异步任务流转和多模态任务引用。
 
 #### 使用示例
 假设有两个子代理:`DataAgent` 和 `ReportAgent`,分别负责数据处理和报告生成。主代理收到用户请求后,可以选择直接使用自身工具处理部分任务,或通过 `transfer_to_DataAgent` 工具将数据处理任务分配给 DataAgent,处理完成后再通过 `transfer_to_ReportAgent` 工具将结果交给 ReportAgent 生成报告。
@@ -31,15 +33,27 @@
 #### 配置说明
 SubAgent 的定义与 Persona 配置一致,需在配置文件中指定 tools、skills、name、description 等。
 
-transfer_to_* 工具现支持 `background_task` 参数:
-- 在调用时可传入 `background_task: true`,任务将以后台模式异步执行,主代理立即返回任务 ID,完成后通过后台任务唤醒机制通知用户。
-- 若未设置或为 `false`,则为同步模式,主代理等待子代理完成任务。
+transfer_to_* 工具现支持以下参数:
+- `input`:转交给子代理的任务输入
+- `image_urls`(可选):图片 URL 或本地路径数组,用于多模态任务
+- `background_task`:设置任务执行模式
+  - 若为 `true`,任务将以后台模式异步执行,主代理立即返回任务 ID,完成后通过后台任务唤醒机制通知用户
+  - 若未设置或为 `false`,则为同步模式,主代理等待子代理完成任务
 
 主代理在未启用 SubAgent 编排时,可直接挂载自身工具集(按 persona 规则,默认全部),并直接调用工具。
 
 启用 SubAgent 编排后,主代理会保留自身工具,并自动挂载 transfer_to_* 委派工具。是否移除与子代理重复的工具由 `remove_main_duplicate_tools` 配置项控制:
 - `remove_main_duplicate_tools: false`(默认):主代理保留自身工具,即使与子代理重复。
 - `remove_main_duplicate_tools: true`:主代理会移除与子代理重复的工具,仅保留独有工具和 handoff 工具。
+
+##### 流式响应配置(PR #5348)
+
+PR #5348 修复了子代理在执行任务时未正确使用系统配置的流式响应设置的问题([Issue #5081](https://github.com/AstrBotDevs/AstrBot/issues/5081))。修复后,子代理会自动从系统配置中获取流式响应设置:
+
+- 前台任务:调用 `ctx.tool_loop_agent` 时,`stream` 参数从系统配置 `provider_settings.stream` 获取
+- 后台任务:创建 `MainAgentBuildConfig` 时,`streaming_response` 参数同样从系统配置获取
+
+确保子代理在前台和后台任务执行时都遵循全局流式响应配置,而非使用硬编码的默认值。
 
 工具分配可通过 UI 或配置文件完成。相关配置项说明已在配置文件注释中明确。
 

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Feb 22, 2026
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

The pull request addresses an issue where the system's streaming configuration was not correctly applied when executing background tasks involving sub-agents. The changes ensure that both ctx.tool_loop_agent calls and MainAgentBuildConfig initialization correctly retrieve and use the stream setting from provider_settings in the system configuration. This is a good fix for maintaining consistent behavior across different agent interactions.

contexts=contexts,
max_steps=30,
run_hooks=tool.agent.run_hooks,
stream=ctx.get_config().get("provider_settings", {}).get("stream", False),
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The addition of stream=ctx.get_config().get("provider_settings", {}).get("stream", False) correctly propagates the streaming setting to the tool_loop_agent call. This ensures that sub-agent execution respects the global streaming configuration.

)
cron_event.role = event.role
config = MainAgentBuildConfig(tool_call_timeout=3600)
config = MainAgentBuildConfig(tool_call_timeout=3600, streaming_response=ctx.get_config().get("provider_settings", {}).get("stream", False))
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The streaming_response parameter in MainAgentBuildConfig is now correctly initialized using the system's stream setting. This ensures that the main agent's response streaming behavior is consistent with the configured provider_settings when waking up for background task results.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Feb 22, 2026
@a61995987 a61995987 changed the title fix: 修复5081号PR在子代理执行后台任务时,未正确使用系统配置的流式/非流请求的问题(#5081) feat:为子代理增加远程图片URL参数支持 Feb 22, 2026
@Soulter Soulter merged commit 997b511 into AstrBotDevs:master Feb 23, 2026
1 check passed
@Soulter Soulter changed the title feat:为子代理增加远程图片URL参数支持 feat: add image urls / paths support for subagents Feb 23, 2026
astrbot-doc-agent bot pushed a commit to AstrBotDevs/AstrBot-docs that referenced this pull request Feb 23, 2026
@astrbot-doc-agent
Copy link

Generated docs update PR (pending manual review):
AstrBotDevs/AstrBot-docs#138
Trigger: PR merged


AI change summary:

  • 更新 zh/use/subagent.mden/use/subagent.md
  • 新增「委派工具参数」章节,详细说明主 Agent 调用委派工具时的参数配置。
  • 新增 image_urls 参数说明,支持传入公开 HTTP URL 或本地文件路径以处理多模态任务。
  • 补充 input(必填)与 background_task(可选)参数说明及使用示例。
  • i18n:中英文文档同步更新。

Experimental bot notice:

  • This output is generated by AstrBot-Doc-Agent for review only.
  • It does not represent the final documentation form.

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: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