接口 Memory

所有已知实现类:
AgentStateMemoryView, InMemoryMemory, StateBackedMemory

@Deprecated(forRemoval=true, since="2.0.0") public interface Memory
已过时, 待删除: 此 API 元素将从以后的版本中删除。
since 2.0.0. Conversation context is now held on AgentState.getContext(). This interface is retained as a write-only mirror for source compatibility with 1.0.x user code.
Interface for memory components that store and manage conversation history.

Different memory implementations can provide various storage strategies such as in-memory, database-backed, or window-based storage. saveTo(io.agentscope.core.state.AgentStateStore, java.lang.String, java.lang.String) / loadFrom(io.agentscope.core.state.AgentStateStore, java.lang.String, java.lang.String) let callers persist the message buffer through a AgentStateStore for legacy v1 sessions; new code should use AgentState instead.

  • 方法概要

    修饰符和类型
    方法
    说明
    void
    addMessage(Msg message)
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Adds a message to the memory.
    void
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Clears all messages from memory.
    void
    deleteMessage(int index)
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Deletes a message at the specified index.
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Retrieves all messages stored in memory.
    void
    loadFrom(AgentStateStore stateStore, String userId, String sessionId)
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Load a previously saved message buffer (no-op when none exists).
    void
    saveTo(AgentStateStore stateStore, String userId, String sessionId)
    已过时, 待删除: 此 API 元素将从以后的版本中删除。
    Save the message buffer under the memory_messages session key.
  • 方法详细资料

    • saveTo

      void saveTo(AgentStateStore stateStore, String userId, String sessionId)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Save the message buffer under the memory_messages session key.
    • loadFrom

      void loadFrom(AgentStateStore stateStore, String userId, String sessionId)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Load a previously saved message buffer (no-op when none exists).
    • addMessage

      void addMessage(Msg message)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Adds a message to the memory.
      参数:
      message - The message to store in memory
    • getMessages

      List<Msg> getMessages()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Retrieves all messages stored in memory.
      返回:
      A list of all messages (may be empty but never null)
    • deleteMessage

      void deleteMessage(int index)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      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()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      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.