StateBackedMemory
@Deprecated(forRemoval = true, since = "2.0.0") public class StateBackedMemory implements Memory
源码Source
io/agentscope/core/memory/StateBackedMemory.java:35–79状态 Backed 记忆,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.memory 包,实现 Memory。核心成员包括 addMessage、getMessages、deleteMessage、clear、saveTo、loadFrom。
A Memory implementation that delegates all reads and writes to
AgentState#contextMutable().
This adapter exists solely to preserve backward compatibility for code that
accesses conversation history via agent.getMemory().getMessages().
The canonical location of conversation context in 2.0 is
AgentState#getContext().
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public StateBackedMemory(AgentState state) | 初始化 `StateBackedMemory` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public void addMessage(Msg message) | 添加消息。 Adds the message. |
public List<Msg> getMessages() | 获取消息。 Returns the messages. |
public void deleteMessage(int index) | 删除消息。 Deletes the message. |
public void clear() | 清空或重置内部状态。 Clears or resets internal state. |
public void saveTo(AgentStateStore stateStore, String userId, String sessionId) | 保存到。 Saves the to. |
public void loadFrom(AgentStateStore stateStore, String userId, String sessionId) | 加载来自。 Loads the from. |
构造器详情Constructor Detail
StateBackedMemory
public StateBackedMemory(AgentState state)
初始化 StateBackedMemory 实例。
Creates a new instance.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
state | AgentState | 状态对象(类型 `AgentState`)。The state. |
源码Source
io/agentscope/core/memory/StateBackedMemory.java:40–42方法详情Method Detail
addMessage
public void addMessage(Msg message)
添加消息。
Adds the message.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
message | Msg | 消息(类型 `Msg`)。The message. |
源码Source
io/agentscope/core/memory/StateBackedMemory.java:44–47getMessages
public List<Msg> getMessages()
获取消息。
Returns the messages.
List<Msg>返回列出。Returns list.
源码Source
io/agentscope/core/memory/StateBackedMemory.java:49–52deleteMessage
public void deleteMessage(int index)
删除消息。
Deletes the message.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
index | int | 索引(类型 `int`)。The index. |
源码Source
io/agentscope/core/memory/StateBackedMemory.java:54–60clear
public void clear()
清空或重置内部状态。
Clears or resets internal state.
源码Source
io/agentscope/core/memory/StateBackedMemory.java:62–65saveTo
public void saveTo(AgentStateStore stateStore, String userId, String sessionId)
保存到。
Saves the to.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stateStore | AgentStateStore | 状态存储(类型 `AgentStateStore`)。The state store. |
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
源码Source
io/agentscope/core/memory/StateBackedMemory.java:67–71loadFrom
public void loadFrom(AgentStateStore stateStore, String userId, String sessionId)
加载来自。
Loads the from.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stateStore | AgentStateStore | 状态存储(类型 `AgentStateStore`)。The state store. |
userId | String | 用户标识(类型 `String`)。The user id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
源码Source
io/agentscope/core/memory/StateBackedMemory.java:73–78