Adaptive Trajectory Compression & Online Context Summarization
Decrypting conversation_compression.py trigger mechanics and System Prompt historical summary concatenation
📊 Figure 2-3-1: Context Size Detection, Small-Model Summarization & Session DB Truncation Flow
📉 1. Trajectory Compression (Context Compaction) Trigger Point
In long conversations, as tool calls accumulate, the context may approach the LLM window limit. In agent/conversation_compression.py, the system initiates a compression decision:
def should_compress(self, current_tokens: int) -> bool:
# Read the configured threshold percentage (e.g., 80% of max window)
limit = self.window_limit * self.threshold_percent
return current_tokens >= limit
📊 Figure 2-3-2: Trajectory Compression Trigger, Small-Model Summarization & DB Physical Truncation Sequence
🤝 2. Summary Concatenation & Database Physical Truncation
Once triggered, the system invokes an auxiliary model, feeding it the history slated for removal (e.g., the previous 5 turns of conversation and tool execution content) to generate a concise Markdown Summary. The Summary is then inserted into the system prompt, and the corresponding 5-turn history block is physically deleted from state.db, retaining only the most recent tail — dramatically reducing time-to-first-token latency.