Package com.google.genkit.ai.session
Class SessionData<S>
java.lang.Object
com.google.genkit.ai.session.SessionData<S>
- Type Parameters:
S- the type of the custom session state
SessionData represents the persistent data structure for a session, including
state and conversation threads.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.SessionData(String id) Creates a new SessionData with the given ID.SessionData(String id, S state) Creates a new SessionData with the given ID and initial state. -
Method Summary
Modifier and TypeMethodDescriptionstatic <S> SessionData.Builder<S> builder()Creates a builder for SessionData.getId()Gets the session ID.getOrCreateThread(String threadName) Gets or creates a thread by name.getState()Gets the session state.Gets a specific thread by name.Gets all conversation threads.voidSets the session ID.voidSets the session state.voidSets messages for a specific thread.voidsetThreads(Map<String, List<Message>> threads) Sets all conversation threads.
-
Constructor Details
-
SessionData
public SessionData()Default constructor. -
SessionData
Creates a new SessionData with the given ID.- Parameters:
id- the session ID
-
SessionData
Creates a new SessionData with the given ID and initial state.- Parameters:
id- the session IDstate- the initial state
-
-
Method Details
-
getId
Gets the session ID.- Returns:
- the session ID
-
setId
Sets the session ID.- Parameters:
id- the session ID
-
getState
Gets the session state.- Returns:
- the session state
-
setState
Sets the session state.- Parameters:
state- the session state
-
getThreads
Gets all conversation threads.- Returns:
- the threads map
-
setThreads
Sets all conversation threads.- Parameters:
threads- the threads map
-
getThread
Gets a specific thread by name.- Parameters:
threadName- the thread name- Returns:
- the list of messages in the thread, or null if not found
-
getOrCreateThread
Gets or creates a thread by name.- Parameters:
threadName- the thread name- Returns:
- the list of messages in the thread
-
setThread
Sets messages for a specific thread.- Parameters:
threadName- the thread namemessages- the messages to set
-
builder
Creates a builder for SessionData.- Type Parameters:
S- the state type- Returns:
- a new builder
-