MongoDistributedStore
public class MongoDistributedStore implements DistributedStore, AutoCloseable
io/agentscope/extensions/mongodb/MongoDistributedStore.java:71–322Mongo 分布式存储,负责持久化与读取数据。位于 io.agentscope.extensions.mongodb 包,实现 DistributedStore、AutoCloseable。核心成员包括 create、fromConnectionString、agentStateStore、baseStore、sandboxSnapshotSpec、sandboxExecutionGuard。
MongoDB-backed DistributedStore.
Usage:
`MongoClient mongoClient = MongoClients.create("mongodb://localhost:27017");
HarnessAgent agent = HarnessAgent.builder()
.name("my-agent")
.model("dashscope:qwen-plus")
.distributedStore(MongoDistributedStore.create(mongoClient, "agentscope"))
.build();
`
This configures:
-
MongoAgentStateStore— agent session state in MongoDB -
MongoBaseStore— workspace filesystem KV in MongoDB -
MongoSandboxExecutionGuard— sandbox execution locking in MongoDB -
MongoSnapshotSpec— sandbox workspace snapshots in MongoDB
When created via #create(MongoClient), the caller owns the MongoClient
lifecycle; #close() will NOT close the client. When created via #fromConnectionString(String), the store owns the client and #close() will close it.
In both cases, #close() also cascades to shut down any cached
MongoSandboxExecutionGuard executor.
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static MongoDistributedStore create(MongoClient mongoClient)static | 创建MongoDB 分布式存储使用默认数据库名称(`"agentscope"`)。 Creates a MongoDB distributed store with the default database name (`"agentscope"`). |
public static MongoDistributedStore create(MongoClient mongoClient, String databaseName)static | 创建MongoDB 分布式存储。 Creates a MongoDB distributed store. |
public static MongoDistributedStore fromConnectionString(String connectionString)static | 设置该参数。 Creates a MongoDB distributed store from a connection string. |
public AgentStateStore agentStateStore() | 返回智能体状态存储。 Returns the agent state store. |
public BaseStore baseStore() | 返回基类存储。 Returns the base store. |
public SandboxSnapshotSpec sandboxSnapshotSpec() | 返回沙箱快照规格。 Returns the sandbox snapshot spec. |
public SandboxExecutionGuard sandboxExecutionGuard() | 返回沙箱执行守卫。 Returns the sandbox execution guard. |
public void close() | 关闭连接并释放相关资源。 Releases resources and connections. |
方法详情Method Detail
create
public static MongoDistributedStore create(MongoClient mongoClient)
创建MongoDB 分布式存储使用默认数据库名称("agentscope")。
Creates a MongoDB distributed store with the default database name ("agentscope").
| 名称Name | 类型Type | 说明Description |
|---|---|---|
mongoClient | MongoClient | MongoDB 客户端。the MongoDB client |
MongoDistributedStoreio/agentscope/extensions/mongodb/MongoDistributedStore.java:101–103create
public static MongoDistributedStore create(MongoClient mongoClient, String databaseName)
创建MongoDB 分布式存储。
Creates a MongoDB distributed store.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
mongoClient | MongoClient | MongoDB 客户端。the MongoDB client |
databaseName | String | 数据库名称。the database name |
MongoDistributedStoreio/agentscope/extensions/mongodb/MongoDistributedStore.java:112–114fromConnectionString
public static MongoDistributedStore fromConnectionString(String connectionString)
设置该参数。
Creates a MongoDB distributed store from a connection string.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
connectionString | String | 连接 String(类型 `String`)。the MongoDB connection string |
MongoDistributedStoreio/agentscope/extensions/mongodb/MongoDistributedStore.java:126–131agentStateStore
public AgentStateStore agentStateStore()
返回智能体状态存储。
Returns the agent state store.
AgentStateStoreio/agentscope/extensions/mongodb/MongoDistributedStore.java:133–152baseStore
public BaseStore baseStore()
返回基类存储。
Returns the base store.
BaseStoreio/agentscope/extensions/mongodb/MongoDistributedStore.java:259–273sandboxSnapshotSpec
public SandboxSnapshotSpec sandboxSnapshotSpec()
返回沙箱快照规格。
Returns the sandbox snapshot spec.
SandboxSnapshotSpecio/agentscope/extensions/mongodb/MongoDistributedStore.java:275–288sandboxExecutionGuard
public SandboxExecutionGuard sandboxExecutionGuard()
返回沙箱执行守卫。
Returns the sandbox execution guard.
SandboxExecutionGuardio/agentscope/extensions/mongodb/MongoDistributedStore.java:290–307close
public void close()
关闭连接并释放相关资源。
Releases resources and connections.
io/agentscope/extensions/mongodb/MongoDistributedStore.java:309–321