Class SessionManager
java.lang.Object
uno.anahata.ai.context.session.SessionManager
Manages the persistence and summarization of chat sessions.
This class provides functionality to:
- Save and load conversation history using Kryo serialization.
- List available saved sessions.
- Perform automatic background backups of the current session.
- Generate a human-readable Markdown summary of the conversation context.
-
Constructor Summary
ConstructorsConstructorDescriptionSessionManager(ContextManager contextManager) Constructs a new SessionManager for the given ContextManager. -
Method Summary
Modifier and TypeMethodDescriptionString[]describePart(com.google.genai.types.Part p) Generates a concise description of a content part, including its type and a summary of its content.Generates a human-readable Markdown table summarizing the entire conversation context.Lists the names of all saved sessions in the sessions directory.voidloadSession(String id) Loads a conversation history from a saved session file.saveSession(String name) Saves the current conversation history to a file.Summarizes a single ChatMessage into Markdown table rows.voidTriggers an asynchronous automatic backup of the current session.
-
Constructor Details
-
SessionManager
Constructs a new SessionManager for the given ContextManager.- Parameters:
contextManager- The ContextManager to manage sessions for.
-
-
Method Details
-
saveSession
Saves the current conversation history to a file.- Parameters:
name- The name of the session (used as the filename).- Returns:
- A success message.
- Throws:
IOException- if an I/O error occurs during saving.
-
listSavedSessions
Lists the names of all saved sessions in the sessions directory.- Returns:
- A list of session names.
- Throws:
IOException- if an I/O error occurs while listing files.
-
loadSession
Loads a conversation history from a saved session file.This method restores the context and resets the message and tool call ID counters to ensure consistency in the resumed session.
- Parameters:
id- The name of the session to load.- Throws:
IOException- if the session file is not found or an error occurs during loading.
-
triggerAutobackup
public void triggerAutobackup()Triggers an asynchronous automatic backup of the current session. -
getSummaryAsString
Generates a human-readable Markdown table summarizing the entire conversation context.- Returns:
- A Markdown string containing the context summary.
-
summarizeMessage
Summarizes a single ChatMessage into Markdown table rows.- Parameters:
msg- The message to summarize.- Returns:
- A Markdown string representing the message's rows in the summary table.
-
describePart
Generates a concise description of a content part, including its type and a summary of its content.- Parameters:
p- The part to describe.- Returns:
- A String array where the first element is the type and the second is the content summary.
-
