AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Feature] tool_loop_agent 支持传入 extra_user_content_parts

Open hypxtmc opened this issue 2 months ago • 3 comments

Context.tool_loop_agent() 内部构造 ProviderRequest 时没有传 extra_user_content_parts,插件通过这个入口起子代理时,没有地方放「不该写进对话历史」的内容。

补一个参数透传即可,ToolLoopAgentRunner 本身是支持的:

async def tool_loop_agent(
    self,
    *,
    ...
    extra_user_content_parts: list[ContentPart] | None = None,   # 新增
    ...
) -> LLMResponse:
    ...
    request = ProviderRequest(
        ...
        extra_user_content_parts=extra_user_content_parts or [],  # 新增
    )

为什么需要

插件用 tool_loop_agent() 起子代理时,常要带一些「每轮现算、但不该沉淀进历史」的东西,比如时间、检索回来的线索、临时状态。现在三条路都不好走:

  • 拼进 prompt:跟用户消息混成一条,还会被写进历史,下一轮又当上下文读回来
  • 拼进 system_prompt:归属清楚,但 system 每轮变会让前缀缓存失效,长会话开销明显上升
  • 自己写一套 tool loop:成本远超收益,上游一改行为就漂

extra_user_content_parts 就是干这个的——mark_as_temp() 让它不落历史,跟 user message 也分得开。主流程 astr_main_agent.py 已经用得不少,子代理这条路缺的只是一个入口。

#10134 给插件和子代理的 tool loop 补了系统层指导,说明「tool loop 需要额外上下文」这个需求是成立的。只是那份内容固定,放 system_prompt 就够;每轮都变的得另走一条。

版本

v4.27.4。当前 master 上同样如此,git log -S "extra_user_content_parts" -- astrbot/core/star/context.py 结果为空。

检查清单

  • [x] 已在 Issue 列表搜索过,确认该功能未被提出(含该字段的结果均为图片/视频相关;含 tool_loop_agent 的结果无此诉求)
  • [x] 与 AstrBot 本体相关,而非建议某一插件的功能
  • [x] 已阅读并同意贡献者行为准则
  • [ ] (可选)愿意提交 PR

hypxtmc avatar Sep 25 '26 16:09 hypxtmc

需求本质:插件用 tool_loop_agent() 起子代理时,缺少「每轮现算、不落历史」的临时上下文入口(时间、检索线索等)。 现状:只能塞进 prompt(会写进历史)或 system_prompt(每轮变、前缀缓存失效);请求对象支持 extra_user_content_parts,此处不接受也不透传。 受益规模:所有用该入口起子代理的插件作者。公开仓库中检索到 20+ 个 astrbot_plugin_* 在代码里调用,覆盖检索笔记、订阅推送、多角色、子代理编排等场景。 建议标签:area:core area:provider feature:plugin

以上为 AI 生成内容。

silvaling avatar Sep 25 '26 17:09 silvaling

Opened a PR for this: #10237 — adds the keyword-only parameter to tool_loop_agent() and forwards it into the ProviderRequest it builds, plus a regression test. Happy to adjust if you'd prefer it plumbed differently.

hypxtmc avatar Sep 26 '26 09:09 hypxtmc

Thank you for your feedback! This issue has been addressed in PR #10237, which has been merged. We’re closing this issue as completed.

If the problem still occurs in the current version, or you still need this feature, please leave a comment with updated details so we can reopen the issue and continue the discussion. For bug reports, please include your AstrBot version, steps to reproduce, and relevant logs.

Thank you for your understanding and support!

anka-afk avatar Oct 12 '26 09:10 anka-afk