接口 Memory
- 所有超级接口:
StateModule
- 所有已知实现类:
InMemoryMemory
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.
-
方法概要
修饰符和类型方法说明voidaddMessage(Msg message) Adds a message to the memory.voidclear()Clears all messages from memory.voiddeleteMessage(int index) Deletes a message at the specified index.Retrieves all messages stored in memory.从接口继承的方法 io.agentscope.core.state.StateModule
loadFrom, loadFrom, loadIfExists, loadIfExists, saveTo, saveTo
-
方法详细资料
-
addMessage
Adds a message to the memory.- 参数:
message- The message to store in memory
-
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.
-