pub struct CompactionConfig {
pub compact_at_pct: f64,
pub compact_budget_threshold_pct: f64,
pub compaction_scope: CompactionScope,
pub keep_first_turns: usize,
pub keep_recent_turns: usize,
pub max_summary_tokens: usize,
pub tool_output_max_lines: usize,
pub focus_message: Option<String>,
pub in_memory_strategy: Option<Arc<dyn CompactionStrategy>>,
pub block_strategy: Option<Arc<dyn BlockCompactionStrategy>>,
}Expand description
Full compaction policy — controls both WHEN and HOW to compact.
Fields§
§compact_at_pct: f64Fraction of max_context_tokens below which headroom is measured.
Compaction fires when headroom drops below compact_budget_threshold_pct.
Default: 0.90 (90%).
compact_budget_threshold_pct: f64Minimum remaining headroom fraction before compaction fires. Default: 0.05 (5%). With defaults at 100k/4k: fires at ~81k tokens.
compaction_scope: CompactionScopeScope controlling how many earlier loops to compact and load.
Default: FixedCount(3).
keep_first_turns: usizeTurns to keep verbatim from the start (most recent loop only). Default: 2.
keep_recent_turns: usizeMinimum turns to keep from the end (most recent loop only). Extended to turn boundary so ToolCall/ToolResult pairs are never split. Default: 10.
max_summary_tokens: usizeToken budget for the summarised middle section. Default: 2_000.
This is a budget, not a per-turn limit. Implementations of
BlockCompactionStrategy::keep_compacted() should aim to summarise
ALL turns in the range within this budget — e.g. by producing shorter
per-turn summaries or an LLM-generated holistic digest.
DefaultBlockCompaction is a basic implementation that generates
per-turn one-liners and drops remaining turns when the budget runs out.
tool_output_max_lines: usizeMax lines per tool output in the keep_recent section. Default: 50.
focus_message: Option<String>Optional focus message to guide compaction summarization. When set, prepended to the compacted section to tell the model what to prioritize. Example: “Focus on specification details, API contracts, and architectural decisions.”
in_memory_strategy: Option<Arc<dyn CompactionStrategy>>Custom in-memory compaction strategy. When set, replaces DefaultCompaction.
Used when AgentContext.session is None (sub-agents, tests, sessionless runs).
block_strategy: Option<Arc<dyn BlockCompactionStrategy>>Block-based compaction strategy for Session-aware compaction.
When set, replaces DefaultBlockCompaction.
Used when AgentContext.session is Some.
Trait Implementations§
Source§impl Clone for CompactionConfig
impl Clone for CompactionConfig
Source§fn clone(&self) -> CompactionConfig
fn clone(&self) -> CompactionConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more