AS AgentScopeAPI 手册 / API Reference

LongTermMemoryTools

@Deprecated(forRemoval = true, since = "2.0.0") public class LongTermMemoryTools
源码Source io/agentscope/core/memory/LongTermMemoryTools.java:66–215

Long 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_CONTROL mode 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.

参数Parameters
名称Name类型Type说明Description
memoryLongTermMemory记忆(类型 `LongTermMemory`)。The long-term memory instance to adapt
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if memory is null
源码Source io/agentscope/core/memory/LongTermMemoryTools.java:77–82

方法详情Method Detail

wrap

public static String wrap(String text)
static

设置该参数。

Performs the wrap operation.

参数Parameters
名称Name类型Type说明Description
textString文本(类型 `String`)。The text.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/memory/LongTermMemoryTools.java:87–94

recordToMemory

public Mono<String> recordToMemory(String thinking, List<String> content)

执行 recordToMemory 方法。

Tool function for agent to record important information to long-term memory.

参数Parameters
名称Name类型Type说明Description
thinkingStringthinking(类型 `String`)。Agent's reasoning about what to record and why
contentList<String>内容(类型 `List`)。List of specific facts to remember (should be clear and concise)
返回Returns Mono<String>
返回Mono。A status message indicating success or failure
源码Source io/agentscope/core/memory/LongTermMemoryTools.java:103–152

retrieveFromMemory

public Mono<String> retrieveFromMemory(List<String> keywords)

检索来自记忆。

Tool function for agent to retrieve information from long-term memory.

参数Parameters
名称Name类型Type说明Description
keywordsList<String>keywords(类型 `List`)。List of keywords to search for (should be specific and relevant)
返回Returns Mono<String>
返回Mono。The retrieved memories as text
源码Source io/agentscope/core/memory/LongTermMemoryTools.java:181–214
基于官方固定版本源码静态生成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.