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): introduce host controls for model execution
Steven Enamakel5efd6afc1240
diff --git a/crates/openhuman-core/src/agent/tinyagents/budget.rs b/crates/openhuman-core/src/agent/tinyagents/budget.rsindex 179b66daab..a2bac9d82e 100644--- a/crates/openhuman-core/src/agent/tinyagents/budget.rs+++ b/crates/openhuman-core/src/agent/tinyagents/budget.rs@@ -47,6 +47,22 @@ impl ModelBudget {tinyagents_harness::cost::ModelBudget::new(self.ledger.clone(), self.call).wrap_model_with_observer(model, observer)}++ pub(crate) fn control(+ model: Arc<dyn ChatModel<()>>,+ budget: Option<&Self>,+ admission: Option<Arc<dyn PhysicalDispatchAdmission>>,+ ) -> Arc<dyn ChatModel<()>> {+ let monetary_budget = budget.map(|budget| {+ tinyagents_harness::cost::ModelBudget::new(budget.ledger.clone(), budget.call)+ });+ Arc::new(tinyagents_harness::cost::ControlledChatModel::new(+ model,+ DispatchModelOptions::new()+ .monetary_budget(monetary_budget)+ .admission(admission),+ ))+ }}/// Effective host depth ceiling, never wider than product policy.@@ -69,14 +85,18 @@ pub(super) fn install_depth(impl crate::inference::turn_models::TurnModels {/// Wrap every concrete route and summarizer below harness retries/fallback.- pub(crate) fn with_budget(mut self, budget: Option<&ModelBudget>) -> Self {- let Some(budget) = budget else {+ pub(crate) fn with_host_controls(+ mut self,+ budget: Option<&ModelBudget>,+ admission: Option<Arc<dyn PhysicalDispatchAdmission>>,+ ) -> Self {+ if budget.is_none() && admission.is_none() {return self;- };- self.primary = budget.wrap(self.primary);- self.summarizer = budget.wrap(self.summarizer);+ }+ self.primary = ModelBudget::control(self.primary, budget, admission.clone());+ self.summarizer = ModelBudget::control(self.summarizer, budget, admission.clone());for (_, route) in &mut self.routes {- *route = budget.wrap(route.clone());+ *route = ModelBudget::control(route.clone(), budget, admission.clone());}self}diff --git a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rsindex e384feca9b..431c596981 100644--- a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs+++ b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs@@ -144,10 +144,11 @@ impl HarnessPayloadSummarizer<OpenHumanRunContext> for SubagentPayloadSummarizer);let provider_model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =Arc::new(provider_model);- let provider_model = match &child_context.data.model_budget {- Some(budget) => budget.wrap(provider_model),- None => provider_model,- };+ let provider_model = super::budget::ModelBudget::control(+ provider_model,+ child_context.data.model_budget.as_ref(),+ child_context.data.dispatch_admission.clone(),+ );// Unary, never streaming: a streaming child would publish the// internal summary to the user as parent `TextDelta`s.Ok(run_unary_summary(diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rsindex 0c9bf28448..72ced1691b 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec.rs@@ -181,7 +181,10 @@ async fn drive_turn(let hosted_security_gate = hosted_root.is_some();let is_local = turn_models.is_local();// Wrap concrete routes before the invocation-local hosted resolver captures them.- let turn_models = turn_models.with_budget(run_context.model_budget.as_ref());+ let turn_models = turn_models.with_host_controls(+ run_context.model_budget.as_ref(),+ run_context.dispatch_admission.clone(),+ );let hosted_model_resolver = hosted_root.as_ref().map(|_| {Arc::new(turn_models.resolver()) as Arc<dyn tinyagents_harness::host::ModelResolver<()>>});diff --git a/crates/openhuman-core/src/inference/host_runtime/ops.rs b/crates/openhuman-core/src/inference/host_runtime/ops.rsindex b37d848af0..38e3877bf4 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops.rs@@ -17,7 +17,9 @@ pub use agent_chat::{agent_chat, agent_chat_for, agent_chat_reply_for, agent_chat_simple, AgentChatEnv,AgentChatReply, AgentChatTarget,};-pub use complete_once::{complete_once, complete_once_observed, CompletionEndpoint};+pub use complete_once::{+ complete_once, complete_once_controlled, complete_once_observed, CompletionEndpoint,+};pub use runtime_ops::{local_ai_prompt, local_ai_status, local_ai_summarize, local_ai_transcribe,local_ai_transcribe_bytes, local_ai_tts, local_ai_vision_prompt,diff --git a/crates/openhuman-embed/src/complete.rs b/crates/openhuman-embed/src/complete.rsindex 2e3258f8ff..dce8db1fdc 100644--- a/crates/openhuman-embed/src/complete.rs+++ b/crates/openhuman-embed/src/complete.rs@@ -658,14 +658,16 @@ impl Completer {);let started = std::time::Instant::now();let response = call.await.map_err(|error| {- if let tinyagents_harness::cost::ControlledDispatchError::Admission(source) = error {- return CoreError::DispatchAdmission {- method: COMPLETE,- source,- usage: None,- };- }- let message = error.to_string();+ let message = match error {+ tinyagents_harness::cost::ControlledDispatchError::Admission(source) => {+ return CoreError::DispatchAdmission {+ method: COMPLETE,+ source,+ usage: None,+ };+ }+ error => error.to_string(),+ };if let Some(source) = budget.as_ref().and_then(|budget| budget.ledger.refusal()) {return CoreError::BudgetExceeded {method: COMPLETE,