MemoryConsolidator
public class MemoryConsolidator
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.mdfiles written byMemoryFlushManager, 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_FILEstaticfinal | String | 状态文件字段。 Hidden state file inside `memory/` tracking the last consolidation Instant. |
DEFAULT_CONSOLIDATION_PROMPTstaticfinal | String | 默认 CONSOLIDATION 提示词字段。 Default prompt for the consolidation step. |
构造器摘要Constructor Summary
方法摘要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
状态文件字段。声明为 public static final String STATE_FILE。
Hidden state file inside memory/ tracking the last consolidation Instant.
io/agentscope/harness/agent/memory/MemoryConsolidator.java:66DEFAULT_CONSOLIDATION_PROMPT
public static final String DEFAULT_CONSOLIDATION_PROMPT
默认 CONSOLIDATION 提示词字段。声明为 public static final String DEFAULT_CONSOLIDATION_PROMPT。
Default prompt for the consolidation step.
io/agentscope/harness/agent/memory/MemoryConsolidator.java:74–98构造器详情Constructor Detail
MemoryConsolidator
public MemoryConsolidator(WorkspaceManager workspaceManager, Model model)
初始化 MemoryConsolidator 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
model | Model | 模型实例(类型 `Model`)。The model. |
io/agentscope/harness/agent/memory/MemoryConsolidator.java:110–112MemoryConsolidator
public MemoryConsolidator(WorkspaceManager workspaceManager, Model model, int maxMemoryTokens)
初始化 MemoryConsolidator 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
model | Model | 模型实例(类型 `Model`)。The model. |
maxMemoryTokens | int | 最大记忆令牌数(类型 `int`)。The max memory tokens. |
io/agentscope/harness/agent/memory/MemoryConsolidator.java:114–116MemoryConsolidator
public MemoryConsolidator(WorkspaceManager workspaceManager, Model model, String consolidationPrompt, int maxMemoryTokens)
初始化 MemoryConsolidator 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
model | Model | 模型实例(类型 `Model`)。The model. |
consolidationPrompt | String | consolidation 提示词(类型 `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`. |
maxMemoryTokens | int | 最大记忆令牌数(类型 `int`)。The max memory tokens. |
io/agentscope/harness/agent/memory/MemoryConsolidator.java:123–129MemoryConsolidator
public MemoryConsolidator(WorkspaceManager workspaceManager, Model model, String consolidationPrompt, int maxMemoryTokens, BaseStore baseStore)
初始化 MemoryConsolidator 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspaceManager | WorkspaceManager | 工作区管理器(类型 `WorkspaceManager`)。The workspace manager. |
model | Model | 模型实例(类型 `Model`)。The model. |
consolidationPrompt | String | consolidation 提示词(类型 `String`)。The consolidation prompt. |
maxMemoryTokens | int | 最大记忆令牌数(类型 `int`)。The max memory tokens. |
baseStore | BaseStore | 基类存储(类型 `BaseStore`)。optional distributed store for the consolidation watermark; when set, watermark reads prefer the store and writes use CAS with a filesystem fallback |
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
Mono<Void>io/agentscope/harness/agent/memory/MemoryConsolidator.java:156–220