Simplify trim_entries, kill ContextBudget

trim_entries is now a simple loop:
1. Drop duplicate memories and DMN entries
2. While over budget: if memories > 50% of entry tokens, drop
   lowest-scored memory; otherwise drop oldest conversation entry
3. Snap to user message boundary

ContextBudget is gone — sections already have cached token totals:
- total_tokens() on ContextState replaces budget.total()
- format_budget() on ContextState replaces budget.format()
- trim() takes fixed_tokens: usize (system + identity + journal)

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-04-07 20:55:35 -04:00
parent 62996e27d7
commit b892cae2be
4 changed files with 68 additions and 133 deletions

View file

@ -337,7 +337,7 @@ impl Mind {
MindCommand::Compact => {
let threshold = compaction_threshold(&self.config.app) as usize;
let mut ag = self.agent.lock().await;
if ag.context_budget().total() > threshold {
if ag.context.total_tokens() > threshold {
ag.compact();
ag.notify("compacted");
}
@ -437,7 +437,7 @@ impl Mind {
// Compact if over budget before sending
let threshold = compaction_threshold(&self.config.app) as usize;
if ag.context_budget().total() > threshold {
if ag.context.total_tokens() > threshold {
ag.compact();
ag.notify("compacted");
}