compact: retained_turns を retained_tokens に置換
保護単位をターン数からトークン量に変更。compact 時のカット位置は Pod::split_for_retained() で UsageRecord を逆算ソースとして決定し、 ターン境界ではなくアイテム単位で切る。デフォルトは 8000 トークン。
This commit is contained in:
@@ -86,7 +86,7 @@ pub struct CompactionConfigPartial {
|
||||
#[serde(default)]
|
||||
pub compact_request_threshold: Option<u64>,
|
||||
#[serde(default)]
|
||||
pub compact_retained_turns: Option<usize>,
|
||||
pub compact_retained_tokens: Option<u64>,
|
||||
#[serde(default)]
|
||||
pub provider: Option<ProviderConfigPartial>,
|
||||
}
|
||||
@@ -241,9 +241,9 @@ impl CompactionConfigPartial {
|
||||
compact_request_threshold: upper
|
||||
.compact_request_threshold
|
||||
.or(self.compact_request_threshold),
|
||||
compact_retained_turns: upper
|
||||
.compact_retained_turns
|
||||
.or(self.compact_retained_turns),
|
||||
compact_retained_tokens: upper
|
||||
.compact_retained_tokens
|
||||
.or(self.compact_retained_tokens),
|
||||
provider: merge_option(self.provider, upper.provider, ProviderConfigPartial::merge),
|
||||
}
|
||||
}
|
||||
@@ -371,9 +371,9 @@ impl TryFrom<PodManifestConfig> for PodManifest {
|
||||
.unwrap_or(defaults::PRUNE_MIN_SAVINGS),
|
||||
compact_threshold: c.compact_threshold,
|
||||
compact_request_threshold: c.compact_request_threshold,
|
||||
compact_retained_turns: c
|
||||
.compact_retained_turns
|
||||
.unwrap_or(defaults::COMPACT_RETAINED_TURNS),
|
||||
compact_retained_tokens: c
|
||||
.compact_retained_tokens
|
||||
.unwrap_or(defaults::COMPACT_RETAINED_TOKENS),
|
||||
provider: comp_provider,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -18,9 +18,11 @@ pub const PRUNE_PROTECTED_TURNS: usize = 3;
|
||||
/// [`crate::CompactionConfig::prune_min_savings`].
|
||||
pub const PRUNE_MIN_SAVINGS: u64 = 4096;
|
||||
|
||||
/// Number of most-recent turns retained after a compact. See
|
||||
/// [`crate::CompactionConfig::compact_retained_turns`].
|
||||
pub const COMPACT_RETAINED_TURNS: usize = 2;
|
||||
/// Token budget retained (unchanged) at the tail of the history across
|
||||
/// a compact. Items whose cumulative token count fits within this budget
|
||||
/// starting from the end are kept verbatim; the rest are summarised.
|
||||
/// See [`crate::CompactionConfig::compact_retained_tokens`].
|
||||
pub const COMPACT_RETAINED_TOKENS: u64 = 8000;
|
||||
|
||||
/// Default instruction asset reference used when `worker.instruction`
|
||||
/// is omitted. See the `PromptLoader` prefix addressing scheme for the
|
||||
|
||||
@@ -195,9 +195,11 @@ pub struct CompactionConfig {
|
||||
#[serde(default)]
|
||||
pub compact_request_threshold: Option<u64>,
|
||||
|
||||
/// Number of recent turns retained after compaction.
|
||||
#[serde(default = "default_compact_retained_turns")]
|
||||
pub compact_retained_turns: usize,
|
||||
/// Token budget retained verbatim at the tail of the history after
|
||||
/// compaction. Measured against the occupancy estimate from
|
||||
/// `UsageRecord` history; turn boundaries are ignored.
|
||||
#[serde(default = "default_compact_retained_tokens")]
|
||||
pub compact_retained_tokens: u64,
|
||||
|
||||
/// Optional provider for the compactor (summary) LLM.
|
||||
/// If omitted, the main provider is cloned via `clone_boxed()`.
|
||||
@@ -211,8 +213,8 @@ fn default_prune_protected_turns() -> usize {
|
||||
fn default_prune_min_savings() -> u64 {
|
||||
defaults::PRUNE_MIN_SAVINGS
|
||||
}
|
||||
fn default_compact_retained_turns() -> usize {
|
||||
defaults::COMPACT_RETAINED_TURNS
|
||||
fn default_compact_retained_tokens() -> u64 {
|
||||
defaults::COMPACT_RETAINED_TOKENS
|
||||
}
|
||||
|
||||
impl Default for CompactionConfig {
|
||||
@@ -222,7 +224,7 @@ impl Default for CompactionConfig {
|
||||
prune_min_savings: default_prune_min_savings(),
|
||||
compact_threshold: None,
|
||||
compact_request_threshold: None,
|
||||
compact_retained_turns: default_compact_retained_turns(),
|
||||
compact_retained_tokens: default_compact_retained_tokens(),
|
||||
provider: None,
|
||||
}
|
||||
}
|
||||
@@ -357,7 +359,7 @@ model = "claude-sonnet-4-20250514"
|
||||
assert_eq!(c.prune_min_savings, 4096);
|
||||
assert_eq!(c.compact_threshold, Some(80000));
|
||||
assert_eq!(c.compact_request_threshold, None);
|
||||
assert_eq!(c.compact_retained_turns, 2);
|
||||
assert_eq!(c.compact_retained_tokens, 8000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user