Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(tinyhumans): add budget gate for inference requests

Steven Enamakel91edaccdbeb0
diff --git a/crates/openhuman-core/src/inference/registry.rs b/crates/openhuman-core/src/inference/registry.rs
index ef249e5306..5032914c85 100644
--- a/crates/openhuman-core/src/inference/registry.rs
+++ b/crates/openhuman-core/src/inference/registry.rs
@@ -41,9 +41,11 @@ pub struct ChatModelRequest<'a> {
pub role: &'a str,
/// The configuration in force.
pub config: &'a Config,
- /// A concrete model id or a role alias (`hint:coding`) the caller pinned.
+ /// The concrete model id the core resolved for this construction (a role
+ /// alias such as `hint:coding` has already been translated to the
+ /// configured default).
pub model_override: Option<&'a str>,
- /// The model the turn runs on when the caller did not pin one.
+ /// The model the turn runs on when the request itself names none.
pub default_model: Option<&'a str>,
/// Whether the model should use native tool calling.
pub native_tool_calling: bool,
@@ -115,6 +117,11 @@ pub struct EmbeddingRequest<'a> {
pub dimensions: usize,
/// The chat turn the call is made in, so disclosures reach that chat.
pub chat: Option<ApprovalChatContext>,
+ /// The directory the caller's credentials live in (the config's credential
+ /// scope, or the process default when the caller has no config).
+ pub state_dir: std::path::PathBuf,
+ /// Whether that credential store is encrypted at rest.
+ pub secrets_encrypt: bool,
}
/// Builds an embedding model.
diff --git a/crates/openhuman-tinyhumans/Cargo.toml b/crates/openhuman-tinyhumans/Cargo.toml
index 4ae2ee8b1e..f076ef4b02 100644
--- a/crates/openhuman-tinyhumans/Cargo.toml
+++ b/crates/openhuman-tinyhumans/Cargo.toml
@@ -78,12 +78,19 @@ log = "0.4"
reqwest = { version = "0.12", default-features = false, features = ["json", "multipart", "rustls-tls"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
+sha2 = "0.10"
thiserror = "2"
# Hosted speech (`voice` feature): the live-provider types the hosted Gemini /
# ElevenLabs sessions build, and the transcription / reply-speech wire helpers.
tinyagents-live = { path = "../../vendor/tinyagents/crates/tinyagents-live", optional = true }
tinyinference-voice = { path = "../../vendor/tinyagents/vendor/tinyinference/crates/tinyinference-voice", features = ["schemars"] }
tinyinference-providers = { path = "../../vendor/tinyagents/vendor/tinyinference/crates/tinyinference-providers" }
+# Managed inference: the crate wire model/embedding types and the error
+# sanitizer. Same vendored paths as the core's, so one copy resolves.
+tinyinference-llm = { path = "../../vendor/tinyagents/vendor/tinyinference/crates/tinyinference-llm" }
+tinyinference-embeddings = { path = "../../vendor/tinyagents/vendor/tinyinference/crates/tinyinference-embeddings" }
+tinyinference-core = { path = "../../vendor/tinyagents/vendor/tinyinference/crates/tinyinference-core" }
+directories = "6"
urlencoding = "2.1"
tracing = "0.1"
tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread", "sync", "time"] }
diff --git a/crates/openhuman-tinyhumans/src/integrations/client/budget_gate.rs b/crates/openhuman-tinyhumans/src/integrations/client/budget_gate.rs
index 857e1cff73..b9536c1bae 100644
--- a/crates/openhuman-tinyhumans/src/integrations/client/budget_gate.rs
+++ b/crates/openhuman-tinyhumans/src/integrations/client/budget_gate.rs
@@ -10,7 +10,7 @@
//! about one probe a minute across both surfaces.
//!
//! The pre-call probe reads `GET /teams/me/usage` through
-//! [`BackendClient`], so it rides the backend transport port. It resolves
+//! [`BackendClient`], so it rides this crate's SDK transport. It resolves
//! the credential first and defers to the backend (allows the call) without
//! any request when there is no usable TinyHumans credential — the offline
//! local session, an API-less core, or a signed-out user.
@@ -20,6 +20,7 @@ use std::time::{Duration, Instant};
use serde_json::Value;
+use crate::backend::url::effective_backend_api_url;
use crate::client::BackendClient;
use openhuman_embed::__host::config::Config;
use openhuman_embed::__host::core::Outcome;
@@ -29,7 +30,7 @@ use openhuman_embed::__host::security::credentials::session_support::BackendCred
/// already-resolved credential. `flatten_authed_error` keeps the typed 401 on
/// the `SESSION_EXPIRED` sentinel so a lapse never anchors the backoff.
async fn fetch_usage(config: &Config, credential: BackendCredential) -> Result<Value, String> {
- let api_url = crate::backend::require_base_url(&config.api_url)?;
+ let api_url = effective_backend_api_url(&config.api_url);
let client = BackendClient::new(&api_url).map_err(|e| format!("{e:#}"))?;
client
.authed_json(&credential, reqwest::Method::GET, "/teams/me/usage", None)
@@ -128,7 +129,7 @@ where
async fn probe_usage(config: &Config) -> Result<Value, String> {
let credential =
openhuman_embed::__host::security::credentials::session_support::resolve_backend_credential(config)?;
- let backend_key = crate::backend::require_base_url(&config.api_url)?;
+ let backend_key = effective_backend_api_url(&config.api_url);
usage_with_failure_backoff(&backend_key, || fetch_usage(config, credential))
.await
.map(|outcome| outcome.value)
diff --git a/crates/openhuman-tinyhumans/src/integrations/client/pricing.rs b/crates/openhuman-tinyhumans/src/integrations/client/pricing.rs
index c6d991f77e..72194d7ed2 100644
--- a/crates/openhuman-tinyhumans/src/integrations/client/pricing.rs
+++ b/crates/openhuman-tinyhumans/src/integrations/client/pricing.rs
@@ -6,6 +6,7 @@ use std::sync::Arc;
use crate::integrations::types::IntegrationPricing;
use super::construct::IntegrationClient;
+use crate::backend::url::effective_backend_api_url;
impl IntegrationClient {
/// Fetch and cache pricing info from the backend. Returns a default
@@ -56,7 +57,7 @@ pub async fn pricing_for_config(
client: &IntegrationClient,
config: &openhuman_embed::__host::config::Config,
) -> IntegrationPricing {
- use crate::config::schema::COMPOSIO_MODE_DIRECT;
+ use openhuman_embed::__host::config::schema::COMPOSIO_MODE_DIRECT;
if config.composio.mode.trim() == COMPOSIO_MODE_DIRECT {
tracing::debug!(
@@ -74,9 +75,9 @@ pub async fn pricing_for_config(
///
/// Both the backend URL and the credential come from **core defaults**:
///
-/// - backend URL → [`crate::backend::base_url`]
+/// - backend URL → [`effective_backend_api_url`]
/// applied to `config.api_url`. Unlike the plain
-/// [`crate::backend::inference_base_url`] resolver (which honours a
+/// `effective_api_url` resolver (which honours a
/// user-set local-AI endpoint so chat completions still work), the
/// backend resolver detects local-AI URLs and falls back to the
/// `BACKEND_URL` / `VITE_BACKEND_URL` env vars (and finally the hosted
@@ -102,15 +103,7 @@ pub fn build_client(config: &openhuman_embed::__host::config::Config) -> Option<
// which 404 against the local LLM and flooded Sentry
// (OPENHUMAN-TAURI-51 / -80 / -7Z). The helper falls through to env /
// default backend in that case so integrations actually work.
- let backend_url = match crate::backend::base_url(&config.api_url) {
- Ok(url) => url,
- Err(_) => {
- tracing::debug!(
- "[integrations] no backend transport — integrations client unavailable"
- );
- return None;
- }
- };
+ let backend_url = effective_backend_api_url(&config.api_url);
let credential =
match openhuman_embed::__host::security::credentials::session_support::resolve_backend_credential(config) {