Skip to content

chimera.compaction

chimera.compaction rewrites old messages so a long-running session keeps fitting in the context window.

from chimera.compaction import (
CompactionStrategy,
SummaryCompaction,
PruneCompaction,
CounterCompaction,
CompositeCompaction,
ThresholdCompaction,
AtomicGroup,
CompactionView,
CompactionUrgency,
CompactionMetadata,
FileAwareCompaction,
)
SymbolModulePurpose
CompactionStrategychimera.compaction.baseABC. Override compact(view, urgency) -> NewMessages.
AtomicGroupchimera.compaction.baseTool call + result pair that must compact together.
CompactionViewchimera.compaction.baseRead-only window over the message history.
CompactionUrgencychimera.compaction.baseEnum: SOFT, HARD. Drives strategy choice.
CompactionMetadatachimera.compaction.baseWhat was kept, what was summarised, file references preserved.
FileAwareCompactionchimera.compaction.baseMixin that pulls FileTracker references into summaries.
SummaryCompactionchimera.compaction.summaryLLM-summarises old turns; subclass of FileAwareCompaction.
PruneCompactionchimera.compaction.strategiesDrop oldest N turns.
CounterCompactionchimera.compaction.strategiesDrop after a fixed message count.
CompositeCompactionchimera.compaction.strategiesRun a list of strategies in order.
ThresholdCompactionchimera.compaction.thresholdsTrigger SOFT at one token budget, HARD at another, with tool-call/result atomicity.

Wire into a loop via LoopConfig(compaction=...).