CompactionManager
Defined in: agent/compaction/manager.ts:63
CompactionManager orchestrates context compaction for an agent.
It:
- Monitors token usage before each LLM call
- Triggers compaction when threshold is exceeded
- Coordinates with ConversationManager to update history
- Tracks statistics for observability
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CompactionManager(
client,model,config):CompactionManager
Defined in: agent/compaction/manager.ts:75
Parameters
Section titled “Parameters”client
Section titled “client”string
config
Section titled “config”CompactionConfig = {}
Returns
Section titled “Returns”CompactionManager
Methods
Section titled “Methods”checkAndCompact()
Section titled “checkAndCompact()”checkAndCompact(
conversation,iteration):Promise<CompactionEvent|null>
Defined in: agent/compaction/manager.ts:95
Check if compaction is needed and perform it if so.
Parameters
Section titled “Parameters”conversation
Section titled “conversation”The conversation manager to compact
iteration
Section titled “iteration”number
Current agent iteration (for event metadata)
Returns
Section titled “Returns”Promise<CompactionEvent | null>
CompactionEvent if compaction was performed, null otherwise
compact()
Section titled “compact()”compact(
conversation,iteration,precomputed?):Promise<CompactionEvent|null>
Defined in: agent/compaction/manager.ts:152
Force compaction regardless of threshold.
Parameters
Section titled “Parameters”conversation
Section titled “conversation”The conversation manager to compact
iteration
Section titled “iteration”number
Current agent iteration (for event metadata). Use -1 for manual compaction.
precomputed?
Section titled “precomputed?”PrecomputedTokens
Optional pre-computed token counts (passed from checkAndCompact for efficiency)
Returns
Section titled “Returns”Promise<CompactionEvent | null>
CompactionEvent with compaction details
getStats()
Section titled “getStats()”getStats():
CompactionStats
Defined in: agent/compaction/manager.ts:226
Get compaction statistics.
Returns
Section titled “Returns”isEnabled()
Section titled “isEnabled()”isEnabled():
boolean
Defined in: agent/compaction/manager.ts:242
Check if compaction is enabled.
Returns
Section titled “Returns”boolean