Package com.tnsai.context.compaction
package com.tnsai.context.compaction
Context compaction for long-running agent sessions.
This package provides mechanisms to automatically manage context size by summarizing older messages when approaching token limits.
Compaction Strategies
TruncatingCompactor(Phase 1) — truncates large tool-call arguments and tool-result content in older messages. Fast, no LLM call.LLMContextCompactor(Phase 2) — uses an LLM to summarize older messages into a concise summary.TwoPhaseCompactor— combines both: truncation first, then LLM summarization if still over threshold.
Quick Start
CompactionConfig config = CompactionConfig.builder()
.thresholdRatio(0.85)
.preserveLastN(5)
.build();
// Two-phase compaction (recommended)
TwoPhaseCompactor compactor = new TwoPhaseCompactor(
new TruncatingCompactor(200),
new LLMContextCompactor(llm)
);
CompactionResult result = compactor.compact(messages, config);
- Since:
- 0.2.3
- Author:
- TnsAI Team
-
ClassDescriptionConfiguration for context compaction.Builder for CompactionConfig.Result of a context compaction operation.Interface for context compaction strategies.LLM-based context compactor that summarizes old messages.Phase-1 compactor that truncates large tool-call arguments in older messages.Two-phase context compactor combining truncation and LLM summarization.