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,
) -> CostTracker
pub fn new( model_registry: Arc<ModelRegistry>, config: CostTrackerConfig, ) -> CostTracker
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