WIP: trim_entries dedup, context_window rename, compact simplification

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-02 15:58:03 -04:00
parent 809679b6ce
commit d419587c1b
3 changed files with 58 additions and 53 deletions

View file

@ -40,14 +40,14 @@ use poc_memory::agent::ui_channel::{ContextInfo, StatusInfo, StreamTarget, UiMes
/// Hard compaction threshold — context is rebuilt immediately.
/// Uses config percentage of model context window.
fn compaction_threshold(model: &str, app: &AppConfig) -> u32 {
(poc_memory::thought::context::model_context_window(model) as u32) * app.compaction.hard_threshold_pct / 100
fn compaction_threshold(app: &AppConfig) -> u32 {
(poc_memory::thought::context::context_window() as u32) * app.compaction.hard_threshold_pct / 100
}
/// Soft threshold — nudge the model to journal before compaction.
/// Fires once; the hard threshold handles the actual rebuild.
fn pre_compaction_threshold(model: &str, app: &AppConfig) -> u32 {
(poc_memory::thought::context::model_context_window(model) as u32) * app.compaction.soft_threshold_pct / 100
fn pre_compaction_threshold(app: &AppConfig) -> u32 {
(poc_memory::thought::context::context_window() as u32) * app.compaction.soft_threshold_pct / 100
}
#[tokio::main]
@ -280,8 +280,8 @@ impl Session {
async fn check_compaction(&mut self) {
let mut agent_guard = self.agent.lock().await;
let tokens = agent_guard.last_prompt_tokens();
let hard = compaction_threshold(agent_guard.model(), &self.config.app);
let soft = pre_compaction_threshold(agent_guard.model(), &self.config.app);
let hard = compaction_threshold(&self.config.app);
let soft = pre_compaction_threshold(&self.config.app);
if tokens > hard {
let _ = self.ui_tx.send(UiMessage::Info(format!(
@ -452,7 +452,7 @@ impl Session {
let total_chars: usize =
msgs.iter().map(|e| e.message().content_text().len()).sum();
let prompt_tokens = agent.last_prompt_tokens();
let threshold = compaction_threshold(agent.model(), &self.config.app);
let threshold = compaction_threshold(&self.config.app);
let _ = self.ui_tx.send(UiMessage::Info(format!(
" {} messages, ~{} chars",
msgs.len(),