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(inference): update model factory and context window logic
Steven Enamakel8b11e5d1497e
diff --git a/crates/openhuman-core/src/inference/context_window.rs b/crates/openhuman-core/src/inference/context_window.rsindex 154cc7783d..083c133290 100644--- a/crates/openhuman-core/src/inference/context_window.rs+++ b/crates/openhuman-core/src/inference/context_window.rs@@ -287,6 +287,8 @@ pub(crate) fn model_limits_request_for(crate::inference::provider::factory::CloudCredentialResolver(&resolution.key),).discovery_request(&spec, &options)+ .ok()+ .flatten()}/// Static hints owned outside TinyInference's generic model catalog.diff --git a/crates/openhuman-core/src/inference/provider/factory.rs b/crates/openhuman-core/src/inference/provider/factory.rsindex c8bda46334..deb49f590e 100644--- a/crates/openhuman-core/src/inference/provider/factory.rs+++ b/crates/openhuman-core/src/inference/provider/factory.rs@@ -34,26 +34,24 @@ pub(crate) use credentials::{openai_bearer_is_oauth, redact_endpoint_origin, resolve_codex_routing,};pub(crate) use local_runtime::create_local_chat_model_from_string;-pub(crate) use managed_backend::make_openhuman_backend_model;pub(crate) use routing::role_uses_implicit_cloud_fallback;pub use routing::{provider_for_role, role_bypasses_managed_credits};// Factory-internal helpers shared across the implementation modules.use access_gates::{emit_inference_egress, enforce_local_only_inference};-use chat_model::{unresolved_chat_model_error_for, with_default_temperature};+#[cfg(test)]+use chat_model::unresolved_chat_model_error_for;#[cfg(test)]use cloud_slug::try_create_cloud_slug_chat_model;-use cloud_slug::{- try_create_cloud_slug_chat_model_from_string,- try_create_cloud_slug_chat_model_from_string_with_native_tools_for,-};+#[cfg(test)]+use cloud_slug::try_create_cloud_slug_chat_model_from_string;+use cloud_slug::try_create_cloud_slug_chat_model_from_string_with_native_tools_for;use local_runtime::{try_create_local_runtime_chat_model_from_string, OptionalChatModelResult};#[cfg(test)]pub(crate) use managed_backend::make_openhuman_backend_model_for_thread;use managed_backend::managed_chat_model_for;pub(crate) use managed_backend::{make_openhuman_backend_model_for_options, make_openhuman_backend_model_for_thread_in,- make_openhuman_backend_model_in,};use subprocess_providers::OpenHumanMcpEndpoint;use tinyinference_providers::route::split_model_and_temperature;@@ -82,7 +80,7 @@ use crate::config::Config;use crate::security::credentials::AuthService;use crate::security::egress::EgressLedger;use std::sync::Arc;-use tinyinference_llm::model::{ChatModel, ModelRequest, ModelResponse, ModelStream};+use tinyinference_llm::model::ChatModel;use tinyinference_llm::providers::openai::codex::{openai_codex_client_version, openai_codex_user_agent, OPENAI_CODEX_ACCOUNT_HEADER,OPENAI_CODEX_ORIGINATOR, OPENAI_CODEX_ORIGINATOR_HEADER,diff --git a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs b/crates/openhuman-core/src/inference/provider/factory/access_gates.rsindex fccf26feca..bcce11271a 100644--- a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs+++ b/crates/openhuman-core/src/inference/provider/factory/access_gates.rs@@ -1,10 +1,7 @@//! Access chokepoints every provider constructor runs through: privacy-mode//! `LocalOnly` enforcement, the backend-session requirement, and egress disclosure.-use super::{- BYOK_INCOMPLETE_SENTINEL, CLAUDE_AGENT_SDK_PREFIX, CLAUDE_AGENT_SDK_PROVIDER,- PROVIDER_OPENHUMAN,-};+use super::{BYOK_INCOMPLETE_SENTINEL, CLAUDE_AGENT_SDK_PROVIDER, PROVIDER_OPENHUMAN};use crate::config::Config;use crate::security::credentials::AuthService;use crate::security::egress::EgressLedger;diff --git a/crates/openhuman-core/src/inference/provider/factory/chat_model.rs b/crates/openhuman-core/src/inference/provider/factory/chat_model.rsindex 0ee591c87f..cc47ab6397 100644--- a/crates/openhuman-core/src/inference/provider/factory/chat_model.rs+++ b/crates/openhuman-core/src/inference/provider/factory/chat_model.rs@@ -141,12 +141,7 @@ impl OpenHumanModelFactory<'_> {{parsed_route = Some(ProviderRoute {provider: CLAUDE_AGENT_SDK_PROVIDER.to_owned(),- model: self- .config- .claude_agent_sdk- .default_model- .clone()- .unwrap_or_default(),+ model: self.config.claude_agent_sdk.default_model.clone(),temperature: None,});}@@ -194,14 +189,16 @@ impl OpenHumanModelFactory<'_> {.parent().map(std::path::Path::to_path_buf).unwrap_or_else(|| self.config.workspace_dir.clone());- let context = tinyagents_harness::host::SubprocessProviderContext {+ let context = tinyagents_harness::host::model_factory::SubprocessProviderContext {workspace_dir: workspace,action_dir: self.config.action_dir.clone(),claude_agent_sdk: (&self.config.claude_agent_sdk).into(),mcp_provider: Some(Arc::new(OpenHumanMcpEndpoint)),};- let model = tinyagents_harness::host::build_claude_subprocess_model(route, &context)?- .ok_or_else(|| anyhow::anyhow!("unsupported subprocess route"))?;+ let model = tinyagents_harness::host::model_factory::build_claude_subprocess_model(+ route, &context,+ )?+ .ok_or_else(|| anyhow::anyhow!("unsupported subprocess route"))?;let route_provider = route.provider.clone();let resolved_model = effective_model.to_owned();let route = ResolvedModelRoute::new(@@ -326,20 +323,21 @@ fn build_one_shot(}impl ModelBuildGate for OpenHumanModelFactory<'_> {- fn check(&self, request: &ModelBuildRequest) -> anyhow::Result<()> {+ fn check(&self, request: &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)?;+ enforce_local_only_inference(&request.role, &provider)+ .map_err(|error| tinyagents_harness::TinyAgentsError::Model(error.to_string()))?;crate::inference::provider::factory::access_gates::verify_provider_session_in(self.ctx,self.config,&provider,- )?;- Ok(())+ )+ .map_err(|error| tinyagents_harness::TinyAgentsError::Model(error.to_string()))}}@@ -347,8 +345,10 @@ impl ModelFactory<()> for OpenHumanModelFactory<'_> {fn build(&self,request: &ModelBuildRequest,- ) -> anyhow::Result<(Arc<dyn ChatModel<()>>, ResolvedModelRoute)> {- let (model, route) = self.build_request(request)?;+ ) -> tinyagents_harness::Result<(Arc<dyn ChatModel<()>>, ResolvedModelRoute)> {+ let (model, route) = self+ .build_request(request)+ .map_err(|error| tinyagents_harness::TinyAgentsError::Model(error.to_string()))?;let opts = ModelRequestDefaults {model: (!route.model.is_empty()).then(|| route.model.clone()),temperature: request.opts.temperature,diff --git a/crates/openhuman-core/src/inference/turn_models.rs b/crates/openhuman-core/src/inference/turn_models.rsindex 2fcb4c4aea..ea5b35c584 100644--- a/crates/openhuman-core/src/inference/turn_models.rs+++ b/crates/openhuman-core/src/inference/turn_models.rs@@ -6,7 +6,6 @@ use std::sync::Arc;use crate::core::runtime::DispatchCtx;use tinyinference_llm::model::ProfileOverrideModel;-use tinyinference_llm::model::{ResolvedModelRoute, RouteRecordingModel};/// The per-turn crate [`ChatModel`](tinyinference_llm::model::ChatModel) set,/// assembled by TinyAgents' `TurnModelSet` for one turn.@@ -500,71 +499,74 @@ impl TurnModelSource {});// Tool/vision gating keeps its historical provider-name rule; only// the wall-clock ceilings use endpoint-aware self-hosted detection.- let (provider_id, native_tools, supports_vision, is_local, self_hosted, context_window) =- if let Some(profile) = injected_profile {- let provider_id = profile- .provider- .as_deref()- .unwrap_or("injected")- .to_string();- (- provider_id.clone(),- profile.tool_calling,- profile.modalities.image_in,- crate::agent::tinyagents::turn_policy::provider_is_self_hosted(- &provider_id,- None,- ),- crate::agent::tinyagents::turn_policy::provider_is_self_hosted(- &provider_id,- None,- ),- context_window.or(profile.max_input_tokens),- )- } else if host_injected.is_some() {- // A host-injected model owns the provider choice even when- // it does not publish a profile. Keep capability claims- // conservative and retain only the caller's window.- (- "injected".to_string(),- false,- false,- false,- false,- context_window,- )+ let (+ provider_id,+ native_tools,+ supports_vision,+ _is_local,+ self_hosted,+ context_window,+ ) = if let Some(profile) = injected_profile {+ let provider_id = profile+ .provider+ .as_deref()+ .unwrap_or("injected")+ .to_string();+ (+ provider_id.clone(),+ profile.tool_calling,+ profile.modalities.image_in,+ crate::agent::tinyagents::turn_policy::provider_is_self_hosted(+ &provider_id,+ None,+ ),+ crate::agent::tinyagents::turn_policy::provider_is_self_hosted(+ &provider_id,+ None,+ ),+ context_window.or(profile.max_input_tokens),+ )+ } else if host_injected.is_some() {+ // A host-injected model owns the provider choice even when+ // it does not publish a profile. Keep capability claims+ // conservative and retain only the caller's window.+ (+ "injected".to_string(),+ false,+ false,+ false,+ false,+ context_window,+ )+ } else {+ let is_local =+ tinyinference_local::profile::is_local_provider_string(&provider_string);+ let self_hosted = crate::agent::tinyagents::turn_policy::provider_is_self_hosted(+ &provider_string,+ crate::agent::tinyagents::turn_policy::local_openai_endpoint(&cn.config)+ .as_deref(),+ );+ let provider_id = if provider_string == "openhuman"+ || provider_string.is_empty()+ || provider_string == "cloud"+ {+ "managed".to_string()} else {- let is_local =- tinyinference_local::profile::is_local_provider_string(&provider_string);- let self_hosted =- crate::agent::tinyagents::turn_policy::provider_is_self_hosted(- &provider_string,- crate::agent::tinyagents::turn_policy::local_openai_endpoint(- &cn.config,- )- .as_deref(),- );- let provider_id = if provider_string == "openhuman"- || provider_string.is_empty()- || provider_string == "cloud"- {- "managed".to_string()- } else {- provider_string- .split(':')- .next()- .unwrap_or(&provider_string)- .to_string()- };- (- provider_id,- !is_local,- !is_local,- is_local,- self_hosted,- context_window,- )+ provider_string+ .split(':')+ .next()+ .unwrap_or(&provider_string)+ .to_string()};+ (+ provider_id,+ !is_local,+ !is_local,+ is_local,+ self_hosted,+ context_window,+ )+ };return build_turn_models_crate(&ctx,&cn.role,@@ -648,13 +650,13 @@ impl TurnModelSource {.profile().and_then(|profile| profile.provider.as_deref()).unwrap_or("unknown");- Ok(crate::attachments::provider::wrap(+ return Ok(crate::attachments::provider::wrap(&ctx,model,cn.config.clone(),&route.model,provider,- ))+ ));}Err(anyhow::anyhow!("turn model source is missing a model"))}