pub struct TokenUsage {
pub input_tokens: u64,
pub output_tokens: u64,
pub total_tokens: u64,
}Expand description
Aggregated token usage for one worker attempt, normalized across
worker kinds (agent-block agent.run return / subprocess declared
mapping / operator self-report). Field names follow the Anthropic
wire convention (input_tokens / output_tokens) that agent-block
already normalizes OpenAI-style responses into.
Every wire field is optional on the way in (TokenUsageWire):
a reporter that only knows one axis (a harness completion notice
that surfaces a single token total, an API response that omits the
total) still lands a usable usage record instead of being dropped.
The stored shape stays the closed 3-field triple — missing splits
read as 0, and a missing total_tokens is derived as
input + output on decode.
Fields§
§input_tokens: u64Prompt-side tokens consumed, summed across the attempt’s turns.
0 when the reporter did not split its total.
output_tokens: u64Completion-side tokens produced, summed across the attempt’s
turns. 0 when the reporter did not split its total.
total_tokens: u64input + output (kept explicit because some producers report a
total that includes cache-read/creation tokens the two split
fields don’t cover). Derived from the splits when the reporter
omits it.
Implementations§
Source§impl TokenUsage
impl TokenUsage
Sourcepub fn from_parts(
input_tokens: Option<u64>,
output_tokens: Option<u64>,
total_tokens: Option<u64>,
) -> Option<Self>
pub fn from_parts( input_tokens: Option<u64>, output_tokens: Option<u64>, total_tokens: Option<u64>, ) -> Option<Self>
Build a usage record from three independently-optional parts,
applying the same normalization the wire decode does: absent
splits read as 0, and an absent total is derived as
input + output.
None only when the reporter carried no token axis at all —
the caller then records no usage rather than a zeroed one.
Shared by the hand-rolled extractors that read usage out of a
worker’s raw payload (agent-block’s agent.run return,
subprocess usage_ptr declarations) so every axis applies one
normalization rule.
Trait Implementations§
Source§impl Clone for TokenUsage
impl Clone for TokenUsage
Source§fn clone(&self) -> TokenUsage
fn clone(&self) -> TokenUsage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TokenUsage
impl Debug for TokenUsage
Source§impl<'de> Deserialize<'de> for TokenUsage
impl<'de> Deserialize<'de> for TokenUsage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for TokenUsage
Source§impl From<TokenUsageWire> for TokenUsage
impl From<TokenUsageWire> for TokenUsage
Source§fn from(w: TokenUsageWire) -> Self
fn from(w: TokenUsageWire) -> Self
Source§impl JsonSchema for TokenUsage
impl JsonSchema for TokenUsage
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for TokenUsage
impl PartialEq for TokenUsage
Source§impl Serialize for TokenUsage
impl Serialize for TokenUsage
impl StructuralPartialEq for TokenUsage
Auto Trait Implementations§
impl Freeze for TokenUsage
impl RefUnwindSafe for TokenUsage
impl Send for TokenUsage
impl Sync for TokenUsage
impl Unpin for TokenUsage
impl UnsafeUnpin for TokenUsage
impl UnwindSafe for TokenUsage
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more