Class ContextWindowGarbageCollector

java.lang.Object
uno.anahata.asi.agi.event.BasicPropertyChangeSource
uno.anahata.asi.agi.context.ContextWindowGarbageCollector
All Implemented Interfaces:
PropertyChangeSource, Rebindable

public class ContextWindowGarbageCollector extends BasicPropertyChangeSource
Orchestrates the monitoring and logging of the Context Window Garbage Collection (CwGC). This class calculates high-fidelity metrics for prompt load and recycling efficiency using a one-pass calculation strategy.
  • Field Details

  • Constructor Details

    • ContextWindowGarbageCollector

      public ContextWindowGarbageCollector(@NonNull @NonNull ContextManager contextManager)
      Constructs a ContextWindowGarbageCollector with its parent manager.
      Parameters:
      contextManager - The parent ContextManager instance.
  • Method Details

    • calculate

      public void calculate()
      Performs a comprehensive, one-pass calculation of all token metrics in the current context. This categorizes tokens into system instructions, tools, metadata, and various history states using the active session tokenizer.
    • summarizeParts

      private String summarizeParts(AbstractMessage message)
      Generates a compact parts summary string for a message being garbage collected.
      Parameters:
      message - The message to summarize.
      Returns:
      The formatted summary string.
    • recordCollection

      public void recordCollection(@NonNull @NonNull AbstractMessage message)
      Records the recycling of a message turn.
      Parameters:
      message - The message being garbage collected.
    • clearLog

      public void clearLog()
      Clears the collection logs.
    • getRecords

      public List<GarbageCollectorRecord> getRecords()
      Gets an unmodifiable view of the collection log.
      Returns:
      The list of collection records.