Skip to content

[harness] 内置 general-purpose 子 Agent 忽略父 Agent 的 LocalFilesystemSpec,只读层回落到 user.dir #4022

Open

Description

@chenrongquan

版本

项目 版本
使用版本 io.agentscope:agentscope-harness:2.0.4(Maven Central,Latest release v2.0.4),同时依赖 agentscope-core / agentscope-extensions 2.0.4
同样存在 v2.1.0-BETA1(Pre-release)、main 分支(2.1.0-SNAPSHOT,提交 7ad4939f4,2026-11-06 核对)
运行环境 JDK 21,LocalFilesystemSpec(未启用沙箱)

官方文档的描述

内置 general-purpose:不需要写声明文件,总是可用。它的角色是"通用兜底"——能力和主 agent 一致(同样的模型、工具、技能),共享主工作区。
—— https://java.agentscope.io/v2/zh/docs/harness/subagent (「内置 general-purpose」)

SHARED:子 agent 直接用主工作区。适合子 agent 的输出会被父立即读到的情况(例如 general-purpose)。
—— 同页「ISOLATED vs SHARED」

实际行为

HarnessAgentBuilderSupport.buildGeneralPurposeFactory 只在以下情况把父 Agent 的文件系统传给子 Agent:

final AbstractFilesystem capturedBackend = sandboxFs != null ? sandboxFs : b.abstractFilesystem;
...
if (capturedBackend == null && capturedRemoteSpec != null) sub.filesystem(capturedRemoteSpec);
if (capturedBackend == null && capturedSandboxSpec != null) sub.filesystem(capturedSandboxSpec);
...
if (capturedBackend != null) sub.abstractFilesystem(capturedBackend);

b.localFilesystemSpec 没有被捕获。父 Agent 用 .filesystem(LocalFilesystemSpec)(即常规的非沙箱配置)时,子 Agent 不带任何文件系统 spec,resolveFilesystem 最终走到:

return new LocalFilesystemSpec().toFilesystem(workspace, nsFactory);

而 LocalFilesystemSpec.toFilesystem 在 project == null 时取 System.getProperty("user.dir") 作为只读下层。

对 general-purpose 子 Agent 的影响:

  1. 丢失父 Agent 的 project:即使父 Agent 显式设置了 project(...) 来收窄可读范围,子 Agent 仍能 read_file JVM 工作目录下的任何文件。典型部署中工作目录下往往还有配置、凭据或其他租户的数据,可读范围因此超出宿主应用的配置。
  2. 丢失父 Agent 的 isolationScope:子 Agent 回落到 HarnessAgent.Builder.build() 中硬编码的 IsolationScope.USER,在 <workspace>/<userId>/... 下读写,与父 Agent 的目录布局不一致。
  3. 丢失 spec 子类:自定义的 LocalFilesystemSpec 子类(例如覆写 toFilesystem 以增加 I/O 上限)对子 Agent 不生效。

复现(示意)

HarnessAgent parent = HarnessAgent.builder()
    .name("p").model(model).workspace(ws)
    .filesystem(new LocalFilesystemSpec()
        .project(Path.of("/srv/project"))
        .isolationScope(IsolationScope.AGENT))
    .build();
// 以 user.dir=/srv 启动 JVM(其中有 /srv/secret.txt)
// 让父 Agent 执行:agent_spawn agent_id="general-purpose" task="read_file secret.txt"
// -> 子 Agent 按 user.dir 解析 secret.txt 并返回内容;
//    父 Agent 自己读不到(project=/srv/project)。

期望

按文档所述("共享主工作区"),general-purpose 子 Agent 应复用父 Agent 的有效文件系统配置,包括 LocalFilesystemSpec:使用同一实例,或使用保留 project、isolationScope、additionalRoots、mode 及具体子类的等价副本。

修复建议

在 buildGeneralPurposeFactory 中捕获 b.localFilesystemSpec,在没有 backend/remote/sandbox 配置时调用 sub.filesystem(capturedLocalSpec)(spec 是工厂,传同一实例是安全的);或者直接共享父 Agent 已构建好的 AbstractFilesystem。

另外建议提供一个单独关闭内置 general-purpose 的 Builder 开关。目前唯一的办法是 disableSubagents(),它会把声明式子 Agent 一起关掉。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions