Skip to content

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

feat(inference): gate harness model builds and allow per-request model overrides

Steven Enamakel030bd9ecb964
diff --git a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs b/crates/openhuman-core/src/inference/provider/factory/access_gates.rs
index 2a7618d7dc..06b94d1cb4 100644
--- a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/access_gates.rs
@@ -406,3 +406,22 @@ pub(crate) fn current_host_requires_session() -> bool {
pub(super) fn host_requires_session(host_kind: crate::core::types::HostKind) -> bool {
host_kind != crate::core::types::HostKind::Library
}
+
+/// The access check every model a harness turn builds passes first.
+impl tinyagents_harness::host::ModelBuildGate for super::OpenHumanModelFactory<'_> {
+ fn check(
+ &self,
+ request: &tinyagents_harness::host::ModelBuildRequest,
+ ) -> tinyagents_harness::Result<()> {
+ // Explicit host model injection is authoritative and has no provider
+ // construction, credential, or egress side effect to gate.
+ if self.injected(request).is_some() {
+ return Ok(());
+ }
+ let provider = self.provider_for(request);
+ enforce_local_only_inference(&request.role, &provider)
+ .map_err(|error| tinyagents_harness::TinyAgentsError::Model(error.to_string()))?;
+ verify_provider_session_in(self.ctx, self.config, &provider)
+ .map_err(|error| tinyagents_harness::TinyAgentsError::Model(error.to_string()))
+ }
+}
diff --git a/crates/openhuman-core/src/inference/provider/factory/chat_model.rs b/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
index 65a6915178..89f5dceef7 100644
--- a/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/chat_model.rs
@@ -12,6 +12,7 @@ use super::{
credentials::CredentialAccess,
local_runtime::try_create_local_runtime_chat_model_from_string,
provider_for_role,
+ routing::route_with_model,
subprocess_providers::OpenHumanMcpEndpoint,
BYOK_INCOMPLETE_SENTINEL, CLAUDE_AGENT_SDK_PREFIX, CLAUDE_AGENT_SDK_PROVIDER,
PROVIDER_OPENHUMAN,
diff --git a/crates/openhuman-core/src/inference/provider/factory/routing.rs b/crates/openhuman-core/src/inference/provider/factory/routing.rs
index 6e3135f490..9cefacf51b 100644
--- a/crates/openhuman-core/src/inference/provider/factory/routing.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/routing.rs
@@ -223,6 +223,26 @@ pub(super) fn route_has_usable_credentials(resolved: &str, config: &Config) -> b
false
}
+/// `provider` with its model replaced by `model`, when one is given: the same
+/// provider (and so the same credentials, endpoint and route temperature)
+/// serving another model. A provider string with no model of its own (a
+/// routing sentinel such as `cloud`, or the managed backend's bare
+/// `openhuman`) is returned as is; those routes take the model from the
+/// request's pin instead.
+pub(super) fn route_with_model(provider: String, model: Option<&str>) -> String {
+ use tinyinference_providers::route::{ProviderRoute, RouteKind};
+ let Some(model) = model else {
+ return provider;
+ };
+ match ProviderRoute::parse(&provider) {
+ Some(route) if route.kind() != RouteKind::Sentinel => match route.temperature {
+ Some(temperature) => format!("{}:{model}@{temperature}", route.provider),
+ None => format!("{}:{model}", route.provider),
+ },
+ _ => provider,
+ }
+}
+
#[cfg(test)]
#[path = "routing_tests.rs"]
mod routing_tests;