Class CompactionConfig
java.lang.Object
io.agentscope.harness.agent.memory.compaction.CompactionConfig
Configuration for conversation compaction (summarization).
- trigger — when to run compaction (by token count or message count)
- keep — how many recent messages to preserve verbatim after compaction
Defaults (dynamic mode):
- Trigger dynamically when estimated token count reaches
model.contextWindow - reserved(20k). Falls back to 160000 tokens when the model does not report its context window, or at 50 messages (whichever comes first) - Keep tail: dynamically computed as
min(8k, max(2k, usable * 0.25))tokens. Falls back to 20 messages when the model does not report its context window - Prune: enabled by default — aggregates old tool result outputs and trims them when the prunable total exceeds 20k tokens (protects the most recent 40k tokens)
- Summarization is enabled; memory flush and offload are both enabled before summary
Memory prompt landscape
The harness has three LLM-driven memory operations, each with its own prompt; they live in two complementary config classes:- Compaction summary — distills the conversation prefix into one summary
message before reasoning. Prompt:
getSummaryPrompt()on this class. - Flush — extracts long-term memories into today's daily ledger. Prompt:
MemoryConfig.flushPrompt(). - Consolidation — periodically merges daily ledgers into
MEMORY.md. Prompt:MemoryConfig.consolidationPrompt().
HarnessAgent.builder().memory(MemoryConfig...).- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classConfiguration for aggregate tool-result pruning.static classConfiguration for the lightweight argument-truncation pass that runs before summarization. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault summary prompt with structured format.static final intFallback trigger threshold (in tokens) when the model does not report its context window andtriggerTokensis set to dynamic mode (0). -
Method Summary
Modifier and TypeMethodDescriptionstatic CompactionConfig.Builderbuilder()intNumber of recent conversation messages (non-SYSTEM) to preserve verbatim.intToken budget for the preserved tail.intintdoubleio.agentscope.core.model.ModelgetModel()Optional model override for compaction (summarization).Configuration for aggregate tool-result pruning.intToken buffer reserved for the compaction process itself (summary prompt + output).Prompt template used for the summarization LLM call.intMessage count above which compaction is triggered (0 = disabled).intEstimated token count above which compaction is triggered.Configuration for the lightweight pre-summarization argument truncation pass.booleanWhether to flush long-term memories from the prefix before compaction.booleanWhether to offload raw messages to the session JSONL before compaction.withEffective(int effectiveTriggerTokens, int effectiveKeepTokens) Creates a resolved copy with effective trigger and keep values computed from a model's context window.
-
Field Details
-
FALLBACK_TRIGGER_TOKENS
public static final int FALLBACK_TRIGGER_TOKENSFallback trigger threshold (in tokens) when the model does not report its context window andtriggerTokensis set to dynamic mode (0).- See Also:
-
DEFAULT_SUMMARY_PROMPT
Default summary prompt with structured format.- See Also:
-
-
Method Details
-
getTriggerMessages
public int getTriggerMessages()Message count above which compaction is triggered (0 = disabled). -
getTriggerTokens
public int getTriggerTokens()Estimated token count above which compaction is triggered.0= dynamic mode (compute from model's context window minusgetReserved()). -
getReserved
public int getReserved()Token buffer reserved for the compaction process itself (summary prompt + output). Only used in dynamic mode (triggerTokens == 0). -
getKeepMessages
public int getKeepMessages()Number of recent conversation messages (non-SYSTEM) to preserve verbatim. Used whengetKeepTokens()is 0 (static keep mode). -
getKeepTokens
public int getKeepTokens()Token budget for the preserved tail.> 0: static budget — scan from end until this budget is exhausted0: usegetKeepMessages()instead (message-count mode)-1: dynamic — compute asmin(keepTokensMax, max(keepTokensMin, usable * keepTokensRatio))
-
getKeepTokensMin
public int getKeepTokensMin() -
getKeepTokensMax
public int getKeepTokensMax() -
getKeepTokensRatio
public double getKeepTokensRatio() -
getSummaryPrompt
Prompt template used for the summarization LLM call. Must contain{messages}. -
isFlushBeforeCompact
public boolean isFlushBeforeCompact()Whether to flush long-term memories from the prefix before compaction. -
isOffloadBeforeCompact
public boolean isOffloadBeforeCompact()Whether to offload raw messages to the session JSONL before compaction. -
getTruncateArgsConfig
Configuration for the lightweight pre-summarization argument truncation pass. Whennull, argument truncation is disabled. -
getPruneConfig
Configuration for aggregate tool-result pruning. Whennull, pruning is disabled. -
getModel
public io.agentscope.core.model.Model getModel()Optional model override for compaction (summarization).nullmeans use the agent's primary model. -
withEffective
Creates a resolved copy with effective trigger and keep values computed from a model's context window. Used byCompactionMiddlewareto resolve dynamic defaults. -
builder
-