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(session_host): unify session model resolution logic
Steven Enamakel5b6b5cec292d
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rsindex 77ac3d79d7..c84c1744fd 100644--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs@@ -227,86 +227,14 @@ impl OpenHumanSessionHost {crate::tools::filter_tools_by_user_preference(&mut tools, &enabled_tools);}- // Route the main agent's chat through the unified per-workload- // factory so the user's "Reasoning" routing in the AI settings- // panel (e.g. `reasoning_provider = "anthropic:claude-..."`)- // actually takes effect. The factory returns a (Provider, model)- // tuple — the resolved model wins over the legacy `default_model`- // fallback so explicit picks like `anthropic:claude-sonnet-4-5`- // actually use claude-sonnet-4-5 end to end (sending the abstract- // "hint:reasoning" tier name to Anthropic would 404).- //- // When `reasoning_provider` is unset or `"cloud"`, the factory- // resolves to the primary cloud (OpenHuman by default), so the- // baseline behaviour is identical to the legacy- // `create_intelligent_routing_provider` path.- //- // The ReliableProvider retry/backoff + model-fallback wrapper is- // re-layered on top of the factory's resolved backend below (issue- // #4249, 1c). `model_routes` translation and intelligent local/cloud- // task hinting now live in the unified routing layer (router.rs) rather- // than a per-session wrapper, so they are not re-wrapped here.- // The Master OpenHumanSessionHost's definition selects the coding workload so the- // default user-facing turn has a model suitable for the direct- // inspect → edit → verify loop. Legacy/no-definition callers retain- // the configured chat default. Other specialised roles still select- // their model in the sub-agent runner.- // Only the explicit `hint:<role>` form routes to a specialised- // workload — legacy tier literals like `hint:reasoning` (which the- // bootstrap historically pinned as `default_model` for everyone)- // fall through to `chat`. This preserves `config.chat_provider` for- // legacy callers. A built-in Master OpenHumanSessionHost has an explicit- // `hint:coding`, while existing pre-registry callers continue using- // `config.default_model` unchanged.- let provider_role =- provider_role_for_definition(config.default_model.as_deref(), target_def);- // Retry/backoff is now owned by the crate `RetryPolicy` at the harness- // model call (issue #4249, Phase 3a) — see `tinyagents::run_policy_for`.- // The turn path therefore no longer wraps the resolved provider in- // `ReliableProvider`; wrapping it here plus the crate retry would- // double-retry every transient error. Cross-route fallback is likewise- // the crate registry `FallbackPolicy`, so `config.reliability.*` no longer- // layers on the turn path (it still governs the non-seam provider paths).- let (mut model_name, supports_native) = match &turn_model_source {- Some((source, model_name)) => {- (model_name.clone(), source.supports_native_tool_calling())- }- None => {- let (resolved_chat_model, model_name) =- crate::inference::provider::create_chat_model_with_model_id_in(- ctx,- provider_role,- config,- config.default_temperature,- )?;- let supports_native = resolved_chat_model- .profile()- .is_none_or(|profile| profile.tool_calling);- (model_name, supports_native)- }- };- log::info!(- "[session-builder] agent_id={} provider_role={} resolved_model={} supports_native_tools={}",- agent_id,- provider_role,- model_name,- supports_native- );- let target_agent_id = target_def- .map(|def| def.id.as_str())- .unwrap_or("orchestrator");- let target_is_lead = target_def- .map(|def| !def.subagents.is_empty())- .unwrap_or(true);- if let Some(pinned_model) = config.configured_agent_model(target_agent_id, target_is_lead) {- log::debug!(- "[session-builder] agent_id={} using config-level model pin model={}",- target_agent_id,- pinned_model- );- model_name = pinned_model.to_string();- }-+ let (provider_role, model_name, supports_native) =+ super::factory_resolution::resolve_session_model(+ ctx,+ config,+ agent_id,+ target_def,+ turn_model_source.as_ref(),+ )?;// Resolve the user-configured vision flag for the (now-final) model while// the full `Config` / `model_registry` is in scope — the turn engine only// sees `MultimodalConfig`. Stored on the session and surfaced to the imagediff --git a/crates/openhuman-core/src/agent/session_host/builder/factory_resolution.rs b/crates/openhuman-core/src/agent/session_host/builder/factory_resolution.rsindex 16d479f83e..5fd8fcee43 100644--- a/crates/openhuman-core/src/agent/session_host/builder/factory_resolution.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/factory_resolution.rs@@ -44,3 +44,59 @@ pub(crate) fn provider_role_for_definition(#[cfg(test)]#[path = "factory_resolution_tests.rs"]mod tests;++/// Resolve the model source, workload role, and native-tool capability for a session.+///+/// Session construction and triage direct turns share the same resolved source when one+/// is already available; otherwise the ordinary provider factory owns construction.+pub(crate) fn resolve_session_model(+ ctx: &crate::core::runtime::DispatchCtx,+ config: &crate::config::Config,+ agent_id: &str,+ target_def: Option<&crate::agent_registry::host_definition::AgentDefinition>,+ turn_model_source: Option<&(crate::agent::tinyagents::TurnModelSource, String)>,+) -> anyhow::Result<(&'static str, String, bool)> {+ // The Master OpenHumanSessionHost definition selects the coding workload so the default+ // user-facing turn has a model suitable for the direct inspect → edit → verify loop.+ // Legacy/no-definition callers retain the configured chat default.+ let provider_role = provider_role_for_definition(config.default_model.as_deref(), target_def);+ // Retry/backoff is owned by the crate RetryPolicy at the harness model call. The turn path+ // must not wrap the provider again or it will double-retry. Cross-route fallback likewise+ // belongs to the crate registry FallbackPolicy.+ let (mut model_name, supports_native) = match turn_model_source {+ Some((source, model_name)) => (model_name.clone(), source.supports_native_tool_calling()),+ None => {+ let (model, model_name) =+ crate::inference::provider::create_chat_model_with_model_id_in(+ ctx,+ provider_role,+ config,+ config.default_temperature,+ )?;+ let supports_native = model.profile().is_none_or(|profile| profile.tool_calling);+ (model_name, supports_native)+ }+ };+ log::info!(+ "[session-builder] agent_id={} provider_role={} resolved_model={} supports_native_tools={}",+ agent_id,+ provider_role,+ model_name,+ supports_native+ );+ let target_agent_id = target_def+ .map(|def| def.id.as_str())+ .unwrap_or("orchestrator");+ let target_is_lead = target_def+ .map(|def| !def.subagents.is_empty())+ .unwrap_or(true);+ if let Some(pinned_model) = config.configured_agent_model(target_agent_id, target_is_lead) {+ log::debug!(+ "[session-builder] agent_id={} using config-level model pin model={}",+ target_agent_id,+ pinned_model+ );+ model_name = pinned_model.to_string();+ }+ Ok((provider_role, model_name, supports_native))+}