Context compaction controller
Context compaction controller
Details
Monitors token usage and dispatches the appropriate compaction level. Includes a circuit breaker that silences compaction after 3 consecutive failures to prevent infinite compaction loops.
Methods
Method adaptive_compact()
Run adaptive compaction with circuit-breaker protection.
Usage
CompactionController$adaptive_compact(
chat,
settings = list(),
model = "",
compact_model = .HAIKU_MODEL,
request_turns = NULL,
full_enabled = FALSE,
force_summary = FALSE,
hooks = NULL,
use_provider_usage = TRUE
)Arguments
chatAn
ellmer::Chatobject.settingsNamed compaction settings.
modelCharacter. Active request model.
compact_modelCharacter. Model for summary tasks.
request_turnsOptional complete outgoing request including pending.
full_enabledWhether summary escalation is allowed.
force_summaryWhether to summarize even after cheap reduction.
hooksOptional lifecycle registry; receives sanitized metadata only.
use_provider_usageWhether initial accounting may include prior usage.
Method maybe_compact()
Check token usage and compact if needed.
Usage
CompactionController$maybe_compact(
chat,
model_limit = 200000L,
compact_model = .HAIKU_MODEL,
model = "",
hooks = NULL,
use_provider_usage = TRUE
)Arguments
chatAn
ellmer::Chatobject.model_limitInteger. Raw model context-window token limit.
compact_modelCharacter. Model for compaction tasks.
modelCharacter. Active request model used to resolve output reserve.
hooksOptional lifecycle registry.
use_provider_usageWhether initial accounting may include prior usage.
Method compact_now()
Force the adaptive summary chain for manual compaction.
Arguments
chatAn
ellmer::Chatobject.compact_modelCharacter. Model for compaction tasks.
Method handle_ptl_error()
Handle a prompt-too-long (PTL) error by dropping turns.
Arguments
chatAn
ellmer::Chatobject.errorAn error condition or message string (parsed for a real context limit when present).
pending_turnOptional failed outgoing pending turn.