Skip to content

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

feat(agent): route turns through per-session model selection

Steven Enamakel415d7bf75f4e
diff --git a/crates/openhuman-core/src/agent/session_host/builder/setters.rs b/crates/openhuman-core/src/agent/session_host/builder/setters.rs
index 4c683a0e8d..cd160d2972 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/setters.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/setters.rs
@@ -83,7 +83,9 @@ impl SessionHostBuilder {
config: Arc<crate::config::Config>,
) -> Self {
self.turn_model_source = Some(crate::agent::tinyagents::TurnModelSource::new_crate_native(
- role, config,
+ &crate::core::runtime::DispatchCtx::ambient(),
+ role,
+ config,
));
self
}
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/provider.rs b/crates/openhuman-core/src/agent/subagent_host/ops/provider.rs
index 87ef8e5f5e..8496c89f06 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/provider.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/provider.rs
@@ -38,7 +38,8 @@ pub(crate) fn resolve_subagent_source(
match spec {
ModelSpec::Hint(workload) => match config {
Some(config) => {
- match crate::inference::provider::create_chat_model_with_model_id(
+ match crate::inference::provider::create_chat_model_with_model_id_in(
+ &parent_source.dispatch_ctx(),
workload,
config,
temperature,
@@ -52,6 +53,7 @@ pub(crate) fn resolve_subagent_source(
);
(
crate::agent::tinyagents::TurnModelSource::new_crate_native(
+ &parent_source.dispatch_ctx(),
workload.clone(),
Arc::new(config.clone()),
),
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs b/crates/openhuman-core/src/agent/tinyagents/turn_models.rs
index f87c585aea..dfa0a73202 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_models.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_models.rs
@@ -413,6 +413,15 @@ impl CrateNativeSource {
}
impl TurnModelSource {
+ /// The context this source builds its models under: the one it was
+ /// constructed for, else the calling task's ambient one.
+ pub(crate) fn dispatch_ctx(&self) -> crate::core::runtime::DispatchCtx {
+ match &self.crate_native {
+ Some(source) => source.ctx(),
+ None => crate::core::runtime::DispatchCtx::ambient(),
+ }
+ }
+
/// Use an already-constructed TinyAgents model as the complete turn model
/// source. Intended for deterministic tests and embedding callers that do
/// not need role/config-based route construction.
diff --git a/crates/openhuman-core/src/agent/triage/routing.rs b/crates/openhuman-core/src/agent/triage/routing.rs
index c13267fec5..2646089737 100644
--- a/crates/openhuman-core/src/agent/triage/routing.rs
+++ b/crates/openhuman-core/src/agent/triage/routing.rs
@@ -94,6 +94,7 @@ pub fn build_local_provider_with_config(config: &Config) -> Option<ResolvedProvi
);
Some(ResolvedProvider {
turn_model_source: crate::agent::tinyagents::TurnModelSource::new_crate_native_from_string(
+ &crate::core::runtime::DispatchCtx::ambient(),
TRIAGE_ROLE,
provider_string,
Arc::new(config.clone()),
@@ -183,6 +184,7 @@ fn build_remote_provider(config: &Config) -> anyhow::Result<ResolvedProvider> {
Ok(ResolvedProvider {
turn_model_source:
crate::agent::tinyagents::TurnModelSource::new_crate_native_from_string(
+ &crate::core::runtime::DispatchCtx::ambient(),
TRIAGE_ROLE,
provider_string,
Arc::new(config.clone()),
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs
index 643802b4d6..eedf8ec15e 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs
@@ -59,6 +59,7 @@ pub(super) async fn dispatch_bus_turn(
// `config`) stay on an injected model source.
turn_model_source: match &ctx.config {
Some(cfg) => crate::agent::tinyagents::TurnModelSource::new_crate_native_from_string(
+ &crate::core::runtime::DispatchCtx::ambient(),
"chat",
route.provider.clone(),
cfg.clone(),