Record Class CompactionConfig

java.lang.Object
java.lang.Record
com.tnsai.context.compaction.CompactionConfig

public record CompactionConfig(double thresholdRatio, int preserveLastN, boolean preserveSystemPrompt, int minMessagesForCompaction, String summarizerModel, String summaryPromptTemplate, int maxSummaryTokens, boolean toolResultPruningEnabled, int toolResultPruningThreshold) extends Record
Configuration for context compaction.

Defines when and how to compact the conversation context when it approaches the token limit.

Usage


 CompactionConfig config = CompactionConfig.builder()
     .thresholdRatio(0.80)           // Compact at 80% capacity
     .preserveLastN(5)               // Keep last 5 messages
     .preserveSystemPrompt(true)     // Always keep system prompt
     .summarizerModel("gpt-4o-mini") // Use cheap model for summarization
     .build();
 
Author:
TnsAI Team
  • Field Details

    • DEFAULT_THRESHOLD_RATIO

      public static final double DEFAULT_THRESHOLD_RATIO
      Default threshold ratio (80%).
      See Also:
    • DEFAULT_PRESERVE_LAST_N

      public static final int DEFAULT_PRESERVE_LAST_N
      Default number of messages to preserve.
      See Also:
    • DEFAULT_MIN_MESSAGES

      public static final int DEFAULT_MIN_MESSAGES
      Default minimum messages for compaction.
      See Also:
    • DEFAULT_MAX_SUMMARY_TOKENS

      public static final int DEFAULT_MAX_SUMMARY_TOKENS
      Default max summary tokens.
      See Also:
    • DEFAULT_TOOL_RESULT_PRUNING_THRESHOLD

      public static final int DEFAULT_TOOL_RESULT_PRUNING_THRESHOLD
      Default tool-result pruning threshold (tokens).
      See Also:
    • DEFAULT_SUMMARY_PROMPT

      public static final String DEFAULT_SUMMARY_PROMPT
      Default summary prompt template.
      See Also:
  • Constructor Details

    • CompactionConfig

      public CompactionConfig()
      Creates config with defaults.
    • CompactionConfig

      public CompactionConfig(double thresholdRatio, int preserveLastN)
      Creates config with threshold ratio and preserve count.
    • CompactionConfig

      public CompactionConfig(double thresholdRatio, int preserveLastN, boolean preserveSystemPrompt, int minMessagesForCompaction, String summarizerModel, String summaryPromptTemplate, int maxSummaryTokens, boolean toolResultPruningEnabled, int toolResultPruningThreshold)
      Creates an instance of a CompactionConfig record class.
      Parameters:
      thresholdRatio - the value for the thresholdRatio record component
      preserveLastN - the value for the preserveLastN record component
      preserveSystemPrompt - the value for the preserveSystemPrompt record component
      minMessagesForCompaction - the value for the minMessagesForCompaction record component
      summarizerModel - the value for the summarizerModel record component
      summaryPromptTemplate - the value for the summaryPromptTemplate record component
      maxSummaryTokens - the value for the maxSummaryTokens record component
      toolResultPruningEnabled - the value for the toolResultPruningEnabled record component
      toolResultPruningThreshold - the value for the toolResultPruningThreshold record component
  • Method Details

    • builder

      public static CompactionConfig.Builder builder()
      Creates a builder for fluent configuration.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • thresholdRatio

      public double thresholdRatio()
      Returns the value of the thresholdRatio record component.
      Returns:
      the value of the thresholdRatio record component
    • preserveLastN

      public int preserveLastN()
      Returns the value of the preserveLastN record component.
      Returns:
      the value of the preserveLastN record component
    • preserveSystemPrompt

      public boolean preserveSystemPrompt()
      Returns the value of the preserveSystemPrompt record component.
      Returns:
      the value of the preserveSystemPrompt record component
    • minMessagesForCompaction

      public int minMessagesForCompaction()
      Returns the value of the minMessagesForCompaction record component.
      Returns:
      the value of the minMessagesForCompaction record component
    • summarizerModel

      public String summarizerModel()
      Returns the value of the summarizerModel record component.
      Returns:
      the value of the summarizerModel record component
    • summaryPromptTemplate

      public String summaryPromptTemplate()
      Returns the value of the summaryPromptTemplate record component.
      Returns:
      the value of the summaryPromptTemplate record component
    • maxSummaryTokens

      public int maxSummaryTokens()
      Returns the value of the maxSummaryTokens record component.
      Returns:
      the value of the maxSummaryTokens record component
    • toolResultPruningEnabled

      public boolean toolResultPruningEnabled()
      Returns the value of the toolResultPruningEnabled record component.
      Returns:
      the value of the toolResultPruningEnabled record component
    • toolResultPruningThreshold

      public int toolResultPruningThreshold()
      Returns the value of the toolResultPruningThreshold record component.
      Returns:
      the value of the toolResultPruningThreshold record component