pub struct SessionStats {
pub turns: u64,
pub input_tokens: u64,
pub output_tokens: u64,
pub cache_read_tokens: u64,
pub cache_write_tokens: u64,
pub tools: Vec<(String, u64)>,
pub last_input_tokens: Option<u64>,
}Expand description
Aggregate view of a conversation for /usage: how many turns reported
usage, the summed token counts, and which tools ran.
Pure data — no timing, no cost (there is no timestamp in AgentMessage).
Derive order is fixed so tests can compare by value.
Fields§
§turns: u64Assistant messages that carried Some(usage).
input_tokens: u64§output_tokens: u64§cache_read_tokens: u64Cache counts absent on a call are treated as 0.
cache_write_tokens: u64§tools: Vec<(String, u64)>Tool name → call count, one entry per distinct name, sorted by count descending, ties broken by name ascending. Empty when no tool has been called.
last_input_tokens: Option<u64>Provider-reported input tokens of the most recent Assistant message with
Some(usage): how full the context was on the last request. None
until a turn reports usage.
Implementations§
Source§impl SessionStats
impl SessionStats
Sourcepub fn summary(&self) -> String
pub fn summary(&self) -> String
The one-line summary both front-ends print: plain text — no colors, no layout, no context; front-ends add chrome.
Contract:
turns == 0⇒"(no usage reported)".- otherwise ⇒
"usage: N turns, X in, Y out[, C cache read][, W cache write][, tools: …]"where the cache fields are omitted when 0, thetools:segment is omitted when no tool ran, and the tool names are capped atTOOL_LIST_CAP, the remainder folded into"+K more". - The trailing
context U/Lreadout is intentionally NOT here: its limit comes from the front-end (REPLmodel_limit, TUIstatus.context_limit), so each wraps/appends it.
Trait Implementations§
Source§impl Clone for SessionStats
impl Clone for SessionStats
Source§impl Debug for SessionStats
impl Debug for SessionStats
Source§impl Default for SessionStats
impl Default for SessionStats
impl Eq for SessionStats
Source§impl PartialEq for SessionStats
impl PartialEq for SessionStats
impl StructuralPartialEq for SessionStats
Auto Trait Implementations§
impl Freeze for SessionStats
impl RefUnwindSafe for SessionStats
impl Send for SessionStats
impl Sync for SessionStats
impl Unpin for SessionStats
impl UnsafeUnpin for SessionStats
impl UnwindSafe for SessionStats
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.