InMemoryMemory
@Deprecated(forRemoval = true, since = "2.0.0") public class InMemoryMemory implements Memory
源码Source
io/agentscope/core/memory/InMemoryMemory.java:36–134In 记忆记忆,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.memory 包,实现 Memory。核心成员包括 saveTo、loadFrom、addMessage、getMessages、deleteMessage、clear。
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.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public InMemoryMemory() | 初始化 `InMemoryMemory` 实例。 Constructor for InMemoryMemory. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void saveTo(AgentStateStore stateStore, String userId, String sessionId) | 保存到。 Save memory state to the session. |
public void loadFrom(AgentStateStore stateStore, String userId, String sessionId) | 加载来自。 Load memory state from the store. |
public void addMessage(Msg message) | 添加消息。 Adds a message to the in-memory message list. |
public List<Msg> getMessages() | 获取消息。 Retrieves all non-null messages from memory. |
public void deleteMessage(int index) | 删除消息。 Deletes a message at the specified index. |
public void clear() | 清空或重置内部状态。 Clears all messages from memory. |
构造器详情Constructor Detail
InMemoryMemory
public InMemoryMemory()
初始化 InMemoryMemory 实例。
Constructor for InMemoryMemory.
源码Source
io/agentscope/core/memory/InMemoryMemory.java:47方法详情Method Detail
saveTo
public void saveTo(AgentStateStore stateStore, String userId, String sessionId)
保存到。
Save memory state to the session.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stateStore | AgentStateStore | 状态存储到保存到。the state store to save to |
userId | String | 用户标识(类型 `String`)。the user identifier |
sessionId | String | 会话标识(类型 `String`)。the session identifier |
源码Source
io/agentscope/core/memory/InMemoryMemory.java:62–66loadFrom
public void loadFrom(AgentStateStore stateStore, String userId, String sessionId)
加载来自。
Load memory state from the store.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stateStore | AgentStateStore | 状态存储到加载来自。the state store to load from |
userId | String | 用户标识(类型 `String`)。nullable user identifier |
sessionId | String | 会话标识(类型 `String`)。session identifier |
源码Source
io/agentscope/core/memory/InMemoryMemory.java:75–81addMessage
public void addMessage(Msg message)
添加消息。
Adds a message to the in-memory message list.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
message | Msg | 消息到添加到记忆。The message to add to memory |
源码Source
io/agentscope/core/memory/InMemoryMemory.java:92–95getMessages
public List<Msg> getMessages()
获取消息。
Retrieves all non-null messages from memory.
List<Msg>返回列出。A new list containing all non-null messages
源码Source
io/agentscope/core/memory/InMemoryMemory.java:105–108deleteMessage
public void deleteMessage(int index)
删除消息。
Deletes a message at the specified index.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
index | int | 索引(类型 `int`)。The index of the message to delete (0-based) |
源码Source
io/agentscope/core/memory/InMemoryMemory.java:118–123clear
public void clear()
清空或重置内部状态。
Clears all messages from memory.
源码Source
io/agentscope/core/memory/InMemoryMemory.java:130–133