pub struct LlmSummarizer { /* private fields */ }Expand description
Summarizes older conversation turns by asking DeepSeek to write a concise
prose summary, then replaces the compressed turns with a single
Role::System message containing that summary.
§Trigger
Fires when the estimated token count of the compressible portion of the
history (everything except permanent system prompts) exceeds token_threshold.
§Behavior
- Permanent
Role::Systemmessages (user-provided viawith_system_prompt) are extracted and re-prepended after summarization — they are never lost. - Any previous
[auto-summary]system message is included in the text sent to the model so the new summary is cumulative. - The
retain_lastmost recent non-system turns are kept verbatim; everything older is replaced by the LLM-generated summary. - If the API call fails the history is left unchanged and the error is returned so the caller can decide whether to abort or continue.
§Example
use ds_api::{DeepseekAgent, ApiClient};
use ds_api::conversation::LlmSummarizer;
let summarizer = LlmSummarizer::new(ApiClient::new("sk-..."));
let agent = DeepseekAgent::new("sk-...")
.with_summarizer(summarizer);Implementations§
Source§impl LlmSummarizer
impl LlmSummarizer
Sourcepub fn new(client: ApiClient) -> Self
pub fn new(client: ApiClient) -> Self
Create with default thresholds: trigger at ~60 000 tokens, retain last 10 turns.
Sourcepub fn token_threshold(self, n: usize) -> Self
pub fn token_threshold(self, n: usize) -> Self
Builder: set a custom token threshold.
Sourcepub fn retain_last(self, n: usize) -> Self
pub fn retain_last(self, n: usize) -> Self
Builder: set how many recent messages to keep verbatim.
Trait Implementations§
Source§impl Clone for LlmSummarizer
impl Clone for LlmSummarizer
Source§fn clone(&self) -> LlmSummarizer
fn clone(&self) -> LlmSummarizer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Summarizer for LlmSummarizer
impl Summarizer for LlmSummarizer
Auto Trait Implementations§
impl Freeze for LlmSummarizer
impl !RefUnwindSafe for LlmSummarizer
impl Send for LlmSummarizer
impl Sync for LlmSummarizer
impl Unpin for LlmSummarizer
impl UnsafeUnpin for LlmSummarizer
impl !UnwindSafe for LlmSummarizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more