Class MongoAgentStateStore.Builder

java.lang.Object
io.agentscope.extensions.mongodb.state.MongoAgentStateStore.Builder
Enclosing class:
MongoAgentStateStore

public static class MongoAgentStateStore.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • mongoClient

      public MongoAgentStateStore.Builder mongoClient(com.mongodb.client.MongoClient mongoClient)
      Use an existing MongoClient. 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

      public MongoAgentStateStore.Builder connectionString(String connectionString)
      MongoDB connection string (e.g. "mongodb://localhost:27017").

      A new MongoClient will be created internally and closed when MongoAgentStateStore.close() is called.

      Parameters:
      connectionString - the connection string
      Returns:
      this builder
    • databaseName

      public MongoAgentStateStore.Builder databaseName(String 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

      public MongoAgentStateStore.Builder collectionName(String collectionName)
      Collection name. Defaults to "agentscope_sessions".
      Parameters:
      collectionName - the collection name
      Returns:
      this builder
    • ttlDays

      public MongoAgentStateStore.Builder ttlDays(Integer ttlDays)
      Optional session TTL in days. When set to a positive value, a TTL index is created on _updated_at so 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, or null to disable automatic expiry
      Returns:
      this builder
    • onDeleteCallback

      public MongoAgentStateStore.Builder onDeleteCallback(BiConsumer<String,String> onDeleteCallback)
      Optional callback invoked before a session document is deleted via MongoAgentStateStore.delete(String, String). Receives the userId and sessionId. Used by MongoDistributedStore to cascade-delete associated snapshots.
      Parameters:
      onDeleteCallback - the callback (userId, sessionId) to run before session deletion
      Returns:
      this builder
    • build

      public MongoAgentStateStore build()
      Returns:
      a new instance