Interface SessionMemory

All Known Implementing Classes:
SessionMemoryClient

public interface SessionMemory
Interface for managing contextual session history between users and AI models.

SessionMemory provides functionality to store, retrieve, and manage messages exchanged during interactions in an agent system. It enables agents to maintain context across multiple interactions within the same session.

Default Implementation: The default implementation is backed by SessionMemoryEntity, a built-in Event Sourced Entity that automatically stores contextual history. This provides durability and allows for session memory to be shared between multiple agents using the same session id.

Custom Implementation: You can provide a custom implementation using MemoryProvider.custom(SessionMemory) to store session memory in external databases or services.

Memory Management: Session memory can be configured to limit the amount of history retained, either by message count or total size, to control token usage and performance.

  • Method Details

    • addInteraction

      void addInteraction(String sessionId, SessionMessage.UserMessage userMessage, List<SessionMessage> messages)
      Adds an interaction between a user and an AI model to the session history for the specified session.
      Parameters:
      sessionId - The unique identifier for the contextual session
      userMessage - The content of the user message
      messages - All other messages generated during this interaction, typically AiMessage but also Tool Call responses.
    • getHistory

      SessionHistory getHistory(String sessionId)
      Retrieves the complete session history for the specified session. For very long sessions, this might return a compacted version of the history.
      Parameters:
      sessionId - The unique identifier for the contextual session
      Returns:
      The complete session history containing all messages