diff --git a/src/agent/context.rs b/src/agent/context.rs index 4aef3e8..d0e683a 100644 --- a/src/agent/context.rs +++ b/src/agent/context.rs @@ -490,15 +490,39 @@ impl ResponseParser { let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); let handle = tokio::spawn(async move { 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 { match event { super::api::StreamToken::Token { text, id } => { + full_text.push_str(&text); 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); } } super::api::StreamToken::Done { usage } => { + if debug { + let tc_count = full_text.matches("").count(); + eprintln!("[parser] done: {} chars, {} 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("").enumerate() { + if i > 0 { + eprintln!("[parser] tool_call text: {}...", + &part[..part.len().min(200)]); + } + } + } + } if let Some(u) = usage { agent.state.lock().await.last_prompt_tokens = u.prompt_tokens; } diff --git a/src/agent/oneshot.rs b/src/agent/oneshot.rs index 45dcab8..eeaa057 100644 --- a/src/agent/oneshot.rs +++ b/src/agent/oneshot.rs @@ -112,7 +112,6 @@ impl AutoAgent { } } - /// Run standalone — TODO: needs rewrite to use completions API pub async fn run( &mut self, _bail_fn: Option<&(dyn Fn(usize) -> Result<(), String> + Sync)>,