AS AgentScopeAPI 手册 / API Reference

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
stateAgentState状态对象(类型 `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
messageMsg消息(类型 `Msg`)。The message.
源码Source io/agentscope/core/memory/StateBackedMemory.java:44–47

getMessages

public List<Msg> getMessages()

获取消息。

Returns the messages.

返回Returns List<Msg>
返回列出。Returns list.
源码Source io/agentscope/core/memory/StateBackedMemory.java:49–52

deleteMessage

public void deleteMessage(int index)

删除消息。

Deletes the message.

参数Parameters
名称Name类型Type说明Description
indexint索引(类型 `int`)。The index.
源码Source io/agentscope/core/memory/StateBackedMemory.java:54–60

clear

public void clear()

清空或重置内部状态。

Clears or resets internal state.

源码Source io/agentscope/core/memory/StateBackedMemory.java:62–65

saveTo

public void saveTo(AgentStateStore stateStore, String userId, String sessionId)

保存到。

Saves the to.

参数Parameters
名称Name类型Type说明Description
stateStoreAgentStateStore状态存储(类型 `AgentStateStore`)。The state store.
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
源码Source io/agentscope/core/memory/StateBackedMemory.java:67–71

loadFrom

public void loadFrom(AgentStateStore stateStore, String userId, String sessionId)

加载来自。

Loads the from.

参数Parameters
名称Name类型Type说明Description
stateStoreAgentStateStore状态存储(类型 `AgentStateStore`)。The state store.
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
源码Source io/agentscope/core/memory/StateBackedMemory.java:73–78
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.