huskies: merge 1015
This commit is contained in:
@@ -16,6 +16,10 @@ pub mod session_store;
|
||||
/// Token-usage tracking and budget estimation.
|
||||
pub mod token_usage;
|
||||
|
||||
/// Typed agent model enum (Sonnet/Opus/Haiku).
|
||||
pub mod model;
|
||||
pub use model::AgentModel;
|
||||
|
||||
use crate::config::AgentConfig;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -205,13 +209,13 @@ impl TokenUsage {
|
||||
/// data in the agent log (since `total_cost_usd` is only available in the
|
||||
/// `result` event at session end). Uses conservative (high) pricing when
|
||||
/// the model is unknown so budget limits are hit sooner rather than later.
|
||||
pub fn estimate_cost_usd(&self, model: Option<&str>) -> f64 {
|
||||
pub fn estimate_cost_usd(&self, model: Option<&AgentModel>) -> f64 {
|
||||
// Per-million-token pricing (input, output, cache_read, cache_create).
|
||||
let (inp, out, cr, cc) = match model {
|
||||
Some(m) if m.contains("haiku") => (0.80, 4.0, 0.08, 1.00),
|
||||
Some(m) if m.contains("sonnet") => (3.0, 15.0, 0.30, 3.75),
|
||||
// Opus or unknown → most expensive = conservative.
|
||||
_ => (15.0, 75.0, 1.50, 18.75),
|
||||
Some(AgentModel::Haiku) => (0.80, 4.0, 0.08, 1.00),
|
||||
Some(AgentModel::Sonnet) => (3.0, 15.0, 0.30, 3.75),
|
||||
// Opus, Other, or unknown → most expensive = conservative.
|
||||
Some(AgentModel::Opus) | Some(AgentModel::Other(_)) | None => (15.0, 75.0, 1.50, 18.75),
|
||||
};
|
||||
(self.input_tokens as f64 * inp
|
||||
+ self.output_tokens as f64 * out
|
||||
|
||||
Reference in New Issue
Block a user