AS AgentScopeAPI 手册 / API Reference

StaticLongTermMemoryHook

@Deprecated(forRemoval = true, since = "2.0.0") public class StaticLongTermMemoryHook implements Hook
源码Source io/agentscope/core/memory/StaticLongTermMemoryHook.java:77–300

Static 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.

参数Parameters
名称Name类型Type说明Description
longTermMemoryLongTermMemorylong Term 记忆(类型 `LongTermMemory`)。The long-term memory instance for persistent storage
memoryMemory记忆(类型 `Memory`)。The agent's memory for accessing conversation history
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if longTermMemory or memory is null
源码Source io/agentscope/core/memory/StaticLongTermMemoryHook.java:99–101

StaticLongTermMemoryHook

public StaticLongTermMemoryHook(LongTermMemory longTermMemory, Memory memory, boolean asyncRecord)

创建新的StaticLongTermMemoryHook。

Creates a new StaticLongTermMemoryHook.

参数Parameters
名称Name类型Type说明Description
longTermMemoryLongTermMemorylong Term 记忆(类型 `LongTermMemory`)。The long-term memory instance for persistent storage
memoryMemory记忆(类型 `Memory`)。The agent's memory for accessing conversation history
asyncRecordboolean异步记录(类型 `boolean`)。Whether to record memories asynchronously (fire-and-forget)
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if longTermMemory or memory is null
源码Source 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.

参数Parameters
名称Name类型Type说明Description
eventT事件(类型 `T`)。The event.
返回Returns Mono<T>
返回Mono。Returns mono.
源码Source io/agentscope/core/memory/StaticLongTermMemoryHook.java:124–136

priority

public int priority()

返回优先级。

Returns the priority.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/core/memory/StaticLongTermMemoryHook.java:138–142

getLongTermMemory

public LongTermMemory getLongTermMemory()

获取 getLongTermMemory。

Gets the long-term memory instance used by this hook.

返回Returns LongTermMemory
返回LongTermMemory。the long-term memory instance
源码Source io/agentscope/core/memory/StaticLongTermMemoryHook.java:288–290

getMemory

public Memory getMemory()

获取记忆。

Gets the memory instance used by this hook.

返回Returns Memory
记忆实例。the memory instance
源码Source io/agentscope/core/memory/StaticLongTermMemoryHook.java:297–299

继承成员Inherited Members

继承自Methods inherited from Hook
基于官方固定版本源码静态生成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.