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.
The summarization call uses "deepseek-chat" by default. Override with
with_model — useful when the agent is
pointed at an OpenAI-compatible provider and you want the summarizer to
use the same model.
Sourcepub fn with_model(self, model: impl Into<String>) -> Self
pub fn with_model(self, model: impl Into<String>) -> Self
Builder: set the model used for the summarization API call.
use ds_api::{ApiClient, LlmSummarizer};
let summarizer = LlmSummarizer::new(ApiClient::new("sk-..."))
.with_model("gpt-4o-mini");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
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more