Debug: add context token count to parser log, fix compact() tool defs

compact() was clearing tool definitions from the system section on
startup — now leaves system section untouched (set once by new()).
Added context token count to parser done log for diagnosing the
subconscious agent loop issue.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-08 17:57:10 -04:00
parent fc75b181cf
commit 8bf6753949

View file

@ -491,13 +491,6 @@ 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();
@ -524,8 +517,9 @@ impl ResponseParser {
if let Some(ref mut f) = log_file {
use std::io::Write;
let tc_count = full_text.matches("<tool_call>").count();
let _ = writeln!(f, "done: {} chars, {} <tool_call> tags",
full_text.len(), tc_count);
let ctx_tokens = agent.context.lock().await.tokens();
let _ = writeln!(f, "done: {} chars, {} <tool_call> tags, ctx: {} tokens",
full_text.len(), tc_count, ctx_tokens);
if tc_count == 0 && full_text.len() > 0 {
let _ = writeln!(f, "full text:\n{}", &full_text[..full_text.len().min(2000)]);
}