RoomSessionService

A persistent SessionService backed by a Room/SQLite database in the consumer app's private storage.

Sessions, events, and app/user state survive process death and device reboot. Use this in place of InMemorySessionService when constructing a com.google.adk.kt.runners.Runner in an Android consumer app.

Default usage — one instance per Application:

val sessionService = RoomSessionService.fromContext(applicationContext)

Pass a distinct databaseName to give an agent its own SQLite file (e.g. when two agents in the same app should not see each other's sessions even within the same appName):

val agentASessions = RoomSessionService.fromContext(context, "agent_a.db")
val agentBSessions = RoomSessionService.fromContext(context, "agent_b.db")

Dispatching is handled by Room — suspend fun DAO calls run on Room's internal transaction executor, so this class does not need to wrap calls in withContext.

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun appendEvent(session: Session, event: Event): Event

Appends an event to an in-memory session object and updates the session's state based on the event's state delta, if applicable.

Link copied to clipboard
fun close()

Closes the underlying Room database, releasing the file handle. Primarily useful for tests that construct and destroy services repeatedly. In a normal app the database stays open for the process lifetime — Android does not require explicit close.

Link copied to clipboard
open suspend fun closeSession(session: Session)

Closes a session.

Link copied to clipboard
open suspend override fun createSession(key: SessionKey, state: Map<String, Any>?): Session

Creates a new session with the specified parameters.

Link copied to clipboard
open suspend override fun deleteSession(key: SessionKey)

Deletes a specific session.

Link copied to clipboard
open suspend override fun getSession(key: SessionKey, config: GetSessionConfig?): Session?

Retrieves a specific session, optionally filtering the events included.

Link copied to clipboard
open suspend override fun listEvents(key: SessionKey): ListEventsResponse

Lists the events within a specific session.

Link copied to clipboard
open suspend override fun listSessions(appName: String, userId: String): ListSessionsResponse

Lists sessions associated with a specific application and user.