Skip to content

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

refactor(config): improve model resolution logic

Steven Enamakel517c9c8637d1
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs
index 15106c3b4c..f9d15c2677 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs
@@ -302,7 +302,17 @@ impl SessionHostBuilder {
let model_name = self
.model_name
- .unwrap_or_else(|| crate::config::DEFAULT_MODEL.into());
+ .or_else(|| {
+ self.runtime_config
+ .as_ref()
+ .and_then(|config| config.default_model.clone())
+ })
+ .or_else(|| {
+ crate::inference::registry::provider_default_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ )
+ })
+ .ok_or_else(|| anyhow::anyhow!("model_name or configured provider default is required"))?;
let context_config = self.context_config.unwrap_or_default();
diff --git a/crates/openhuman-core/src/agent/tinyagents/config.rs b/crates/openhuman-core/src/agent/tinyagents/config.rs
index bf1d330f42..b3f3daae70 100644
--- a/crates/openhuman-core/src/agent/tinyagents/config.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/config.rs
@@ -20,7 +20,7 @@ use tinyagents_harness::config::{
};
use crate::config::{
- AgentConfig, Config, DelegateAgentConfig, RequiredOutputContract, DEFAULT_MODEL,
+ AgentConfig, Config, DelegateAgentConfig, RequiredOutputContract,
};
/// Translates OpenHuman's free-form `agent.tool_dispatcher` string into the
@@ -58,19 +58,25 @@ fn dispatcher_from(raw: &str) -> ToolDispatcher {
/// left at `0` (delegation disabled) because depth is a per-delegate setting;
/// see [`apply_delegate`]. A caller that wants the plain single-agent case gets
/// exactly that, with no delegation implied by accident.
-pub fn session_config_from(config: &Config) -> SessionConfig {
+pub fn session_config_from(config: &Config) -> anyhow::Result<SessionConfig> {
+ let model = config
+ .default_model
+ .clone()
+ .or_else(|| {
+ crate::inference::registry::provider_default_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ )
+ })
+ .ok_or_else(|| anyhow::anyhow!("a model must be selected before building a session"))?;
let mut session = SessionConfig::new(
config.workspace_dir.clone(),
config.action_dir.clone(),
- config
- .default_model
- .clone()
- .unwrap_or_else(|| DEFAULT_MODEL.to_string()),
+ model,
);
session.temperature = Some(config.default_temperature);
apply_agent_config(&mut session, &config.agent);
- session
+ Ok(session)
}
/// Overlays one [`AgentConfig`] onto `session`, replacing its turn, tool, and
diff --git a/crates/openhuman-core/src/config/ops/primary_cloud.rs b/crates/openhuman-core/src/config/ops/primary_cloud.rs
index b6fa6fa299..eb46884c6b 100644
--- a/crates/openhuman-core/src/config/ops/primary_cloud.rs
+++ b/crates/openhuman-core/src/config/ops/primary_cloud.rs
@@ -139,14 +139,13 @@ fn cloud_entry_provider_string(entry: &CloudProviderCreds, config: &Config) -> S
.map(str::trim)
.filter(|model| !model.is_empty())
})
- .unwrap_or(crate::config::DEFAULT_MODEL);
+ .unwrap_or("");
format!("{}:{model}", entry.slug)
}
fn is_openhuman_cloud_entry(config: &Config, entry: &CloudProviderCreds) -> bool {
- entry.slug == PROVIDER_OPENHUMAN
- || crate::config::schema::cloud_providers::is_hosted_auth_style(entry.auth_style)
+ crate::config::schema::cloud_providers::is_hosted_auth_style(entry.auth_style)
|| looks_like_openhuman_backend(config, &entry.endpoint)
}
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run.rs b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
index 05870b1842..43d8d43b04 100644
--- a/crates/openhuman-core/src/cron/scheduler/agent_run.rs
+++ b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
@@ -87,10 +87,11 @@ pub(super) async fn run_agent_job_for_run(
// on. Inherit / Exact keep their literal `resolve()`
// behaviour because neither relies on the `-v1` trick.
use tinyagents_definition::ModelSpec;
- let fallback_model = effective
- .default_model
- .clone()
- .unwrap_or_else(|| crate::config::DEFAULT_MODEL.to_string());
+ let fallback_model = effective.default_model.clone().or_else(|| {
+ crate::inference::registry::provider_default_model(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ )
+ });
let resolved_model = match &def.model {
ModelSpec::Hint(workload) => {
// Resolve the workload's configured model id via the crate
@@ -129,9 +130,11 @@ pub(super) async fn run_agent_job_for_run(
}
}
ModelSpec::Inherit => fallback_model.clone(),
- ModelSpec::Exact(name) => name.clone(),
+ ModelSpec::Exact(name) => Some(name.clone()),
};
- effective.default_model = Some(resolved_model);
+ if let Some(model) = resolved_model {
+ effective.default_model = Some(model);
+ }
// Issue #4868 — the iteration cap is no longer set here. The
// session builder (`build_session_agent_inner`) resolves it
// from `def.effective_max_iterations()` directly, which (unlike