From 8bf6753949d154ccaeadb529089609f77be6c967 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 8 Apr 2026 17:57:10 -0400 Subject: [PATCH] Debug: add context token count to parser log, fix compact() tool defs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/agent/context.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/agent/context.rs b/src/agent/context.rs index 0223183..05ad935 100644 --- a/src/agent/context.rs +++ b/src/agent/context.rs @@ -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("").count(); - let _ = writeln!(f, "done: {} chars, {} tags", - full_text.len(), tc_count); + let ctx_tokens = agent.context.lock().await.tokens(); + let _ = writeln!(f, "done: {} chars, {} 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)]); }