Package io.agentscope.extensions.mongodb
Class MongoDistributedStore
java.lang.Object
io.agentscope.extensions.mongodb.MongoDistributedStore
- All Implemented Interfaces:
io.agentscope.harness.agent.DistributedStore,AutoCloseable
public class MongoDistributedStore
extends Object
implements io.agentscope.harness.agent.DistributedStore, AutoCloseable
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 MongoDBMongoBaseStore— workspace filesystem KV in MongoDBMongoSandboxExecutionGuard— sandbox execution locking in MongoDBMongoSnapshotSpec— 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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.agentscope.harness.agent.DistributedStore
io.agentscope.harness.agent.DistributedStore.Builder, io.agentscope.harness.agent.DistributedStore.CompositeDistributedStore -
Method Summary
Modifier and TypeMethodDescriptionio.agentscope.core.state.AgentStateStoreio.agentscope.harness.agent.filesystem.remote.store.BaseStorevoidclose()static MongoDistributedStorecreate(com.mongodb.client.MongoClient mongoClient) Creates a MongoDB distributed store with the default database name ("agentscope").static MongoDistributedStoreCreates a MongoDB distributed store.static MongoDistributedStorefromConnectionString(String connectionString) Creates a MongoDB distributed store from a connection string.io.agentscope.harness.agent.sandbox.SandboxExecutionGuardio.agentscope.harness.agent.sandbox.snapshot.SandboxSnapshotSpecMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.harness.agent.DistributedStore
asyncToolRegistry, messageBus, sessionTurnGate, taskRepository, teamClient
-
Method Details
-
create
Creates a MongoDB distributed store with the default database name ("agentscope").- Parameters:
mongoClient- the MongoDB client- Returns:
- a new MongoDB distributed store
-
create
public static MongoDistributedStore create(com.mongodb.client.MongoClient mongoClient, String databaseName) Creates a MongoDB distributed store.- Parameters:
mongoClient- the MongoDB clientdatabaseName- the database name- Returns:
- a new MongoDB distributed store
-
fromConnectionString
Creates a MongoDB distributed store from a connection string. A newMongoClientis created internally and owned by the store;close()will close it.If the connection string includes a database path (e.g.
"mongodb://host:27017/mydb"), that database is used instead of the default.- Parameters:
connectionString- the MongoDB connection string- Returns:
- a new MongoDB distributed store
-
agentStateStore
public io.agentscope.core.state.AgentStateStore agentStateStore()- Specified by:
agentStateStorein interfaceio.agentscope.harness.agent.DistributedStore
-
baseStore
public io.agentscope.harness.agent.filesystem.remote.store.BaseStore baseStore()- Specified by:
baseStorein interfaceio.agentscope.harness.agent.DistributedStore
-
sandboxSnapshotSpec
public io.agentscope.harness.agent.sandbox.snapshot.SandboxSnapshotSpec sandboxSnapshotSpec()- Specified by:
sandboxSnapshotSpecin interfaceio.agentscope.harness.agent.DistributedStore
-
sandboxExecutionGuard
public io.agentscope.harness.agent.sandbox.SandboxExecutionGuard sandboxExecutionGuard()- Specified by:
sandboxExecutionGuardin interfaceio.agentscope.harness.agent.DistributedStore
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-