pub struct RetentionPolicy {
pub max_per_thread: Option<usize>,
pub max_age: Option<Duration>,
}Expand description
How many checkpoints to keep for a thread, and for how long.
A long-running thread accumulates one checkpoint per super-step. Without a
policy that grows without bound, which costs storage and slows a list.
The newest checkpoint is never removed, whatever the policy says: it is the one a resume loads, so discarding it would end the thread.
§Example
use adk_graph::checkpoint::RetentionPolicy;
use std::time::Duration;
// Keep the last 50 steps, and nothing older than a week.
let policy = RetentionPolicy::keep_last(50).with_max_age(Duration::from_secs(7 * 24 * 3600));Fields§
§max_per_thread: Option<usize>Keep at most this many checkpoints per thread, newest first.
max_age: Option<Duration>Remove checkpoints older than this.
Implementations§
Source§impl RetentionPolicy
impl RetentionPolicy
Sourcepub fn keep_last(count: usize) -> Self
pub fn keep_last(count: usize) -> Self
Keeps the newest count checkpoints for a thread.
A count of zero is raised to one, because the newest is always kept.
Sourcepub fn with_max_age(self, age: Duration) -> Self
pub fn with_max_age(self, age: Duration) -> Self
Adds an age limit to a count limit.
Sourcepub fn with_max_per_thread(self, count: usize) -> Self
pub fn with_max_per_thread(self, count: usize) -> Self
Adds a count limit to an age limit.
Sourcepub fn is_unlimited(&self) -> bool
pub fn is_unlimited(&self) -> bool
Whether this policy would remove anything.
Sourcepub fn expired(&self, checkpoints: &[Checkpoint]) -> Vec<String>
pub fn expired(&self, checkpoints: &[Checkpoint]) -> Vec<String>
Selects the checkpoint ids this policy discards, newest always kept.
Shared by every backend so they cannot disagree about what to keep.