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
feat(inference): add provider factory modules for access gates and backends
Steven Enamakel1a3d5013089f
diff --git a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs b/crates/openhuman-core/src/inference/provider/factory/access_gates.rsindex f35d038ffb..605fd9319c 100644--- a/crates/openhuman-core/src/inference/provider/factory/access_gates.rs+++ b/crates/openhuman-core/src/inference/provider/factory/access_gates.rs@@ -92,7 +92,7 @@ pub(super) fn enforce_local_only_inference(role: &str, provider: &str) -> anyhow/// this is called). Local runtimes are marked non-external, so/// [`emit_external_transfer`](crate::security::egress::emit_external_transfer)/// discloses them without firing the external-transfer event.-pub(super) fn emit_inference_egress(role: &str, provider: &str) {+pub(super) fn emit_inference_egress(role: &str, provider: &str, egress: &EgressLedger) {let p = provider.trim();if p.is_empty() || p == "cloud" {// Defensive: a sentinel would re-resolve on recursion; don't emit here.@@ -116,7 +116,8 @@ pub(super) fn emit_inference_egress(role: &str, provider: &str) {} else {model};- crate::security::egress::emit_external_transfer(+ crate::security::egress::emit_external_transfer_in(+ egress,crate::security::egress::EgressDescriptor::inference(slug, service, !is_local),);}diff --git a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rsindex 20c4695ad6..6c51247ea1 100644--- a/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs+++ b/crates/openhuman-core/src/inference/provider/factory/cloud_slug.rs@@ -209,14 +209,16 @@ pub(super) fn resolve_cloud_slug<'a>(pub(super) fn try_create_cloud_slug_chat_model(role: &str,config: &Config,+ egress: &EgressLedger,) -> OptionalChatModelResult {- try_create_cloud_slug_chat_model_with_native_tools(role, config, true)+ try_create_cloud_slug_chat_model_with_native_tools(role, config, true, egress)}pub(super) fn try_create_cloud_slug_chat_model_with_native_tools(role: &str,config: &Config,native_tool_calling: bool,+ egress: &EgressLedger,) -> OptionalChatModelResult {// Resolve the role's provider string, expanding the empty / "cloud" sentinel// to the primary cloud target.@@ -229,6 +231,7 @@ pub(super) fn try_create_cloud_slug_chat_model_with_native_tools(&resolved,config,native_tool_calling,+ egress,)}@@ -236,8 +239,11 @@ pub(super) fn try_create_cloud_slug_chat_model_from_string(role: &str,provider: &str,config: &Config,+ egress: &EgressLedger,) -> OptionalChatModelResult {- try_create_cloud_slug_chat_model_from_string_with_native_tools(role, provider, config, true)+ try_create_cloud_slug_chat_model_from_string_with_native_tools(+ role, provider, config, true, egress,+ )}pub(super) fn try_create_cloud_slug_chat_model_from_string_with_native_tools(@@ -245,6 +251,7 @@ pub(super) fn try_create_cloud_slug_chat_model_from_string_with_native_tools(provider: &str,config: &Config,native_tool_calling: bool,+ egress: &EgressLedger,) -> OptionalChatModelResult {let p = provider.trim().to_string();@@ -332,7 +339,12 @@ pub(super) fn try_create_cloud_slug_chat_model_from_string_with_native_tools(let model_override =(!effective_model.trim().is_empty()).then_some(effective_model.as_str());let (backend, pinned_model) =- match resolve_managed_backend_with_model_override(role, config, model_override) {+ match resolve_managed_backend_with_model_override(+ role,+ config,+ model_override,+ egress,+ ) {Ok(result) => result,Err(error) => return Some(Err(error)),};@@ -370,7 +382,8 @@ pub(super) fn try_create_cloud_slug_chat_model_from_string_with_native_tools(// — past the managed/bespoke returns and the access// gates, so this constructs. Disclose as external. Single cloud chokepoint// for every cloud ChatModel/turn entry.- crate::security::egress::emit_external_transfer(+ crate::security::egress::emit_external_transfer_in(+ egress,crate::security::egress::EgressDescriptor::inference(&slug, &effective_model, true),);diff --git a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rsindex 0414b4106a..3aef45d5ac 100644--- a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs+++ b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs@@ -27,15 +27,17 @@ pub(super) type OptionalChatModelResult = Option<anyhow::Result<ResolvedChatModepub(super) fn try_create_local_runtime_chat_model(role: &str,config: &Config,+ egress: &EgressLedger,) -> OptionalChatModelResult {let resolved = provider_for_role(role, config);- try_create_local_runtime_chat_model_from_string(role, &resolved, config)+ try_create_local_runtime_chat_model_from_string(role, &resolved, config, egress)}pub(super) fn try_create_local_runtime_chat_model_from_string(role: &str,provider: &str,config: &Config,+ egress: &EgressLedger,) -> OptionalChatModelResult {use tinyinference_local::local_runtime::{resolve_local_runtime, LocalRuntimeAuth, LocalRuntimeInputs,@@ -65,7 +67,7 @@ pub(super) fn try_create_local_runtime_chat_model_from_string(// NON-external — local inference never leaves the device, so// `emit_external_transfer` records it without firing a pending event. This// is the single local chokepoint for every ChatModel/turn entry.- emit_inference_egress(role, &p);+ emit_inference_egress(role, &p, egress);// Endpoint, auth, model and `@temp` resolution is the module's pure// `resolve_local_runtime`; the host only supplies config + env.@@ -111,6 +113,6 @@ pub(crate) fn create_local_chat_model_from_string(provider: &str,config: &Config,) -> anyhow::Result<(Arc<dyn ChatModel<()>>, String)> {- try_create_local_runtime_chat_model_from_string("chat", provider, config)+ try_create_local_runtime_chat_model_from_string("chat", provider, config, &EgressLedger::none()).ok_or_else(|| anyhow::anyhow!("unsupported local provider string '{provider}'"))?}diff --git a/crates/openhuman-core/src/inference/provider/factory/managed_backend.rs b/crates/openhuman-core/src/inference/provider/factory/managed_backend.rsindex 352aea1879..7e2b315aa9 100644--- a/crates/openhuman-core/src/inference/provider/factory/managed_backend.rs+++ b/crates/openhuman-core/src/inference/provider/factory/managed_backend.rs@@ -11,8 +11,9 @@ use super::*;pub(super) fn resolve_managed_backend(role: &str,config: &Config,+ egress: &EgressLedger,) -> anyhow::Result<(OpenHumanBackendModel, String)> {- resolve_managed_backend_with_model_override(role, config, None)+ resolve_managed_backend_with_model_override(role, config, None, egress)}/// Construct a managed turn model with the explicit OpenHuman thread attached.@@ -23,6 +24,7 @@ pub(crate) fn make_openhuman_backend_model_for_thread(model: &str,native_tool_calling: bool,thread_id: Option<&str>,+ egress: &EgressLedger,) -> anyhow::Result<(std::sync::Arc<dyn tinyinference_llm::model::ChatModel<()>>,String,@@ -30,7 +32,7 @@ pub(crate) fn make_openhuman_backend_model_for_thread(// `model` may be a role alias (`hint:reasoning`) the registry keys the// route by; the backend only ever sees the concrete id it resolves to.let (backend, resolved_model) =- resolve_managed_backend_with_model_override(role, config, Some(model))?;+ resolve_managed_backend_with_model_override(role, config, Some(model), egress)?;Ok((std::sync::Arc::new(backend@@ -45,6 +47,7 @@ pub(super) fn resolve_managed_backend_with_model_override(role: &str,config: &Config,model_override: Option<&str>,+ egress: &EgressLedger,) -> anyhow::Result<(OpenHumanBackendModel, String)> {// Managed construction shares the same privacy gate as local and BYOK// factories, before constructing a client or announcing any egress.@@ -112,7 +115,8 @@ pub(super) fn resolve_managed_backend_with_model_override(// (`create_turn_chat_model[_from_string]_with_native_tools`) resolve here.// Emitting once here guarantees the default managed chat turn discloses// egress exactly once (see `emit_inference_egress`).- crate::security::egress::emit_external_transfer(+ crate::security::egress::emit_external_transfer_in(+ egress,crate::security::egress::EgressDescriptor::inference("openhuman", &model, true),);Ok((@@ -133,7 +137,7 @@ pub(crate) fn make_openhuman_backend_model(std::sync::Arc<dyn tinyinference_llm::model::ChatModel<()>>,String,)> {- let (model_client, model) = resolve_managed_backend(role, config)?;+ let (model_client, model) = resolve_managed_backend(role, config, &EgressLedger::none())?;let chat: std::sync::Arc<dyn tinyinference_llm::model::ChatModel<()>> =std::sync::Arc::new(model_client);Ok((chat, model))diff --git a/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs b/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rsindex 314bacd81e..e1b6581ef4 100644--- a/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs+++ b/crates/openhuman-core/src/inference/provider/factory/subprocess_providers.rs@@ -9,21 +9,23 @@ use crate::inference::provider::factory::access_gates::verify_provider_session;pub(super) fn try_create_claude_agent_sdk_chat_model(role: &str,config: &Config,+ egress: &EgressLedger,) -> OptionalChatModelResult {let resolved = provider_for_role(role, config);- try_create_claude_agent_sdk_chat_model_from_string(role, &resolved, config)+ try_create_claude_agent_sdk_chat_model_from_string(role, &resolved, config, egress)}pub(super) fn try_create_claude_agent_sdk_chat_model_from_string(role: &str,provider: &str,config: &Config,+ egress: &EgressLedger,) -> OptionalChatModelResult {let model = match prepare_claude_agent_sdk_chat_model(role, provider, config)? {Ok(model) => model,Err(error) => return Some(Err(error)),};- emit_inference_egress(role, &format!("{CLAUDE_AGENT_SDK_PREFIX}{model}"));+ emit_inference_egress(role, &format!("{CLAUDE_AGENT_SDK_PREFIX}{model}"), egress);let chat: Arc<dyn ChatModel<()>> = Arc::new(ClaudeAgentSdkProvider::for_model((&config.claude_agent_sdk).into(),model.clone(),@@ -64,9 +66,10 @@ pub(super) fn try_create_claude_code_chat_model(role: &str,config: &Config,model_override: Option<&str>,+ egress: &EgressLedger,) -> OptionalChatModelResult {let resolved = provider_for_role(role, config);- try_create_claude_code_chat_model_from_string(role, &resolved, config, model_override)+ try_create_claude_code_chat_model_from_string(role, &resolved, config, model_override, egress)}pub(super) fn try_create_claude_code_chat_model_from_string(@@ -74,6 +77,7 @@ pub(super) fn try_create_claude_code_chat_model_from_string(provider: &str,config: &Config,model_override: Option<&str>,+ egress: &EgressLedger,) -> OptionalChatModelResult {let provider = provider.trim();let model_with_temp =@@ -111,6 +115,7 @@ pub(super) fn try_create_claude_code_chat_model_from_string("{}{effective_model}",tinyagents_harness::providers::claude_code::PROVIDER_PREFIX),+ egress,);let chat = match tinyagents_harness::providers::claude_code::ClaudeCodeProvider::from_env(effective_model,