Class AutoConsolidationManager

java.lang.Object
com.tnsai.session.consolidation.AutoConsolidationManager

public final class AutoConsolidationManager extends Object
Monitors conversation state and triggers consolidation automatically.

Wires ConsolidationTrigger into the memory lifecycle by checking configurable thresholds on each message addition:

Usage


 AutoConsolidationManager manager = AutoConsolidationManager.builder()
     .pipeline(consolidationPipeline)
     .triggers(Set.of(ConsolidationTrigger.MESSAGE_COUNT, ConsolidationTrigger.TOKEN_LIMIT))
     .messageCountThreshold(50)
     .tokenBudget(8192)
     .tokenThresholdPercent(80)
     .build();

 // Call on each message
 manager.onMessageAdded(session, estimatedTokens);

 // Call when session closes
 manager.onSessionEnd(session);
 
Since:
0.1.0
  • Method Details

    • onMessageAdded

      public ConsolidationResult onMessageAdded(AgentSession session, int estimatedTokens)
      Called when a message is added to the conversation.

      Checks if any configured trigger condition is met and runs consolidation if so. Consolidation is skipped if another consolidation is already in progress.

      Parameters:
      session - the current agent session
      estimatedTokens - current estimated token usage
      Returns:
      the consolidation result if triggered, or null if no consolidation occurred
    • onSessionEnd

      public ConsolidationResult onSessionEnd(AgentSession session)
      Called when a session ends.

      Triggers consolidation if ConsolidationTrigger.ON_SESSION_END is in the configured trigger set.

      Parameters:
      session - the ending session
      Returns:
      the consolidation result, or null if session-end trigger is not configured
    • getMessagesSinceLastConsolidation

      public int getMessagesSinceLastConsolidation()
      Returns the number of messages recorded since the last consolidation.
    • getTriggers

      public Set<ConsolidationTrigger> getTriggers()
      Returns the configured triggers.
    • builder

      public static AutoConsolidationManager.Builder builder()