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(session_host): support turn model source in session host builder
Steven Enamakel73f24e960485
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rsindex 265b18bf92..904a541c45 100644--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs@@ -140,6 +140,22 @@ impl OpenHumanSessionHost {host_only: bool,host: Option<&super::HostTools>,session_id: Option<&str>,+ ) -> Result<Self> {+ Self::build_session_agent_inner_with_turn_model_source(+ ctx, config, agent_id, target_def, host_only, host, session_id, None,+ )+ }++ #[allow(clippy::too_many_arguments)]+ pub(crate) fn build_session_agent_inner_with_turn_model_source(+ ctx: &DispatchCtx,+ config: &Config,+ agent_id: &str,+ target_def: Option<&crate::agent_registry::host_definition::AgentDefinition>,+ host_only: bool,+ host: Option<&super::HostTools>,+ session_id: Option<&str>,+ turn_model_source: Option<(crate::agent::tinyagents::TurnModelSource, String)>,) -> Result<Self> {let workspace_descriptor: Option<tinytools::WorkspaceDescriptor> = None;@@ -251,16 +267,30 @@ impl OpenHumanSessionHost {// 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 (resolved_chat_model, mut 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);+ let (mut model_name, supports_native) = match &turn_model_source {+ Some((source, model_name)) => {+ let models = source.build(+ model_name,+ target_def.map_or(config.default_temperature, |definition| definition.temperature),+ None,+ None,+ )?;+ (model_name.clone(), models.native_tools())+ }+ 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,@@ -770,7 +800,6 @@ impl OpenHumanSessionHost {super::host_only::session_policy(host_only, &tools, merged_host_tools.policy);let withheld_tool_names = merged_host_tools.withheld;let mut builder = OpenHumanSessionHost::builder()- .crate_native_provider(ctx, provider_role, Arc::clone(&base_config)).tools(tools).synthesized_tools(delegation_tools).visible_tool_names(visible)@@ -792,6 +821,10 @@ impl OpenHumanSessionHost {.agent_definition_name(agent_id.to_string()).omit_memory_context(effective_omit_memory_context).tokenjuice_compression(effective_tokenjuice_compression);+ builder = match turn_model_source {+ Some((source, _)) => builder.turn_model_source(source),+ None => builder.crate_native_provider(ctx, provider_role, Arc::clone(&base_config)),+ };if let Some(ps) = payload_summarizer {builder = builder.payload_summarizer(ps);}diff --git a/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs b/crates/openhuman-core/src/agent/session_host/builder/host_tools.rsindex 583c1eb887..b508ee7a39 100644--- a/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs@@ -442,4 +442,23 @@ impl OpenHumanSessionHost {None,)}++ pub(crate) fn from_config_with_definition_and_turn_model_source(+ ctx: &crate::core::runtime::DispatchCtx,+ config: &Config,+ definition: &crate::agent_registry::host_definition::AgentDefinition,+ source: crate::agent::tinyagents::TurnModelSource,+ model: String,+ ) -> Result<Self> {+ OpenHumanSessionHost::build_session_agent_inner_with_turn_model_source(+ ctx,+ config,+ &definition.id,+ Some(definition),+ false,+ None,+ None,+ Some((source, model)),+ )+ }}diff --git a/crates/openhuman-core/src/agent/session_host/builder/setters.rs b/crates/openhuman-core/src/agent/session_host/builder/setters.rsindex 448e2cb9ef..f1ecef0693 100644--- a/crates/openhuman-core/src/agent/session_host/builder/setters.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/setters.rs@@ -89,6 +89,14 @@ impl SessionHostBuilder {self}+ pub(crate) fn turn_model_source(+ mut self,+ source: crate::agent::tinyagents::TurnModelSource,+ ) -> Self {+ self.turn_model_source = Some(source);+ self+ }+/// Sets the available tools for the agent.pub fn tools(mut self, tools: Vec<Box<dyn Tool>>) -> Self {self.tools = Some(tools);diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rsindex 67581ab99b..c2b2ea60af 100644--- a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs+++ b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs@@ -273,6 +273,7 @@ fn build_turn_agent(target: &AgentChatTarget<'_>,session_id: Option<&str>,temperature: Option<f64>,+ turn_model_source: Option<(crate::agent::tinyagents::TurnModelSource, String)>,) -> Result<OpenHumanSessionHost, String> {match target {AgentChatTarget::Orchestrator => OpenHumanSessionHost::from_config(ctx, config),@@ -293,7 +294,13 @@ fn build_turn_agent(definition, host, ..} => {let definition = definition_for_turn(definition, temperature);- match host {+ match (host, turn_model_source) {+ (None, Some((source, model))) => {+ OpenHumanSessionHost::from_config_with_definition_and_turn_model_source(+ ctx, config, &definition, source, model,+ )+ }+ (host, None) => match host {Some(host) => OpenHumanSessionHost::from_config_with_host_tools(ctx,config,@@ -302,6 +309,10 @@ fn build_turn_agent(session_id,),None => OpenHumanSessionHost::from_config_with_definition(ctx, config, &definition),+ },+ (Some(host), Some(_)) => Err(anyhow::anyhow!(+ "explicit turn model source cannot be combined with host tools"+ )),}}}@@ -336,6 +347,24 @@ pub fn agent_chat_for<'a>(cwd: Option<String>,route: Option<crate::config::schema::EphemeralRoute>,env: AgentChatEnv,+) -> futures::future::BoxFuture<'a, Result<Outcome<String>, String>> {+ agent_chat_for_with_turn_model_source(+ config, target, message, model_override, temperature, thread_id, cwd, route, env, None,+ )+}++#[allow(clippy::too_many_arguments)]+pub(crate) fn agent_chat_for_with_turn_model_source<'a>(+ config: &'a mut Config,+ target: AgentChatTarget<'a>,+ message: &'a str,+ model_override: Option<String>,+ temperature: Option<f64>,+ thread_id: Option<String>,+ cwd: Option<String>,+ route: Option<crate::config::schema::EphemeralRoute>,+ env: AgentChatEnv,+ turn_model_source: Option<(crate::agent::tinyagents::TurnModelSource, String)>,) -> futures::future::BoxFuture<'a, Result<Outcome<String>, String>> {Box::pin(agent_chat_for_inner(config,@@ -347,6 +376,7 @@ pub fn agent_chat_for<'a>(cwd,route,env,+ turn_model_source,))}@@ -361,8 +391,9 @@ async fn agent_chat_for_inner(cwd: Option<String>,route: Option<crate::config::schema::EphemeralRoute>,env: AgentChatEnv,+ turn_model_source: Option<(crate::agent::tinyagents::TurnModelSource, String)>,) -> Result<Outcome<String>, String> {- agent_chat_reply_for(+ agent_chat_reply_for_inner(config,target,message,@@ -372,6 +403,7 @@ async fn agent_chat_for_inner(cwd,route,env,+ turn_model_source,).await.map(AgentChatReply::into_outcome)@@ -390,6 +422,25 @@ pub async fn agent_chat_reply_for(cwd: Option<String>,route: Option<crate::config::schema::EphemeralRoute>,env: AgentChatEnv,+) -> Result<AgentChatReply, String> {+ agent_chat_reply_for_inner(+ config, target, message, model_override, temperature, thread_id, cwd, route, env, None,+ )+ .await+}++#[allow(clippy::too_many_arguments)]+async fn agent_chat_reply_for_inner(+ config: &mut Config,+ target: AgentChatTarget<'_>,+ message: &str,+ model_override: Option<String>,+ temperature: Option<f64>,+ thread_id: Option<String>,+ cwd: Option<String>,+ route: Option<crate::config::schema::EphemeralRoute>,+ env: AgentChatEnv,+ turn_model_source: Option<(crate::agent::tinyagents::TurnModelSource, String)>,) -> Result<AgentChatReply, String> {match target {AgentChatTarget::Definition {@@ -450,14 +501,14 @@ pub async fn agent_chat_reply_for(root.display());let mut agent =- build_turn_agent(&turn_ctx, &scoped, &target, turn_session_id, temperature)?;+ build_turn_agent(&turn_ctx, &scoped, &target, turn_session_id, temperature, turn_model_source.clone())?;// Also thread it as the turn's workspace descriptor so acting tools// that read `ToolExecutionContext::workspace` (shell) resolve their// default cwd here, and so spawned sub-agents inherit the same root.agent.set_workspace_descriptor(Some(tinytools::WorkspaceDescriptor::new(root.clone())));agent}- None => build_turn_agent(&turn_ctx, config, &target, turn_session_id, temperature)?,+ None => build_turn_agent(&turn_ctx, config, &target, turn_session_id, temperature, turn_model_source)?,};// Thread-correct resume. `OpenHumanSessionHost::turn` would otherwise auto-load the// newest transcript for the agent *name*, which is another thread's