Class CompactionConfig

java.lang.Object
io.agentscope.harness.agent.memory.compaction.CompactionConfig

public class CompactionConfig extends Object
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().
Configure the latter two via HarnessAgent.builder().memory(MemoryConfig...).
See Also:
  • Field Details

    • FALLBACK_TRIGGER_TOKENS

      public static final int FALLBACK_TRIGGER_TOKENS
      Fallback trigger threshold (in tokens) when the model does not report its context window and triggerTokens is set to dynamic mode (0).
      See Also:
    • DEFAULT_SUMMARY_PROMPT

      public static final String DEFAULT_SUMMARY_PROMPT
      Default summary prompt with structured format.
  • 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 minus getReserved()).
    • 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 when getKeepTokens() 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 exhausted
      • 0: use getKeepMessages() instead (message-count mode)
      • -1: dynamic — compute as min(keepTokensMax, max(keepTokensMin, usable * keepTokensRatio))
    • getKeepTokensMin

      public int getKeepTokensMin()
    • getKeepTokensMax

      public int getKeepTokensMax()
    • getKeepTokensRatio

      public double getKeepTokensRatio()
    • getSummaryPrompt

      public String 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

      public CompactionConfig.TruncateArgsConfig getTruncateArgsConfig()
      Configuration for the lightweight pre-summarization argument truncation pass. When null, argument truncation is disabled.
    • getPruneConfig

      public CompactionConfig.PruneConfig getPruneConfig()
      Configuration for aggregate tool-result pruning. When null, pruning is disabled.
    • getModel

      public io.agentscope.core.model.Model getModel()
      Optional model override for compaction (summarization). null means use the agent's primary model.
    • withEffective

      public CompactionConfig withEffective(int effectiveTriggerTokens, int effectiveKeepTokens)
      Creates a resolved copy with effective trigger and keep values computed from a model's context window. Used by CompactionMiddleware to resolve dynamic defaults.
    • builder

      public static CompactionConfig.Builder builder()