LongTermMemoryTools
@Deprecated(forRemoval = true, since = "2.0.0") public class LongTermMemoryTools
io/agentscope/core/memory/LongTermMemoryTools.java:66–215Long Term 记忆工具,封装可被智能体调用的能力。位于 io.agentscope.core.memory 包。核心成员包括 wrap、recordToMemory、retrieveFromMemory、LongTermMemoryTools。
Tool adapter that exposes long-term memory operations as agent-callable tools.
This class provides a clean separation between the core memory API (defined in
LongTermMemory) and the tool interface used by agents. It adapts the
developer-facing record() and retrieve() methods into tool functions
with agent-friendly signatures.
Architecture:
-
LongTermMemoryBase: Defines core storage API (
record(),retrieve()) -
LongTermMemoryTools: Adapts core API to tool interface for agent control
-
ReActAgent: Registers tools when
AGENT_CONTROLmode is enabled
Usage Example:
`// Create long-term memory instance
LongTermMemoryBase memory = Mem0LongTermMemory.builder()
.agentName("Assistant")
.userName("user_123")
.build();
// Create tool adapter
LongTermMemoryTools tools = new LongTermMemoryTools(memory);
// Register in ReActAgent (done automatically by framework)
ReActAgent agent = ReActAgent.builder()
.name("Assistant")
.model(model)
.longTermMemory(memory)
.longTermMemoryMode(LongTermMemoryMode.AGENT_CONTROL)
.build();
`
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public LongTermMemoryTools(LongTermMemory memory) | 初始化 `LongTermMemoryTools` 实例。 Creates a new tool adapter for the given long-term memory instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static String wrap(String text)static | 设置该参数。 Performs the wrap operation. |
public Mono<String> recordToMemory(String thinking, List<String> content) | 执行 `recordToMemory` 方法。 Tool function for agent to record important information to long-term memory. |
public Mono<String> retrieveFromMemory(List<String> keywords) | 检索来自记忆。 Tool function for agent to retrieve information from long-term memory. |
构造器详情Constructor Detail
LongTermMemoryTools
public LongTermMemoryTools(LongTermMemory memory)
初始化 LongTermMemoryTools 实例。
Creates a new tool adapter for the given long-term memory instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
memory | LongTermMemory | 记忆(类型 `LongTermMemory`)。The long-term memory instance to adapt |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if memory is null
io/agentscope/core/memory/LongTermMemoryTools.java:77–82方法详情Method Detail
wrap
public static String wrap(String text)
设置该参数。
Performs the wrap operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
text | String | 文本(类型 `String`)。The text. |
Stringio/agentscope/core/memory/LongTermMemoryTools.java:87–94recordToMemory
public Mono<String> recordToMemory(String thinking, List<String> content)
执行 recordToMemory 方法。
Tool function for agent to record important information to long-term memory.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
thinking | String | thinking(类型 `String`)。Agent's reasoning about what to record and why |
content | List<String> | 内容(类型 `List`)。List of specific facts to remember (should be clear and concise) |
Mono<String>io/agentscope/core/memory/LongTermMemoryTools.java:103–152retrieveFromMemory
public Mono<String> retrieveFromMemory(List<String> keywords)
检索来自记忆。
Tool function for agent to retrieve information from long-term memory.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
keywords | List<String> | keywords(类型 `List`)。List of keywords to search for (should be specific and relevant) |
Mono<String>io/agentscope/core/memory/LongTermMemoryTools.java:181–214