类 StaticLongTermMemoryHook

java.lang.Object
io.agentscope.core.memory.StaticLongTermMemoryHook
所有已实现的接口:
Hook

public class StaticLongTermMemoryHook extends Object implements Hook
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:

  1. Retrieves relevant memories before reasoning (PreReasoningEvent)
  2. Injects retrieved memories as system messages for context
  3. 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

      public StaticLongTermMemoryHook(LongTermMemory longTermMemory, Memory memory)
      Creates a new StaticLongTermMemoryHook with synchronous recording.
      参数:
      longTermMemory - The long-term memory instance for persistent storage
      memory - The agent's memory for accessing conversation history
      抛出:
      IllegalArgumentException - if longTermMemory or memory is null
    • StaticLongTermMemoryHook

      public StaticLongTermMemoryHook(LongTermMemory longTermMemory, Memory memory, boolean asyncRecord)
      Creates a new StaticLongTermMemoryHook.
      参数:
      longTermMemory - The long-term memory instance for persistent storage
      memory - The agent's memory for accessing conversation history
      asyncRecord - Whether to record memories asynchronously (fire-and-forget)
      抛出:
      IllegalArgumentException - if longTermMemory or memory is null
  • 方法详细资料

    • onEvent

      public <T extends HookEvent> reactor.core.publisher.Mono<T> onEvent(T event)
      从接口复制的说明: Hook
      Handle 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:

      Notification Events: Events without setters are read-only:

      指定者:
      onEvent 在接口中 Hook
      类型参数:
      T - The concrete event type
      参数:
      event - The hook event
      返回:
      Mono containing the potentially modified event
    • priority

      public int priority()
      从接口复制的说明: Hook
      The 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)
      指定者:
      priority 在接口中 Hook
      返回:
      The priority value (default: 100)
    • getLongTermMemory

      public LongTermMemory getLongTermMemory()
      Gets the long-term memory instance used by this hook.
      返回:
      the long-term memory instance
    • getMemory

      public Memory getMemory()
      Gets the memory instance used by this hook.
      返回:
      the memory instance