接口 Memory

所有超级接口:
StateModule
所有已知实现类:
InMemoryMemory

public interface Memory extends StateModule
Interface for memory components that store and manage conversation history.

Memory extends StateModule to provide state persistence capabilities, allowing conversation history to be saved and restored through sessions. Different memory implementations can provide various storage strategies such as in-memory, database-backed, or window-based storage.

  • 方法详细资料

    • addMessage

      void addMessage(Msg message)
      Adds a message to the memory.
      参数:
      message - The message to store in memory
    • getMessages

      List<Msg> getMessages()
      Retrieves all messages stored in memory.
      返回:
      A list of all messages (may be empty but never null)
    • deleteMessage

      void deleteMessage(int index)
      Deletes a message at the specified index.

      If the index is out of bounds (negative or >= size), this operation should be a no-op rather than throwing an exception. This provides safe cleanup even with concurrent modifications.

      参数:
      index - The index of the message to delete (0-based)
    • clear

      void clear()
      Clears all messages from memory.

      This operation removes all stored conversation history. Use with caution as this action is typically irreversible unless state has been persisted.