agentscope-ai / agentscope-ai/agentscope-java

[Bug]:agentscope-builder 无法以 remote/sandbox 模式启动,即使已提供 Redis 环境

オープン
#1,725 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
area/examples bug
主要言語
Java
スター
5.6k
フォーク
1.3k
平均マージ
4日 12時間
マージ済み PR(30日)
77

説明

**项目:** `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`:

```48:204:agentscope-examples/agents/agentscope-builder/pom.xml


io.agentscope
agentscope-harness


io.agentscope
agentscope-extensions-mysql




```

#### 2. `agentscope-extensions-redis` 没有 Spring Boot 自动配置

该模块是纯程序式 API,无任何 `spring.factories` 或 `AutoConfiguration.imports` 文件。即使加上依赖,Spring 也不会自动注册 `RedisAgentStateStore` 或 `RedisDistributedStore` Bean。

#### 3. `BuilderConfig.java` 从未创建分布式状态存储

```207:215:agentscope-examples/agents/agentscope-builder/src/main/java/io/agentscope/builder/web/config/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 组合

```1818:1826:agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java
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 区新增:**
```java
import io.agentscope.extensions.redis.RedisDistributedStore;
import redis.clients.jedis.JedisPooled;
```

**② 字段区新增 Redis 连接配置:**
```java
@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`:**
```java
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` 新增依赖:**
```xml

io.agentscope
agentscope-extensions-redis

```

### 相关 issue

关联 #1723 ——两个问题都需要修复才能使 remote/sandbox 模式正常工作。

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。