Replace build_context_window with trim_conversation

build_context_window loaded journal from a stale flat file and
assembled the full context. Now journal comes from the memory graph
and context is assembled on the fly. All that's needed is trimming
the conversation to fit the budget.

trim_conversation accounts for identity, journal, and reserve
tokens, then drops oldest conversation messages until it fits.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-02 03:35:28 -04:00
parent 87add36cdd
commit e9e47eb798
2 changed files with 30 additions and 41 deletions

View file

@ -967,7 +967,7 @@ impl Agent {
fn do_compact(&mut self) {
let conversation: Vec<Message> = self.context.entries.iter()
.map(|e| e.api_message().clone()).collect();
let (messages, _) = crate::agent::context::build_context_window(
let messages = crate::agent::context::trim_conversation(
&self.context,
&conversation,
&self.client.model,
@ -1030,7 +1030,7 @@ impl Agent {
.collect();
dbglog!("[restore] {} messages after filtering system", conversation.len());
let (messages, _) = crate::agent::context::build_context_window(
let messages = crate::agent::context::trim_conversation(
&self.context,
&conversation,
&self.client.model,