Fix: compact() was clearing tool definitions from system section

compact() cleared and rebuilt the system section but only pushed the
system prompt — tool definitions were lost. Since new() sets up the
system section correctly (prompt + tools), compact() now only reloads
identity and journal, leaving system untouched.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-08 17:48:10 -04:00
parent d4d661df5b
commit fc75b181cf
2 changed files with 9 additions and 3 deletions

View file

@ -491,6 +491,13 @@ impl ResponseParser {
let handle = tokio::spawn(async move {
let mut parser = self;
let agent_name = agent.state.lock().await.provenance.clone();
// One-shot debug: dump rendered prompt to file
{
let ctx = agent.context.lock().await;
let rendered = ctx.render();
let dump_path = format!("/tmp/poc-{}-prompt.txt", agent_name);
let _ = std::fs::write(&dump_path, &rendered);
}
let log_path = format!("/tmp/poc-{}.log", agent_name);
let mut log_file = std::fs::OpenOptions::new()
.create(true).append(true).open(&log_path).ok();

View file

@ -540,10 +540,9 @@ impl Agent {
pub async fn compact(&self) {
match crate::config::reload_for_model(&self.app_config, &self.prompt_file) {
Ok((system_prompt, personality)) => {
Ok((_system_prompt, personality)) => {
let mut ctx = self.context.lock().await;
ctx.clear(Section::System);
ctx.push(Section::System, AstNode::system_msg(&system_prompt));
// System section (prompt + tools) set by new(), don't touch it
ctx.clear(Section::Identity);
for (name, content) in &personality {
ctx.push(Section::Identity, AstNode::memory(name, content));