类 InMemoryMemory

java.lang.Object
io.agentscope.core.memory.InMemoryMemory
所有已实现的接口:
Memory, StateModule

public class InMemoryMemory extends Object implements Memory
In-memory implementation of Memory with state persistence support. This implementation stores messages in memory using thread-safe collections and provides state serialization/deserialization for session management.
  • 构造器详细资料

    • InMemoryMemory

      public InMemoryMemory()
      Constructor for InMemoryMemory.
  • 方法详细资料

    • saveTo

      public void saveTo(Session session, SessionKey sessionKey)
      Save memory state to the session.

      Passes the full message list to the session, including the case where the list is empty. The Session implementation is responsible for incremental storage (e.g., JsonSession appends only new items based on file line count).

      指定者:
      saveTo 在接口中 StateModule
      参数:
      session - the session to save state to
      sessionKey - the session identifier
    • loadFrom

      public void loadFrom(Session session, SessionKey sessionKey)
      Load memory state from the session.
      指定者:
      loadFrom 在接口中 StateModule
      参数:
      session - the session to load state from
      sessionKey - the session identifier
    • addMessage

      public void addMessage(Msg message)
      Adds a message to the in-memory message list.

      This method is thread-safe due to the use of CopyOnWriteArrayList.

      指定者:
      addMessage 在接口中 Memory
      参数:
      message - The message to add to memory
    • getMessages

      public List<Msg> getMessages()
      Retrieves all non-null messages from memory.

      This method filters out any null entries and returns a new list copy. Thread-safe for concurrent reads.

      指定者:
      getMessages 在接口中 Memory
      返回:
      A new list containing all non-null messages
    • deleteMessage

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

      This method is thread-safe due to the use of CopyOnWriteArrayList. If the index is out of bounds, this operation is a no-op (no exception thrown).

      指定者:
      deleteMessage 在接口中 Memory
      参数:
      index - The index of the message to delete (0-based)
    • clear

      public void clear()
      Clears all messages from memory.

      This method is thread-safe due to the use of CopyOnWriteArrayList.

      指定者:
      clear 在接口中 Memory