Add parser debug logging (POC_DEBUG=1)

Logs full text length, <tool_call> tag count, and tool call details
on stream completion. Helps diagnose parsing issues with subconscious
agents.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-08 17:38:02 -04:00
parent 119dc8c146
commit 473909db47
2 changed files with 25 additions and 2 deletions

View file

@ -490,15 +490,39 @@ impl ResponseParser {
let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
let handle = tokio::spawn(async move { let handle = tokio::spawn(async move {
let mut parser = self; let mut parser = self;
let debug = std::env::var("POC_DEBUG").is_ok();
let mut full_text = String::new();
while let Some(event) = stream.recv().await { while let Some(event) = stream.recv().await {
match event { match event {
super::api::StreamToken::Token { text, id } => { super::api::StreamToken::Token { text, id } => {
full_text.push_str(&text);
let mut ctx = agent.context.lock().await; let mut ctx = agent.context.lock().await;
for call in parser.feed_token(&text, id, &mut ctx) { let calls = parser.feed_token(&text, id, &mut ctx);
if !calls.is_empty() && debug {
for c in &calls {
eprintln!("[parser] tool_call: {} args={}",
c.name, &c.arguments[..c.arguments.len().min(80)]);
}
}
for call in calls {
let _ = tx.send(call); let _ = tx.send(call);
} }
} }
super::api::StreamToken::Done { usage } => { super::api::StreamToken::Done { usage } => {
if debug {
let tc_count = full_text.matches("<tool_call>").count();
eprintln!("[parser] done: {} chars, {} <tool_call> tags",
full_text.len(), tc_count);
if tc_count > 0 {
// Log the raw text around tool calls for debugging
for (i, part) in full_text.split("<tool_call>").enumerate() {
if i > 0 {
eprintln!("[parser] tool_call text: {}...",
&part[..part.len().min(200)]);
}
}
}
}
if let Some(u) = usage { if let Some(u) = usage {
agent.state.lock().await.last_prompt_tokens = u.prompt_tokens; agent.state.lock().await.last_prompt_tokens = u.prompt_tokens;
} }

View file

@ -112,7 +112,6 @@ impl AutoAgent {
} }
} }
/// Run standalone — TODO: needs rewrite to use completions API
pub async fn run( pub async fn run(
&mut self, &mut self,
_bail_fn: Option<&(dyn Fn(usize) -> Result<(), String> + Sync)>, _bail_fn: Option<&(dyn Fn(usize) -> Result<(), String> + Sync)>,