Class MongoAgentStateStore.Builder
java.lang.Object
io.agentscope.extensions.mongodb.state.MongoAgentStateStore.Builder
- Enclosing class:
- MongoAgentStateStore
Builder for
MongoAgentStateStore.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build theMongoAgentStateStore.collectionName(String collectionName) Collection name.connectionString(String connectionString) MongoDB connection string (e.g.databaseName(String databaseName) Database name.mongoClient(com.mongodb.client.MongoClient mongoClient) Use an existingMongoClient.onDeleteCallback(BiConsumer<String, String> onDeleteCallback) Optional callback invoked before a session document is deleted viaMongoAgentStateStore.delete(String, String).Optional session TTL in days.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
mongoClient
Use an existingMongoClient. The caller owns its lifecycle;MongoAgentStateStore.close()will NOT close a client supplied through this method.- Parameters:
mongoClient- the client to use- Returns:
- this builder
-
connectionString
MongoDB connection string (e.g."mongodb://localhost:27017").A new
MongoClientwill be created internally and closed whenMongoAgentStateStore.close()is called.- Parameters:
connectionString- the connection string- Returns:
- this builder
-
databaseName
Database name. Defaults to"agentscope". When a connection string is provided, the database name in the URI (if any) is used as a fallback before the default.- Parameters:
databaseName- the database name- Returns:
- this builder
-
collectionName
Collection name. Defaults to"agentscope_sessions".- Parameters:
collectionName- the collection name- Returns:
- this builder
-
ttlDays
Optional session TTL in days. When set to a positive value, a TTL index is created on_updated_atso MongoDB automatically removes documents that have not been updated within the specified number of days.Defaults to
null(no TTL), aligned with Postgres/JDBC/Redis which retain sessions indefinitely by default.- Parameters:
ttlDays- number of days, ornullto disable automatic expiry- Returns:
- this builder
-
onDeleteCallback
Optional callback invoked before a session document is deleted viaMongoAgentStateStore.delete(String, String). Receives the userId and sessionId. Used byMongoDistributedStoreto cascade-delete associated snapshots.- Parameters:
onDeleteCallback- the callback (userId, sessionId) to run before session deletion- Returns:
- this builder
-
build
Build theMongoAgentStateStore.- Returns:
- a new instance
-