Class History

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class History extends AnahataToolkit
A specialized toolkit for managing the conversation history, including metadata injection and surgical pruning of messages and parts.

This toolkit is primarily used during 'History Compression' turns where the model is forced to evaluate its own context window and decide which information remains relevant.

Author:
anahata
  • Constructor Details

    • History

      public History()
  • Method Details

    • getSystemInstructions

      public List<String> getSystemInstructions() throws Exception
      Gets a list of system instruction strings provided by this context provider. These are typically prepended to the conversation as high-level guidance.

      Provides context-aware system instructions for the History toolkit, detailing CwGC operational parameters, pruningStates, and metadata strategies.

      Returns:
      A singleton list containing the detailed history system prompt.
      Throws:
      Exception - if metadata serialization or context lookup fails.
    • populateMessage

      public void populateMessage(RagMessage ragMessage) throws Exception
      Populates the RAG message with comprehensive session metadata.

      Provides a Markdown summary of session identity, model configuration, context window usage, and the status of executing tools.

      Parameters:
      ragMessage - The target RAG message.
      Throws:
      Exception - if metadata extraction fails.
    • createConsolidatedIndex

      public String createConsolidatedIndex()
      Creates the consolidated history index.
      Returns:
      The formatted Markdown consolidated index string containing message and part metadata.
    • clearGarbageCollectorLogs

      public String clearGarbageCollectorLogs()
      Clears all Context Window Garbage Collector (CwGC) log records from memory.
      Returns:
      A descriptive confirmation string indicating the number of logs cleared.
    • setMessagePruningState

      public String setMessagePruningState(List<Long> messageIds, PruningState newState)
      Updates the pruning policy for all parts of one or more messages.

      Pruning states:

      • PINNED: Never garbage collected; always remains in context.
      • PRUNED: Excluded from the next API payload but kept in history.
      • AUTO: Standard lifecycle managed by the CwGC system.
      Parameters:
      messageIds - The sequential IDs of the messages to update.
      newState - The new pruning state to apply.
      Returns:
      Confirmation message.
    • setPartPruningState

      public String setPartPruningState(List<Long> partIds, PruningState newState)
      Updates the pruning policy for specific message parts.

      This tool allows for granular control over individual content segments, such as pinning a critical code block while allowing the rest of the message to be pruned.

      Parameters:
      partIds - The sequential IDs of the parts to update.
      newState - The new pruning state.
      Returns:
      Confirmation message.
    • setInjectInbandMetadata

      public String setInjectInbandMetadata(boolean enabled)
      Toggles the injection of in-band metadata headers.

      When enabled, the model receives unique sequential IDs for every message and part in the history, enabling the use of pruning tools.

      Parameters:
      enabled - If true, metadata headers are included in the prompt.
      Returns:
      Confirmation message.