StaticLongTermMemoryHook
@Deprecated(forRemoval = true, since = "2.0.0") public class StaticLongTermMemoryHook implements Hook
io/agentscope/core/memory/StaticLongTermMemoryHook.java:77–300Static Long Term 记忆钩子,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.memory 包,实现 Hook。核心成员包括 onEvent、priority、getLongTermMemory、getMemory、StaticLongTermMemoryHook。
Static Long-Term Memory Hook for automatic memory management.
This hook implements the STATIC_CONTROL mode for long-term memory, where memory retrieval and recording are handled automatically by the framework without agent involvement. The hook:
-
Retrieves relevant memories before reasoning (PreReasoningEvent)
-
Injects retrieved memories as system messages for context
-
Records conversations to long-term memory after agent replies (PostCallEvent)
When to Use:
-
STATIC_CONTROL mode: Framework manages memory automatically
-
BOTH mode: Combined with agent control tools
Usage Example:
`LongTermMemory memory = Mem0LongTermMemory.builder()
.agentName("Assistant")
.userName("user_123")
.build();
StaticLongTermMemoryHook hook = new StaticLongTermMemoryHook(memory, agentMemory);
ReActAgent agent = ReActAgent.builder()
.name("Assistant")
.model(model)
.hook(hook) // Hook is automatically registered in STATIC_CONTROL/BOTH mode
.build();
`
Priority: This hook has high priority (50) to ensure memory is retrieved early in the event chain, before other processing occurs.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public StaticLongTermMemoryHook(LongTermMemory longTermMemory, Memory memory) | 初始化 `StaticLongTermMemoryHook` 实例。 Creates a new StaticLongTermMemoryHook with synchronous recording. |
public StaticLongTermMemoryHook(LongTermMemory longTermMemory, Memory memory, boolean asyncRecord) | 创建新的StaticLongTermMemoryHook。 Creates a new StaticLongTermMemoryHook. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public T extends HookEvent Mono<T> onEvent(T event) | 处理事件事件。 Performs the on event operation. |
public int priority() | 返回优先级。 Returns the priority. |
public LongTermMemory getLongTermMemory() | 获取 `getLongTermMemory`。 Gets the long-term memory instance used by this hook. |
public Memory getMemory() | 获取记忆。 Gets the memory instance used by this hook. |
构造器详情Constructor Detail
StaticLongTermMemoryHook
public StaticLongTermMemoryHook(LongTermMemory longTermMemory, Memory memory)
初始化 StaticLongTermMemoryHook 实例。
Creates a new StaticLongTermMemoryHook with synchronous recording.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
longTermMemory | LongTermMemory | long Term 记忆(类型 `LongTermMemory`)。The long-term memory instance for persistent storage |
memory | Memory | 记忆(类型 `Memory`)。The agent's memory for accessing conversation history |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if longTermMemory or memory is null
io/agentscope/core/memory/StaticLongTermMemoryHook.java:99–101StaticLongTermMemoryHook
public StaticLongTermMemoryHook(LongTermMemory longTermMemory, Memory memory, boolean asyncRecord)
创建新的StaticLongTermMemoryHook。
Creates a new StaticLongTermMemoryHook.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
longTermMemory | LongTermMemory | long Term 记忆(类型 `LongTermMemory`)。The long-term memory instance for persistent storage |
memory | Memory | 记忆(类型 `Memory`)。The agent's memory for accessing conversation history |
asyncRecord | boolean | 异步记录(类型 `boolean`)。Whether to record memories asynchronously (fire-and-forget) |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if longTermMemory or memory is null
io/agentscope/core/memory/StaticLongTermMemoryHook.java:111–122方法详情Method Detail
onEvent
public T extends HookEvent Mono<T> onEvent(T event)
处理事件事件。
Performs the on event operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
event | T | 事件(类型 `T`)。The event. |
Mono<T>io/agentscope/core/memory/StaticLongTermMemoryHook.java:124–136priority
public int priority()
返回优先级。
Returns the priority.
intio/agentscope/core/memory/StaticLongTermMemoryHook.java:138–142getLongTermMemory
public LongTermMemory getLongTermMemory()
获取 getLongTermMemory。
Gets the long-term memory instance used by this hook.
LongTermMemoryio/agentscope/core/memory/StaticLongTermMemoryHook.java:288–290getMemory
public Memory getMemory()
获取记忆。
Gets the memory instance used by this hook.
Memoryio/agentscope/core/memory/StaticLongTermMemoryHook.java:297–299