pub struct Usage {
pub tokens: Option<TokenUsage>,
pub cost: Option<CostUsage>,
pub metadata: MetadataMap,
}Expand description
Token and cost usage reported by a model provider for a single turn.
Reporters and compaction triggers inspect Usage to log progress, enforce
budgets, and decide when to compact the transcript.
§Example
use agentkit_core::{TokenUsage, Usage};
let usage = Usage::new(
TokenUsage::new(1500, 200)
.with_cached_input_tokens(1000)
.with_cache_write_input_tokens(1200),
);
let tokens = usage.tokens.as_ref().unwrap();
assert_eq!(tokens.input_tokens, 1500);Fields§
§tokens: Option<TokenUsage>Token counts for this turn, if the provider reports them.
cost: Option<CostUsage>Monetary cost for this turn, if the provider reports it.
metadata: MetadataMapArbitrary key-value metadata.
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn new(tokens: TokenUsage) -> Self
pub fn new(tokens: TokenUsage) -> Self
Builds a usage record with token counts and no cost.
Sourcepub fn with_metadata(self, metadata: MetadataMap) -> Self
pub fn with_metadata(self, metadata: MetadataMap) -> Self
Replaces the usage metadata.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Usage
impl<'de> Deserialize<'de> for Usage
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>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Usage
Auto Trait Implementations§
impl Freeze for Usage
impl RefUnwindSafe for Usage
impl Send for Usage
impl Sync for Usage
impl Unpin for Usage
impl UnsafeUnpin for Usage
impl UnwindSafe for Usage
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
Mutably borrows from an owned value. Read more