Skip to content

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

feat(agent): route host agent turns through session host

Steven Enamakelca30f6a7811f
diff --git a/crates/openhuman-core/src/agent/host_agents.rs b/crates/openhuman-core/src/agent/host_agents.rs
index d2d1126006..a64dbc2494 100644
--- a/crates/openhuman-core/src/agent/host_agents.rs
+++ b/crates/openhuman-core/src/agent/host_agents.rs
@@ -70,7 +70,11 @@ impl HostAgent {
"[host_agents] building session for host agent"
);
let mut session = CoreContext::sync_scope(Arc::clone(&self.context), || {
- if crate::profiles::capabilities::ProfileCapabilities::current().is_some() {
+ if crate::profiles::capabilities::ProfileCapabilities::in_ctx(&DispatchCtx::new(Arc::clone(
+ &self.context,
+ )))
+ .is_some()
+ {
return OpenHumanSessionHost::from_config_host_only(
config,
&self.definition,
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
index 2425c416ef..0d51011f41 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
@@ -80,7 +80,8 @@ impl OpenHumanSessionHost {
// A hosted profile never receives the ordinary config-derived belt.
// Its operator-selected factory carries registration and permission
// boundaries into the same session builder, under this profile scope.
- if crate::profiles::capabilities::ProfileCapabilities::current().is_some() {
+ if crate::profiles::capabilities::ProfileCapabilities::in_ctx(&DispatchCtx::ambient()).is_some()
+ {
return Self::from_config_for_agent_session(config, agent_id, None);
}
let target_def = resolve_target_definition(config, agent_id)?;
diff --git a/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs b/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs
index bea853740f..ae1f302a32 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs
@@ -15,7 +15,9 @@ impl OpenHumanSessionHost {
agent_id: &str,
session_id: Option<&str>,
) -> anyhow::Result<Self> {
- if let Some(capabilities) = crate::profiles::capabilities::ProfileCapabilities::current() {
+ if let Some(capabilities) =
+ crate::profiles::capabilities::ProfileCapabilities::in_ctx(&DispatchCtx::ambient())
+ {
let mut definition = super::factory::resolve_target_definition(config, agent_id)?
.ok_or_else(|| anyhow::anyhow!("profile agent definition is unavailable"))?;
capabilities.apply_system_prompt(&mut definition);
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs
index bb01d0800d..afa4eb3310 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs
@@ -24,6 +24,7 @@ use crate::channels::{ChannelSendExt, SendMessage};
use crate::config::Config;
use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
+use crate::core::runtime::DispatchCtx;
use tinychannels_bus as traits;
pub(crate) mod posture;
@@ -53,9 +54,12 @@ pub(crate) fn bound_agent_id<'a>(config: &'a Config, channel: &str) -> Option<&'
/// Resolve `channel`'s binding against the installed host agents.
pub(crate) fn route(ctx: &ChannelRuntimeContext, channel: &str) -> HostRoute {
- if let Some(capabilities) = crate::profiles::capabilities::ProfileCapabilities::current() {
+ // Transitional (#7801): the channel runtime context carries no core yet.
+ let dispatch = DispatchCtx::ambient();
+ if let Some(capabilities) = crate::profiles::capabilities::ProfileCapabilities::in_ctx(&dispatch)
+ {
if let (Some(context), Some(config), Some(definitions)) = (
- crate::core::runtime::CoreContext::scoped(),
+ dispatch.core().cloned(),
ctx.config.as_ref(),
crate::agent::harness::host_definition::AgentDefinitionRegistry::current(),
) {
diff --git a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
index 44a1ef12fd..a91dac2714 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
@@ -141,7 +141,7 @@ pub(crate) fn build_channel_turn_parts(
config.workspace_dir.clone(),
)?;
let workspace = config.workspace_dir.clone();
- let capabilities = crate::profiles::capabilities::ProfileCapabilities::current();
+ let capabilities = crate::profiles::capabilities::ProfileCapabilities::in_ctx(&DispatchCtx::ambient());
let tools_registry = Arc::new(if capabilities.is_some() {
// The profile host route builds the selected belt once with the exact
// durable thread. No second, unnamed factory invocation is needed here.
diff --git a/crates/openhuman-core/src/memory/engine.rs b/crates/openhuman-core/src/memory/engine.rs
index f1f30fe706..03cd5a2a6b 100644
--- a/crates/openhuman-core/src/memory/engine.rs
+++ b/crates/openhuman-core/src/memory/engine.rs
@@ -209,10 +209,10 @@ pub fn resolve(config: &Config) -> Binding {
tracing::debug!("[memory:engine] components.memory is off; engine not bound");
return off(None, None, COMPONENT_OFF_REASON);
}
- if let Some(capabilities) = crate::profiles::capabilities::ProfileCapabilities::current() {
+ // The hosted profile's engine is bound for the calling task's own tenant.
+ let ctx = crate::core::runtime::DispatchCtx::ambient();
+ if let Some(capabilities) = crate::profiles::capabilities::ProfileCapabilities::in_ctx(&ctx) {
if let Some(engine) = &capabilities.memory_engine {
- // The hosted profile's engine is bound for the calling task's own tenant.
- let ctx = crate::core::runtime::DispatchCtx::ambient();
if let Err(reason) = crate::profiles::host::ensure_hosted(&ctx) {
return off(None, None, &reason);
}
diff --git a/crates/openhuman-core/src/profiles/tools.rs b/crates/openhuman-core/src/profiles/tools.rs
index d4a8c795ba..6798446940 100644
--- a/crates/openhuman-core/src/profiles/tools.rs
+++ b/crates/openhuman-core/src/profiles/tools.rs
@@ -27,7 +27,7 @@
use std::path::Path;
-use crate::core::runtime::is_saas;
+use crate::core::runtime::{is_saas, DispatchCtx};
use crate::core::runtime::saas::SaasSandboxConfig;
use crate::sandbox::{DockerOverrides, SandboxBackendKind, SandboxPolicy};