The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(tinyagents): update budget gate to handle optional model strings
Steven Enamakelef766e4fa220
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rs b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rsindex 08ba7f8cef..b5ef3f964c 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate.rs@@ -66,7 +66,7 @@ use tinyagents_harness::host::budget_gate::{};use tinyinference_llm::usage::Usage;-use crate::config::{Config, DEFAULT_MODEL};+use crate::config::Config;use crate::platform::cost;use crate::platform::llm_gate;use tinyjuice_bus::types::AgentTokenjuiceCompression;@@ -88,7 +88,7 @@ pub struct OpenHumanBudgetGate {/// Model attributed to the next [`record`](Self::record). Seeded from the/// session config and re-stamped by each [`acquire`](Self::acquire); see/// mismatch (1) in the module docs.- last_model: RwLock<String>,+ last_model: RwLock<Option<String>>,/// Whether this session's model calls are **background** work that must/// queue behind [`llm_gate`].///@@ -121,10 +121,7 @@ impl OpenHumanBudgetGate {/// The profile is a ceiling on the hint, not a trigger: see/// [`Self::cap_hint`].pub fn with_compression(config: Arc<Config>, compression: AgentTokenjuiceCompression) -> Self {- let fallback = config- .default_model- .clone()- .unwrap_or_else(|| DEFAULT_MODEL.to_string());+ let fallback = config.default_model.clone();Self {config,compression,@@ -162,7 +159,7 @@ impl OpenHumanBudgetGate {}/// The model id [`record`](Self::record) will attribute usage to.- fn attributed_model(&self) -> String {+ fn attributed_model(&self) -> Option<String> {self.last_model.read().clone()}@@ -238,7 +235,11 @@ impl OpenHumanBudgetGate {let model = if est.model.trim().is_empty() {self.attributed_model()} else {- est.model.clone()+ Some(est.model.clone())+ };+ let Some(model) = model else {+ log::debug!("[tinyagents][budget] no model available for estimate; skipping budget check");+ return None;};let call = cost::budget::CallUnderCheck {model: &model,@@ -298,7 +299,7 @@ impl BudgetGate for OpenHumanBudgetGate {/// session is signed out); the caller's turn timeout is what bounds that.async fn acquire(&self, est: &CallEstimate) -> Result<Permit> {if !est.model.trim().is_empty() {- *self.last_model.write() = est.model.clone();+ *self.last_model.write() = Some(est.model.clone());}// Configured budgets (`[[cost.budgets]]`) are checked before anything@@ -387,7 +388,7 @@ impl BudgetGate for OpenHumanBudgetGate {log::debug!("[tinyagents][budget] observed usage model={} in={} out={} cached={} (ledger is \written by the event bridge)",- self.attributed_model(),+ model = ?self.attributed_model(),usage.input_tokens,usage.output_tokens,usage.cache_read_tokens,diff --git a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate_tests.rsindex 5ffa34e7ed..3731701ced 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/budget_gate_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/budget_gate_tests.rs@@ -19,12 +19,12 @@ fn seeds_the_attributed_model_from_config() {let mut config = Config::default();config.default_model = Some("pinned-model".into());let gate = OpenHumanBudgetGate::new(Arc::new(config));- assert_eq!(gate.attributed_model(), "pinned-model");+ assert_eq!(gate.attributed_model(), Some("pinned-model".to_string()));let mut unpinned = Config::default();unpinned.default_model = None;let gate = OpenHumanBudgetGate::new(Arc::new(unpinned));- assert_eq!(gate.attributed_model(), DEFAULT_MODEL);+ assert_eq!(gate.attributed_model(), None);}#[tokio::test]@@ -35,7 +35,7 @@ async fn acquire_stamps_the_model_that_record_will_attribute() {gate.acquire(&CallEstimate::new("some/model", 10, 5)).await.expect("no tracker in tests, so nothing can refuse");- assert_eq!(gate.attributed_model(), "some/model");+ assert_eq!(gate.attributed_model(), Some("some/model".to_string()));}#[tokio::test]