InMemoryChatbot

abstract class InMemoryChatbot(maxSessions: Int = 1000, evictionBatchSize: Int = maxOf(1, maxSessions / 10)) : Chatbot

Abstract implementation of Chatbot that maintains sessions in memory. This implementation is thread-safe and supports configurable maximum number of sessions. When the maximum number of sessions is reached, the oldest sessions are evicted to make room for new ones.

Parameters

maxSessions

The maximum number of concurrent chat sessions to maintain. Defaults to 1000.

evictionBatchSize

The number of sessions to evict when the limit is reached. Defaults to 10% of maxSessions.

Constructors

Link copied to clipboard
constructor(maxSessions: Int = 1000, evictionBatchSize: Int = maxOf(1, maxSessions / 10))

Functions

Link copied to clipboard

Clears all sessions from memory.

Link copied to clipboard
override fun createSession(user: User?, systemMessage: String?): ChatSession

Creates a new chat session and automatically registers it with the chatbot. Subclasses must implement doCreateSession to provide their specific session implementation.

Link copied to clipboard
override fun findSession(conversationId: String): ChatSession?

Finds an existing chat session by its conversation ID.

Link copied to clipboard

Gets all active conversation IDs.

Link copied to clipboard

Gets the current number of active sessions.

Link copied to clipboard

Gets the maximum number of sessions that can be maintained.

Link copied to clipboard
fun removeSession(conversationId: String): Boolean

Removes a chat session from the chatbot.