pub struct CompactionConfig {
pub threshold_prompt_tokens: u32,
pub keep_recent_turns: u32,
pub compactor_model: String,
pub max_summary_tokens: u32,
}Expand description
Configuration for natural-language history compaction.
When set on RunOptions::compaction, the agent loop monitors the
previous turn’s prompt_tokens and — once it crosses
threshold_prompt_tokens — replaces the middle of the conversation with
a single synthetic system message containing a compacted summary
produced by a separate (typically cheaper) DeepSeek call.
§Cost trade-off
Compaction costs one extra API call (input = serialized middle slice,
output ≤ max_summary_tokens) and invalidates the prompt cache prefix
for subsequent turns because the front of the message vector changes.
DeepSeek’s cache-hit input price is ~25% of the cache-miss price, so:
- For short loops (a few turns): leave
RunOptions::compaction = None— cache hits already make resending cheap. - For long loops where
prompt_tokenscrosses ~30K: one compaction call ondeepseek-chatcosts ~$0.008, but saves resending ~30K tokens × each remaining turn at the cache-hit rate. Break-even is roughly four future turns.
Defaults are tuned for the long-loop case; tune
threshold_prompt_tokens deliberately if your workload is short.
Fields§
§threshold_prompt_tokens: u32Trigger compaction when the previous turn’s prompt_tokens >= this.
keep_recent_turns: u32Number of complete recent turns to keep verbatim after the summary. A “turn” is one assistant message plus its associated tool-result group (if the assistant requested tool calls). Tool-call/result pairs are never split — compaction may keep one extra turn to preserve atomicity.
compactor_model: StringModel used for the compaction call. Default: deepseek-chat
(cheapest input rate).
max_summary_tokens: u32Soft cap on summary completion tokens.
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