diff --git a/FEATURE_PARITY.md b/FEATURE_PARITY.md index d6952cbd..61e32b0c 100644 --- a/FEATURE_PARITY.md +++ b/FEATURE_PARITY.md @@ -53,7 +53,7 @@ This document tracks feature parity between IronClaw (Rust implementation) and O | Trusted-proxy auth mode | ✅ | ❌ | Header-based auth for reverse proxies | | APNs push pipeline | ✅ | ❌ | Wake disconnected iOS nodes via push | | Oversized payload guard | ✅ | 🚧 | HTTP webhook has 64KB body limit + Content-Length check; no chat.history cap | -| Pre-prompt context diagnostics | ✅ | ❌ | Context size logging before prompt | +| Pre-prompt context diagnostics | ✅ | 🚧 | Token breakdown logged before LLM call (conversational dispatcher path); other LLM entry points not yet covered | ### Owner: _Unassigned_ diff --git a/src/agent/dispatcher.rs b/src/agent/dispatcher.rs index 99feed9d..b1678d89 100644 --- a/src/agent/dispatcher.rs +++ b/src/agent/dispatcher.rs @@ -10,6 +10,7 @@ use tokio::task::JoinSet; use uuid::Uuid; use crate::agent::Agent; +use crate::agent::context_monitor::{ContextBreakdown, estimate_text_tokens}; use crate::agent::session::{PendingApproval, Session, ThreadState}; use crate::channels::{IncomingMessage, StatusUpdate}; use crate::context::JobContext; @@ -254,6 +255,27 @@ impl Agent { ); } + // Pre-prompt context diagnostics: log token breakdown before LLM call + { + let breakdown = ContextBreakdown::analyze(&context_messages); + let system_prompt_tokens = + estimate_text_tokens(context.system_prompt.as_deref().unwrap_or("")); + let total_tokens = breakdown.total_tokens + system_prompt_tokens; + tracing::debug!( + iteration, + messages = breakdown.message_count, + total_tokens, + system_prompt_tokens, + system_msg_tokens = breakdown.system_tokens, + user_tokens = breakdown.user_tokens, + assistant_tokens = breakdown.assistant_tokens, + tool_tokens = breakdown.tool_tokens, + tools_available = context.available_tools.len(), + force_text, + "Pre-prompt context diagnostics" + ); + } + let _ = self .channels .send_status(