pub struct CostTracker { /* private fields */ }Expand description
Cost tracker — accumulates token usage and computed costs per agent.
Usage: call record(agent_id, model, usage) after each LLM call,
then query snapshot(agent_id) or global_snapshot().
Implementations§
Source§impl CostTracker
impl CostTracker
Sourcepub fn new(
model_registry: Arc<ModelRegistry>,
config: CostTrackerConfig,
) -> Self
pub fn new( model_registry: Arc<ModelRegistry>, config: CostTrackerConfig, ) -> Self
Create a new cost tracker.
Sourcepub fn record(&self, agent_id: &str, model: &Model, usage: TokenUsage)
pub fn record(&self, agent_id: &str, model: &Model, usage: TokenUsage)
Record token usage for an agent using a model’s pricing.
Sourcepub fn snapshot(&self, agent_id: &str) -> Option<CostSnapshot>
pub fn snapshot(&self, agent_id: &str) -> Option<CostSnapshot>
Snapshot for a specific agent.
Sourcepub fn global_snapshot(&self) -> GlobalCostSnapshot
pub fn global_snapshot(&self) -> GlobalCostSnapshot
Global snapshot across all agents.
Sourcepub fn is_over_budget(&self, agent_id: &str) -> bool
pub fn is_over_budget(&self, agent_id: &str) -> bool
Returns true if the agent has exceeded its per-agent budget.
Sourcepub fn is_over_global_budget(&self) -> bool
pub fn is_over_global_budget(&self) -> bool
Returns true if the total across all agents exceeds the global budget.
Sourcepub fn agent_cost(&self, agent_id: &str) -> f64
pub fn agent_cost(&self, agent_id: &str) -> f64
Get current total cost for an agent.
Auto Trait Implementations§
impl !RefUnwindSafe for CostTracker
impl !UnwindSafe for CostTracker
impl Freeze for CostTracker
impl Send for CostTracker
impl Sync for CostTracker
impl Unpin for CostTracker
impl UnsafeUnpin for CostTracker
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.