AS AgentScopeAPI 手册 / API Reference

LongTermMemory

@Deprecated(forRemoval = true, since = "2.0.0") public interface LongTermMemory
源码Source io/agentscope/core/memory/LongTermMemory.java:70–111

定义 Long Term 记忆契约的接口。位于 io.agentscope.core.memory 包。核心成员包括 record、retrieve。

Abstract base class for long-term memory implementations.

This class provides a time-series memory management system that persists information beyond individual conversation sessions. Long-term memory enables agents to:

  • Remember user preferences, habits, and personal information across sessions

  • Learn from past interactions and improve over time

  • Maintain context for long-running tasks or projects

  • Build personalized experiences based on historical data

This class defines the core memory API for framework-level integration:

  • #record(List) - Record messages to memory (called by framework)

  • #retrieve(Msg) - Retrieve relevant memories (called by framework)

For agent-controlled memory operations (AGENT_CONTROL mode), use LongTermMemoryTools which provides tool functions that adapt these core methods for agent use.

All methods are asynchronous and return Reactor Mono types for non-blocking integration with the agent framework.

Usage Example:

`// Create long-term memory instance
LongTermMemoryBase longTermMemory = Mem0LongTermMemory.builder()
.agentName("Assistant")
.userName("user_123")
.apiBaseUrl("http://localhost:8000")
.build();

// Use in ReActAgent
ReActAgent agent = ReActAgent.builder()
.name("Assistant")
.model(model)
.longTermMemory(longTermMemory)
.longTermMemoryMode(LongTermMemoryMode.BOTH)
.build();
`

方法摘要Method Summary

方法Method说明Description
public Mono<Void> record(List<Msg> msgs)
设置记录。
Records messages to long-term memory.
public Mono<String> retrieve(Msg msg)
按查询检索相关文档。
Retrieves relevant information from long-term memory based on the input message.

方法详情Method Detail

record

public Mono<Void> record(List<Msg> msgs)

设置记录。

Records messages to long-term memory.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。List of messages to record (null entries are filtered out)
返回Returns Mono<Void>
返回Mono。A Mono that completes when recording is finished
源码Source io/agentscope/core/memory/LongTermMemory.java:91

retrieve

public Mono<String> retrieve(Msg msg)

按查询检索相关文档。

Retrieves relevant information from long-term memory based on the input message.

参数Parameters
名称Name类型Type说明Description
msgMsg消息到使用 as 查询用于记忆检索。The message to use as a query for memory retrieval
返回Returns Mono<String>
返回Mono。A Mono emitting the retrieved memory text (may be empty)
源码Source io/agentscope/core/memory/LongTermMemory.java:110
基于官方固定版本源码静态生成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.