Class SessionData<S>

java.lang.Object
com.google.genkit.ai.session.SessionData<S>
Type Parameters:
S - the type of the custom session state

public class SessionData<S> extends Object
SessionData represents the persistent data structure for a session, including state and conversation threads.
  • Constructor Details

    • SessionData

      public SessionData()
      Default constructor.
    • SessionData

      public SessionData(String id)
      Creates a new SessionData with the given ID.
      Parameters:
      id - the session ID
    • SessionData

      public SessionData(String id, S state)
      Creates a new SessionData with the given ID and initial state.
      Parameters:
      id - the session ID
      state - the initial state
  • Method Details

    • getId

      public String getId()
      Gets the session ID.
      Returns:
      the session ID
    • setId

      public void setId(String id)
      Sets the session ID.
      Parameters:
      id - the session ID
    • getState

      public S getState()
      Gets the session state.
      Returns:
      the session state
    • setState

      public void setState(S state)
      Sets the session state.
      Parameters:
      state - the session state
    • getThreads

      public Map<String,List<Message>> getThreads()
      Gets all conversation threads.
      Returns:
      the threads map
    • setThreads

      public void setThreads(Map<String,List<Message>> threads)
      Sets all conversation threads.
      Parameters:
      threads - the threads map
    • getThread

      public List<Message> getThread(String threadName)
      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

      public List<Message> getOrCreateThread(String threadName)
      Gets or creates a thread by name.
      Parameters:
      threadName - the thread name
      Returns:
      the list of messages in the thread
    • setThread

      public void setThread(String threadName, List<Message> messages)
      Sets messages for a specific thread.
      Parameters:
      threadName - the thread name
      messages - the messages to set
    • builder

      public static <S> SessionData.Builder<S> builder()
      Creates a builder for SessionData.
      Type Parameters:
      S - the state type
      Returns:
      a new builder