类 StaticLongTermMemoryHook
- 所有已实现的接口:
Hook
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.
- 另请参阅:
-
构造器概要
构造器构造器说明StaticLongTermMemoryHook(LongTermMemory longTermMemory, Memory memory) Creates a new StaticLongTermMemoryHook with synchronous recording.StaticLongTermMemoryHook(LongTermMemory longTermMemory, Memory memory, boolean asyncRecord) Creates a new StaticLongTermMemoryHook. -
方法概要
-
构造器详细资料
-
StaticLongTermMemoryHook
Creates a new StaticLongTermMemoryHook with synchronous recording.- 参数:
longTermMemory- The long-term memory instance for persistent storagememory- The agent's memory for accessing conversation history- 抛出:
IllegalArgumentException- if longTermMemory or memory is null
-
StaticLongTermMemoryHook
Creates a new StaticLongTermMemoryHook.- 参数:
longTermMemory- The long-term memory instance for persistent storagememory- The agent's memory for accessing conversation historyasyncRecord- Whether to record memories asynchronously (fire-and-forget)- 抛出:
IllegalArgumentException- if longTermMemory or memory is null
-
-
方法详细资料
-
onEvent
从接口复制的说明:HookHandle a hook event.This method is called for all agent execution events. Use pattern matching to handle specific event types.
Modifiable Events: For events with setters, you can modify the context and the changes will affect agent execution:
PreReasoningEvent- Modify messages before LLM reasoningPostReasoningEvent- Modify reasoning resultsPreActingEvent- Modify tool parameters before executionPostActingEvent- Modify tool resultsPreCallEvent- Modify messages before agent startsPostCallEvent- Modify final agent response
Notification Events: Events without setters are read-only:
ReasoningChunkEvent- Streaming reasoning chunksActingChunkEvent- Streaming tool execution chunksErrorEvent- Errors during execution
-
priority
public int priority()从接口复制的说明:HookThe priority of this hook (lower value = higher priority).Hooks are executed in ascending priority order. Hooks with the same priority execute in their registration order.
Common Priority Ranges:
- 0-50: Critical system hooks (auth, security)
- 51-100: High priority hooks (validation, preprocessing)
- 101-500: Normal priority hooks (business logic)
- 501-1000: Low priority hooks (logging, metrics)
-
getLongTermMemory
Gets the long-term memory instance used by this hook.- 返回:
- the long-term memory instance
-
getMemory
Gets the memory instance used by this hook.- 返回:
- the memory instance
-