类 InMemoryMemory
java.lang.Object
io.agentscope.core.memory.InMemoryMemory
- 所有已实现的接口:
Memory,StateModule
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.
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidaddMessage(Msg message) Adds a message to the in-memory message list.voidclear()Clears all messages from memory.voiddeleteMessage(int index) Deletes a message at the specified index.Retrieves all non-null messages from memory.voidloadFrom(Session session, SessionKey sessionKey) Load memory state from the session.voidsaveTo(Session session, SessionKey sessionKey) Save memory state to the session.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 io.agentscope.core.state.StateModule
loadFrom, loadIfExists, loadIfExists, saveTo
-
构造器详细资料
-
InMemoryMemory
public InMemoryMemory()Constructor for InMemoryMemory.
-
-
方法详细资料
-
saveTo
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 tosessionKey- the session identifier
-
loadFrom
Load memory state from the session.- 指定者:
loadFrom在接口中StateModule- 参数:
session- the session to load state fromsessionKey- the session identifier
-
addMessage
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
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.
-