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:
Dhanji R. Prasanna
2025-12-24 15:44:19 +11:00
parent fd22ce9890
commit cd64ebbf87
6 changed files with 16 additions and 8 deletions

View File

@@ -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();
}