Class MemoryConsolidator
java.lang.Object
io.agentscope.harness.agent.memory.MemoryConsolidator
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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMemoryConsolidator(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model) MemoryConsolidator(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, int maxMemoryTokens) MemoryConsolidator(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String consolidationPrompt, int maxMemoryTokens) MemoryConsolidator(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String consolidationPrompt, int maxMemoryTokens, BaseStore baseStore) -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>consolidate(io.agentscope.core.agent.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 Details
-
STATE_FILE
Hidden state file insidememory/tracking the last consolidation Instant.- See Also:
-
DEFAULT_CONSOLIDATION_PROMPT
Default prompt for the consolidation step. Exposed publicly so callers can extend (e.g. append project-specific guidelines) when constructingMemoryConfig. The prompt contains exactly two%dplaceholders (max-tokens, max-chars) that are filled in at call time.
-
-
Constructor Details
-
MemoryConsolidator
-
MemoryConsolidator
public MemoryConsolidator(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, int maxMemoryTokens) -
MemoryConsolidator
public MemoryConsolidator(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String consolidationPrompt, int maxMemoryTokens) - Parameters:
consolidationPrompt- prompt template for the consolidation LLM call. Must contain exactly two%dplaceholders (max-tokens, max-chars).nullfalls back toDEFAULT_CONSOLIDATION_PROMPT.
-
MemoryConsolidator
public MemoryConsolidator(WorkspaceManager workspaceManager, io.agentscope.core.model.Model model, String consolidationPrompt, int maxMemoryTokens, BaseStore baseStore) - Parameters:
baseStore- optional distributed store for the consolidation watermark; when set, watermark reads prefer the store and writes use CAS with a filesystem fallback
-
-
Method Details
-
consolidate
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.If no daily files have been touched since the last run, this is a no-op.
-