Understand Context Compaction Logic
mainContext compaction in Forge is used to manage long conversation histories by summarizing parts of the context. The logic identifies sequences of assistant messages and replaces them with a concise summary to save tokens and maintain context relevance.
Key behaviors:
- Targeted Compression: Instead of compressing the entire context at once, the system identifies the first continuous sequence of 2 or more consecutive assistant messages.
- Message Preservation: User messages and single assistant messages are preserved in their original positions to maintain conversation flow.
- Incremental Processing: Only one compressible sequence is processed per call to
compact_context. Subsequent sequences can be compressed in later iterations.