Package com.tnsai.context.compaction
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for CompactionConfig. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault max summary tokens.static final intDefault minimum messages for compaction.static final intDefault number of messages to preserve.static final StringDefault summary prompt template.static final doubleDefault threshold ratio (80%).static final intDefault tool-result pruning threshold (tokens). -
Constructor Summary
ConstructorsConstructorDescriptionCreates config with defaults.CompactionConfig(double thresholdRatio, int preserveLastN) Creates config with threshold ratio and preserve count.CompactionConfig(double thresholdRatio, int preserveLastN, boolean preserveSystemPrompt, int minMessagesForCompaction, String summarizerModel, String summaryPromptTemplate, int maxSummaryTokens, boolean toolResultPruningEnabled, int toolResultPruningThreshold) Creates an instance of aCompactionConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic CompactionConfig.Builderbuilder()Creates a builder for fluent configuration.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intReturns the value of themaxSummaryTokensrecord component.intReturns the value of theminMessagesForCompactionrecord component.intReturns the value of thepreserveLastNrecord component.booleanReturns the value of thepreserveSystemPromptrecord component.Returns the value of thesummarizerModelrecord component.Returns the value of thesummaryPromptTemplaterecord component.doubleReturns the value of thethresholdRatiorecord component.booleanReturns the value of thetoolResultPruningEnabledrecord component.intReturns the value of thetoolResultPruningThresholdrecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
DEFAULT_THRESHOLD_RATIO
public static final double DEFAULT_THRESHOLD_RATIODefault threshold ratio (80%).- See Also:
-
DEFAULT_PRESERVE_LAST_N
public static final int DEFAULT_PRESERVE_LAST_NDefault number of messages to preserve.- See Also:
-
DEFAULT_MIN_MESSAGES
public static final int DEFAULT_MIN_MESSAGESDefault minimum messages for compaction.- See Also:
-
DEFAULT_MAX_SUMMARY_TOKENS
public static final int DEFAULT_MAX_SUMMARY_TOKENSDefault max summary tokens.- See Also:
-
DEFAULT_TOOL_RESULT_PRUNING_THRESHOLD
public static final int DEFAULT_TOOL_RESULT_PRUNING_THRESHOLDDefault tool-result pruning threshold (tokens).- See Also:
-
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 aCompactionConfigrecord class.- Parameters:
thresholdRatio- the value for thethresholdRatiorecord componentpreserveLastN- the value for thepreserveLastNrecord componentpreserveSystemPrompt- the value for thepreserveSystemPromptrecord componentminMessagesForCompaction- the value for theminMessagesForCompactionrecord componentsummarizerModel- the value for thesummarizerModelrecord componentsummaryPromptTemplate- the value for thesummaryPromptTemplaterecord componentmaxSummaryTokens- the value for themaxSummaryTokensrecord componenttoolResultPruningEnabled- the value for thetoolResultPruningEnabledrecord componenttoolResultPruningThreshold- the value for thetoolResultPruningThresholdrecord component
-
-
Method Details
-
builder
Creates a builder for fluent configuration. -
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
thresholdRatio
public double thresholdRatio()Returns the value of thethresholdRatiorecord component.- Returns:
- the value of the
thresholdRatiorecord component
-
preserveLastN
public int preserveLastN()Returns the value of thepreserveLastNrecord component.- Returns:
- the value of the
preserveLastNrecord component
-
preserveSystemPrompt
public boolean preserveSystemPrompt()Returns the value of thepreserveSystemPromptrecord component.- Returns:
- the value of the
preserveSystemPromptrecord component
-
minMessagesForCompaction
public int minMessagesForCompaction()Returns the value of theminMessagesForCompactionrecord component.- Returns:
- the value of the
minMessagesForCompactionrecord component
-
summarizerModel
Returns the value of thesummarizerModelrecord component.- Returns:
- the value of the
summarizerModelrecord component
-
summaryPromptTemplate
Returns the value of thesummaryPromptTemplaterecord component.- Returns:
- the value of the
summaryPromptTemplaterecord component
-
maxSummaryTokens
public int maxSummaryTokens()Returns the value of themaxSummaryTokensrecord component.- Returns:
- the value of the
maxSummaryTokensrecord component
-
toolResultPruningEnabled
public boolean toolResultPruningEnabled()Returns the value of thetoolResultPruningEnabledrecord component.- Returns:
- the value of the
toolResultPruningEnabledrecord component
-
toolResultPruningThreshold
public int toolResultPruningThreshold()Returns the value of thetoolResultPruningThresholdrecord component.- Returns:
- the value of the
toolResultPruningThresholdrecord component
-