Add tokens consumed and context percentage to per-tool timing footer
The per-tool timing line now shows:
- Tokens delta (tokens added to context by this tool call)
- Context window usage percentage
Example: └─ ⚡️ 1ms 523tk | 49% ctx
Changes:
- Updated UiWriter trait print_tool_timing signature
- Track tokens before/after adding tool messages to calculate delta
- Updated ConsoleUiWriter, MachineUiWriter, PlannerUiWriter, and test mocks
This commit is contained in:
@@ -4072,6 +4072,9 @@ impl<W: UiWriter> Agent<W> {
|
||||
}
|
||||
};
|
||||
|
||||
// Track tokens before adding messages
|
||||
let tokens_before = self.context_window.used_tokens;
|
||||
|
||||
self.context_window.add_message(tool_message);
|
||||
self.context_window.add_message(result_message);
|
||||
|
||||
@@ -4107,8 +4110,11 @@ impl<W: UiWriter> Agent<W> {
|
||||
|
||||
// Closure marker with timing
|
||||
if tool_call.tool != "final_output" {
|
||||
let tokens_delta = self.context_window.used_tokens.saturating_sub(tokens_before);
|
||||
self.ui_writer
|
||||
.print_tool_timing(&Self::format_duration(exec_duration));
|
||||
.print_tool_timing(&Self::format_duration(exec_duration),
|
||||
tokens_delta,
|
||||
self.context_window.percentage_used());
|
||||
self.ui_writer.print_agent_prompt();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ pub trait UiWriter: Send + Sync {
|
||||
fn print_tool_output_summary(&self, hidden_count: usize);
|
||||
|
||||
/// Print tool execution timing
|
||||
fn print_tool_timing(&self, duration_str: &str);
|
||||
fn print_tool_timing(&self, duration_str: &str, tokens_delta: u32, context_percentage: f32);
|
||||
|
||||
/// Print the agent prompt indicator
|
||||
fn print_agent_prompt(&self);
|
||||
@@ -99,7 +99,7 @@ impl UiWriter for NullUiWriter {
|
||||
fn update_tool_output_line(&self, _line: &str) {}
|
||||
fn print_tool_output_line(&self, _line: &str) {}
|
||||
fn print_tool_output_summary(&self, _hidden_count: usize) {}
|
||||
fn print_tool_timing(&self, _duration_str: &str) {}
|
||||
fn print_tool_timing(&self, _duration_str: &str, _tokens_delta: u32, _context_percentage: f32) {}
|
||||
fn print_agent_prompt(&self) {}
|
||||
fn print_agent_response(&self, _content: &str) {}
|
||||
fn notify_sse_received(&self) {}
|
||||
|
||||
Reference in New Issue
Block a user