diff --git a/src/agent/context.rs b/src/agent/context.rs index 93ef607..8063918 100644 --- a/src/agent/context.rs +++ b/src/agent/context.rs @@ -607,19 +607,18 @@ impl ResponseParser { super::api::StreamToken::Done { usage } => { if let Some(ref mut f) = log_file { use std::io::Write; - let tc_count = full_text.matches("").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 ctx = agent.context.lock().await; + let children = ctx.conversation().get(parser.branch_idx) + .map(|n| n.children()).unwrap_or(&[]); + let n_think = children.iter().filter(|c| matches!(c.leaf().map(|l| l.body()), Some(NodeBody::Thinking(_)))).count(); + let n_content = children.iter().filter(|c| matches!(c.leaf().map(|l| l.body()), Some(NodeBody::Content(_)))).count(); + let n_tool = children.iter().filter(|c| matches!(c.leaf().map(|l| l.body()), Some(NodeBody::ToolCall { .. }))).count(); + let _ = writeln!(f, "done: {} chars, {} content + {} think + {} tool_call, ctx: {} tokens", + full_text.len(), n_content, n_think, n_tool, ctx.tokens()); + drop(ctx); + if full_text.len() > 0 && n_content == 0 && n_tool == 0 { let end = full_text.floor_char_boundary(full_text.len().min(2000)); - let _ = writeln!(f, "full text:\n{}", &full_text[..end]); - } - for (i, part) in full_text.split("").enumerate() { - if i > 0 { - let end = part.floor_char_boundary(part.len().min(200)); - let _ = writeln!(f, "tool_call body: {}...", &part[..end]); - } + let _ = writeln!(f, " unparsed text: {}", &full_text[..end]); } } if let Some(u) = usage {