[Bug]:agentscope-builder 无法以 remote/sandbox 模式启动,即使已提供 Redis 环境
项目: agentscope-examples/agentscope-builder
影响版本: 当前 main 分支(${revision})
问题描述
按照 README 文档配置 Redis 后,以 --builder.workspace-store.fs-spec=remote 启动 builder,应用启动失败,抛出 IllegalStateException:
java.lang.IllegalStateException: filesystem(RemoteFilesystemSpec) is designed for distributed /
multi-replica deployments, but the effective AgentStateStore is a local in-process implementation
(InMemoryAgentStateStore). Configure a distributed AgentStateStore (...)
根因分析
三层原因叠加导致:
1. agentscope-extensions-redis 不在 builder 的 pom.xml 中
agentscope-builder/pom.xml 依赖了 agentscope-extensions-mysql、agentscope-extensions-channel-*、agentscope-extensions-skill-*,但没有 agentscope-extensions-redis:
<dependencies>
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-harness</artifactId>
</dependency>
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-mysql</artifactId>
</dependency>
<!-- ... 各种 channel 和 skill 扩展 ... -->
<!-- ❌ 缺少 agentscope-extensions-redis -->
</dependencies>
2. agentscope-extensions-redis 没有 Spring Boot 自动配置
该模块是纯程序式 API,无任何 spring.factories 或 AutoConfiguration.imports 文件。即使加上依赖,Spring 也不会自动注册 RedisAgentStateStore 或 RedisDistributedStore Bean。
3. BuilderConfig.java 从未创建分布式状态存储
AgentStateStore stateStore = sessionOpt.orElseGet(InMemoryAgentStateStore::new);
if (sessionOpt.isEmpty()) {
log.warn(
"No distributed AgentStateStore bean configured ({}); using"
+ " InMemoryAgentStateStore...",
AgentStateStore.class.getName());
}
没有 Redis 连接配置注入(redis.host、redis.port),没有 RedisDistributedStore 创建逻辑,sessionOpt 永远为空,只能 fallback 到 InMemoryAgentStateStore。
4. HarnessAgent.Builder.build() 拒绝 local + remote 组合
if (remoteFilesystemSpec != null && isLocalSession(effectiveSession)) {
throw new IllegalStateException(
"filesystem(RemoteFilesystemSpec) is designed for distributed /"
+ " multi-replica deployments, but the effective AgentStateStore is a"
+ " local in-process implementation...");
}
建议修复方案
为 BuilderConfig.java 补充 Redis 支持:
① import 区新增:
import io.agentscope.extensions.redis.RedisDistributedStore;
import redis.clients.jedis.JedisPooled;
② 字段区新增 Redis 连接配置:
@Value("${builder.redis.host:localhost}")
private String redisHost;
@Value("${builder.redis.port:6379}")
private int redisPort;
@Value("${builder.redis.password:}")
private String redisPassword;
③ remote/sandbox 分支创建 RedisDistributedStore:
case "remote":
case "sandbox":
UnifiedJedis jedis = redisPassword.isEmpty()
? new JedisPooled("redis://" + redisHost + ":" + redisPort)
: new JedisPooled("redis://:" + redisPassword + "@" + redisHost + ":" + redisPort);
RedisDistributedStore distStore = RedisDistributedStore.fromJedis(jedis);
b.middleware(new ToolNotificationMiddleware(toolEventBus));
b.distributedStore(distStore);
b.filesystem(
new RemoteFilesystemSpec(distStore.baseStore())
.isolationScope(IsolationScope.USER)
.addSharedPrefix("activity/"));
break;
④ pom.xml 新增依赖:
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-redis</artifactId>
</dependency>
相关 issue
关联 #1723 ——两个问题都需要修复才能使 remote/sandbox 模式正常工作。