LongTermMemory
@Deprecated(forRemoval = true, since = "2.0.0") public interface LongTermMemory
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。List of messages to record (null entries are filtered out) |
Mono<Void>io/agentscope/core/memory/LongTermMemory.java:91retrieve
public Mono<String> retrieve(Msg msg)
按查询检索相关文档。
Retrieves relevant information from long-term memory based on the input message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息到使用 as 查询用于记忆检索。The message to use as a query for memory retrieval |
Mono<String>io/agentscope/core/memory/LongTermMemory.java:110