Describe the bug
harness 升级到2.0版本后,启用沙箱时,注册的工具中获取不到类型安全上下文对象,debug发现是因为在io.agentscope.harness.agent.HarnessAgent#ensureSessionDefaults中没有复制相关属性
After upgrading Harness to version 2.0, when sandbox mode is enabled, type-safe context objects cannot be retrieved from registered tools; debugging reveals that the issue lies in io.agentscope.harness.agent.HarnessAgent#ensureSessionDefaults, which fails to copy the relevant properties.
To Reproduce
@Component
public class CustomTools {
@Resource
private CommonToolSet commonToolSet;
@Tool(name = "upload_output_files",
description = "上传沙箱中的输出文件到云存储")
public String uploadOutputFiles(
@ToolParam(name = "file_paths",
description = "要上传的文件路径列表,相对于工作区根目录")
List<String> filePaths,
RuntimeContext runtimeContext,
ToolCallContext tcc
) {
// tcc is null,这里获取到的是null
return commonToolSet.uploadToOss(filePaths, plan, tcc, runtimeContext);
}
}
Toolkit toolkit = new Toolkit();
toolkit.registerTool(customTools);
DockerFilesystemSpec dockerSpec = new DockerFilesystemSpec();
dockerSpec.image("agentscope/runtime-sandbox-base:latest");
dockerSpec.memorySizeBytes(64L * 1024 * 1024); // 64MB
dockerSpec.cpuCount(2L);
dockerSpec.snapshotSpec(snapshotSpec != null ? snapshotSpec : new NoopSnapshotSpec());
dockerSpec.isolationScope(IsolationScope.SESSION);
dockerSpec.environment(Map.of("TZ", "Asia/Shanghai"));
dockerSpec.network("bridge"); // 默认 none 无网络,改为 bridge 允许容器访问外网(下载图片等)
// dockerSpec.client(new DockerCpSandboxClient()); 自定义实现docker cp解决过长文件名过长问题
ExecutionConfig toolConfig = ExecutionConfig.builder()
.timeout(Duration.ofMinutes(30))
.maxAttempts(2)
.build();
HarnessAgent.Builder builder = HarnessAgent.builder()
.name(name)
.sysPrompt(sysPrompt)
.model(model)
.toolkit(toolkit)
.toolExecutionConfig(toolConfig)
.middlewares(middlewares)
.maxIters(maxIters)
.filesystem(dockerSpec)
.sandboxDistributed(SandboxDistributedOptions.builder()
.requireDistributed(false).build());
# custom object
ToolCallContext toolCallContext = new ToolCallContext();
RuntimeContext runtimeContext = RuntimeContext.builder()
.sessionId(session.getSessionId())
.put(ToolCallContext.class, toolCallContext)
.build();
builder.build().call(List.of(userMsg), runtimeContext).block();
Expected behavior
tcc is not null
应该能获取到put的ToolCallContext实例
Error messages
Detailed error messages.
Environment (please complete the following information):
- AgentScope-Java Version: 2.0.0-RC1
- Java Version: 17
- OS: windows
Additional context
Add any other context about the problem here.
Describe the bug
harness 升级到2.0版本后,启用沙箱时,注册的工具中获取不到类型安全上下文对象,debug发现是因为在
io.agentscope.harness.agent.HarnessAgent#ensureSessionDefaults中没有复制相关属性After upgrading Harness to version 2.0, when sandbox mode is enabled, type-safe context objects cannot be retrieved from registered tools; debugging reveals that the issue lies in
io.agentscope.harness.agent.HarnessAgent#ensureSessionDefaults, which fails to copy the relevant properties.To Reproduce
Expected behavior
tcc is not null
应该能获取到put的ToolCallContext实例
Error messages
Detailed error messages.
Environment (please complete the following information):
Additional context
Add any other context about the problem here.