[Bug]: AgentScope-Java V2 版本中手动设置agentId后,获取到的agentId还是uuid格式
package com.eavision.agent;
import io.agentscope.core.agent.RuntimeContext;
import io.agentscope.core.message.Msg;
import io.agentscope.core.message.MsgRole;
import io.agentscope.core.tool.Toolkit;
import io.agentscope.harness.agent.HarnessAgent;
import io.agentscope.harness.agent.filesystem.spec.LocalFilesystemSpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
/**
* 验证 HarnessAgent 的 agentId 设置和获取。
*/
public class AgentIdVerificationDemo {
private static final Logger LOGGER = LoggerFactory.getLogger(AgentIdVerificationDemo.class);
public static void main(String[] args) throws IOException {
System.out.println("=== HarnessAgent AgentId 验证 Demo ===\n");
// 手动指定 agentId
String manualAgentId = "alice:note-taker";
System.out.println("1. 手动指定 agentId: " + manualAgentId);
// 构建 HarnessAgent
HarnessAgent agent = HarnessAgent.builder()
.name("note-taker")
.agentId(manualAgentId)
.sysPrompt("You are a helpful assistant.")
.model("dashscope:qwen3.6-plus")
.workspace(Path.of(System.getProperty("user.home"), ".harness-agent", "workspaces", "alice", "agents", "note-taker"))
.toolkit(new Toolkit())
.filesystem(new LocalFilesystemSpec())
.build();
// 获取 agentId
String retrievedAgentId = agent.getAgentId();
System.out.println("2. 获取 agent.getAgentId(): " + retrievedAgentId);
// 验证是否一致
boolean isSame = manualAgentId.equals(retrievedAgentId);
System.out.println("3. 验证结果: " + (isSame ? "✅ 一致" : "❌ 不一致"));
if (!isSame) {
System.out.println(" 期望值: " + manualAgentId);
System.out.println(" 实际值: " + retrievedAgentId);
}
agent.close();
System.out.println("\n=== Demo 结束 ===");
}
}
17:39:18.433 [main] INFO io.agentscope.core.skill.repository.FileSystemSkillRepository -- FileSystemSkillRepository initialized with base directory: /Users/lxw/.harness-agent/workspaces/alice/agents/note-taker/skills
17:39:18.442 [main] INFO io.agentscope.harness.agent.tools.ToolFilter -- tools.json filter applied: removed 12 tool(s); 6 tool(s) remain: [edit_file, glob_files, grep_files, list_files, read_file, write_file]
17:39:18.442 [main] INFO io.agentscope.harness.agent.HarnessAgent -- HarnessAgent 'note-taker' built [workspace=/Users/lxw/.harness-agent/workspaces/alice/agents/note-taker, backend=ShellAwareOverlay, subagents=true]
2. 获取 agent.getAgentId(): 86882652-25d0-4644-9109-e51495714ed6
3. 验证结果: ❌ 不一致
期望值: alice:note-taker
实际值: 86882652-25d0-4644-9109-e51495714ed6
=== Demo 结束 ===
I’m very interested in this issue and would appreciate the opportunity to help fix it.
After tracing the construction path, I believe the problem is not that HarnessAgent#getAgentId() fails to forward the Builder value to the internal ReActAgent; rather, the current code uses two identifiers with different semantics:
- The Javadoc for
HarnessAgent.Builder.agentId(...)defines it as the stable namespace key for the composite filesystem, used for Harness resource isolation such as workspaces, default state directories, and sandboxes. Agent#getAgentId()is documented as the unique identifier for an agent.HarnessAgent#getAgentId()currently delegates to the internalReActAgent, whoseAgentBasegenerates a UUID for each runtime instance.
Forwarding the Harness agentId directly to ReActAgent would conflate a stable resource namespace with a unique runtime instance identity. For example, a logical agent may intentionally retain the same namespace across restarts or replicas, while each ReActAgent instance should still have its own unique ID. Such forwarding would change the existing Agent#getAgentId() contract and require callers to guarantee global uniqueness for custom values.
I suggest preserving the separation of concerns:
- Keep
HarnessAgent#getAgentId()delegating todelegate.getAgentId()so it continues to return the actualReActAgentinstance ID. - Add a clearly named
namespaceId(...)Builder API for configuring the Harness workspace, default state directory, and sandbox namespace. - Deprecate the current ambiguous
agentId(...)Builder method and retain it as a compatibility alias that delegates tonamespaceId(...). - Update the relevant Javadocs, examples, and migration notes to clearly distinguish the unique instance identity returned by
Agent#getAgentId()from the stable Harness resource namespace represented bynamespaceId.
This approach removes the API ambiguity, preserves the Core agent identity contract, and provides a smooth migration path for existing users. If maintainers agree with this direction, I would be glad to take responsibility for the implementation and tests.
@ethan-lee-club @AgentScopeJavaBot
应该是不行的,底层代码在AgentBase里面是直接构造函数赋值的,并没有提供外部修改的接口哦。 算是官方的设计问题吧。
Fixed in: https://github.com/agentscope-ai/agentscope-java/pull/3360