AS AgentScopeAPI 手册 / API Reference

AgentStateMemoryView

@Deprecated(forRemoval = true, since = "2.0.0") public final class AgentStateMemoryView implements Memory
源码Source io/agentscope/core/memory/AgentStateMemoryView.java:42–86

智能体状态记忆 View,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.memory 包,实现 Memory。核心成员包括 getMessages、addMessage、deleteMessage、clear、saveTo、loadFrom。

Read-only Memory adapter that proxies #getMessages() to a live AgentState#getContext() resolved at call time.

Exists solely so deprecated 1.x hooks and tools (notably StaticLongTermMemoryHook) keep working after the 2.0 builder dropped agent-owned Memory. All mutating operations throw UnsupportedOperationException; mutate context via AgentState.context instead.

The Supplier contract is "best-effort": a null return is interpreted as "agent not yet bound" and surfaces as an empty message list rather than an exception, so callers may instantiate the view before the owning io.agentscope.core.ReActAgent is constructed.

构造器摘要Constructor Summary

构造器Constructor说明Description
public AgentStateMemoryView(Supplier<AgentState> stateSupplier)
初始化 `AgentStateMemoryView` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public List<Msg> getMessages()
获取消息。
Returns the messages.
public void addMessage(Msg message)
添加消息。
Adds the message.
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

AgentStateMemoryView

public AgentStateMemoryView(Supplier<AgentState> stateSupplier)

初始化 AgentStateMemoryView 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
stateSupplierSupplier<AgentState>状态 Supplier(类型 `Supplier`)。The state supplier.
源码Source io/agentscope/core/memory/AgentStateMemoryView.java:47–49

方法详情Method Detail

getMessages

public List<Msg> getMessages()

获取消息。

Returns the messages.

返回Returns List<Msg>
返回列出。Returns list.
源码Source io/agentscope/core/memory/AgentStateMemoryView.java:51–55

addMessage

public void addMessage(Msg message)

添加消息。

Adds the message.

参数Parameters
名称Name类型Type说明Description
messageMsg消息(类型 `Msg`)。The message.
源码Source io/agentscope/core/memory/AgentStateMemoryView.java:57–60

deleteMessage

public void deleteMessage(int index)

删除消息。

Deletes the message.

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

clear

public void clear()

清空或重置内部状态。

Clears or resets internal state.

源码Source io/agentscope/core/memory/AgentStateMemoryView.java:67–70

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/AgentStateMemoryView.java:72–75

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/AgentStateMemoryView.java:77–80
基于官方固定版本源码静态生成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.