AS AgentScopeAPI 手册 / API Reference

MemoryConsolidator

public class MemoryConsolidator
源码Source io/agentscope/harness/agent/memory/MemoryConsolidator.java:61–385

记忆 Consolidator,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.harness.agent.memory 包。核心成员包括 consolidate、MemoryConsolidator、STATE_FILE、DEFAULT_CONSOLIDATION_PROMPT。

LLM-based consolidation of daily memory ledgers into the curated MEMORY.md.

This component owns the second layer of the two-layer memory model:

  • Layer 1 — daily ledger: memory/YYYY-MM-DD.md files written by MemoryFlushManager, append-only, one section per compaction flush.

  • Layer 2 — curated MEMORY.md: Owned by this class. Periodically reads the daily ledgers (those modified since the last consolidation watermark) plus the current MEMORY.md, asks the LLM to merge / dedupe / trim, and overwrites MEMORY.md with the result.

A small state file (memory/.consolidation_state) records the timestamp of the last successful consolidation. Daily files whose modifiedAt is at or before that timestamp are skipped — reducing token usage and protecting MEMORY.md from being re-rewritten with stale content.

All file I/O is performed via the AbstractFilesystem obtained from the WorkspaceManager, so this class is backend-agnostic (works with Local, Sandbox, and Remote filesystems without any direct java.nio.file.Files usage).

字段摘要Field Summary

字段Field类型Type说明Description
STATE_FILE
staticfinal
String
状态文件字段。
Hidden state file inside `memory/` tracking the last consolidation Instant.
DEFAULT_CONSOLIDATION_PROMPT
staticfinal
String
默认 CONSOLIDATION 提示词字段。
Default prompt for the consolidation step.

构造器摘要Constructor Summary

构造器Constructor说明Description
public MemoryConsolidator(WorkspaceManager workspaceManager, Model model)
初始化 `MemoryConsolidator` 实例。
Creates a new instance.
public MemoryConsolidator(WorkspaceManager workspaceManager, Model model, int maxMemoryTokens)
初始化 `MemoryConsolidator` 实例。
Creates a new instance.
public MemoryConsolidator(WorkspaceManager workspaceManager, Model model, String consolidationPrompt, int maxMemoryTokens)
初始化 `MemoryConsolidator` 实例。
Creates a new instance.
public MemoryConsolidator(WorkspaceManager workspaceManager, Model model, String consolidationPrompt, int maxMemoryTokens, BaseStore baseStore)
初始化 `MemoryConsolidator` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public Mono<Void> consolidate(RuntimeContext rc)
设置该参数。
Runs consolidation: reads daily files modified after the last watermark and the current MEMORY.md, uses the LLM to merge them, overwrites MEMORY.md, and advances the watermark on success.

字段详情Field Detail

STATE_FILE

public static final String STATE_FILE
staticfinal

状态文件字段。声明为 public static final String STATE_FILE。

Hidden state file inside memory/ tracking the last consolidation Instant.

源码Source io/agentscope/harness/agent/memory/MemoryConsolidator.java:66

DEFAULT_CONSOLIDATION_PROMPT

public static final String DEFAULT_CONSOLIDATION_PROMPT
staticfinal

默认 CONSOLIDATION 提示词字段。声明为 public static final String DEFAULT_CONSOLIDATION_PROMPT。

Default prompt for the consolidation step.

源码Source io/agentscope/harness/agent/memory/MemoryConsolidator.java:74–98

构造器详情Constructor Detail

MemoryConsolidator

public MemoryConsolidator(WorkspaceManager workspaceManager, Model model)

初始化 MemoryConsolidator 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
modelModel模型实例(类型 `Model`)。The model.
源码Source io/agentscope/harness/agent/memory/MemoryConsolidator.java:110–112

MemoryConsolidator

public MemoryConsolidator(WorkspaceManager workspaceManager, Model model, int maxMemoryTokens)

初始化 MemoryConsolidator 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
modelModel模型实例(类型 `Model`)。The model.
maxMemoryTokensint最大记忆令牌数(类型 `int`)。The max memory tokens.
源码Source io/agentscope/harness/agent/memory/MemoryConsolidator.java:114–116

MemoryConsolidator

public MemoryConsolidator(WorkspaceManager workspaceManager, Model model, String consolidationPrompt, int maxMemoryTokens)

初始化 MemoryConsolidator 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
modelModel模型实例(类型 `Model`)。The model.
consolidationPromptStringconsolidation 提示词(类型 `String`)。prompt template for the consolidation LLM call. Must contain exactly two `%d` placeholders (max-tokens, max-chars). `null` falls back to `#DEFAULT_CONSOLIDATION_PROMPT`.
maxMemoryTokensint最大记忆令牌数(类型 `int`)。The max memory tokens.
源码Source io/agentscope/harness/agent/memory/MemoryConsolidator.java:123–129

MemoryConsolidator

public MemoryConsolidator(WorkspaceManager workspaceManager, Model model, String consolidationPrompt, int maxMemoryTokens, BaseStore baseStore)

初始化 MemoryConsolidator 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
workspaceManagerWorkspaceManager工作区管理器(类型 `WorkspaceManager`)。The workspace manager.
modelModel模型实例(类型 `Model`)。The model.
consolidationPromptStringconsolidation 提示词(类型 `String`)。The consolidation prompt.
maxMemoryTokensint最大记忆令牌数(类型 `int`)。The max memory tokens.
baseStoreBaseStore基类存储(类型 `BaseStore`)。optional distributed store for the consolidation watermark; when set, watermark reads prefer the store and writes use CAS with a filesystem fallback
源码Source io/agentscope/harness/agent/memory/MemoryConsolidator.java:135–147

方法详情Method Detail

consolidate

public Mono<Void> consolidate(RuntimeContext rc)

设置该参数。

Runs consolidation: reads daily files modified after the last watermark and the current MEMORY.md, uses the LLM to merge them, overwrites MEMORY.md, and advances the watermark on success.

参数Parameters
名称Name类型Type说明Description
rcRuntimeContextrc(类型 `RuntimeContext`)。The rc.
返回Returns Mono<Void>
返回Mono。Returns mono.
源码Source io/agentscope/harness/agent/memory/MemoryConsolidator.java:156–220
基于官方固定版本源码静态生成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.