Skip to content

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

feat(agent): retain hosted authority on sessions

Steven Enamakel766e270d2c77
diff --git a/crates/openhuman-core/src/agent/harness/definition/registry.rs b/crates/openhuman-core/src/agent/harness/definition/registry.rs
index 806d0ddaf9..460f2e4258 100644
--- a/crates/openhuman-core/src/agent/harness/definition/registry.rs
+++ b/crates/openhuman-core/src/agent/harness/definition/registry.rs
@@ -4,7 +4,7 @@ use super::agent_definition::AgentDefinition;
use anyhow::Result;
use std::collections::HashMap;
use std::path::Path;
-use std::sync::OnceLock;
+use std::sync::{Arc, OnceLock};
/// In-memory registry of all known [`AgentDefinition`]s.
///
@@ -19,7 +19,7 @@ pub struct AgentDefinitionRegistry {
order: Vec<String>,
}
-static GLOBAL: OnceLock<AgentDefinitionRegistry> = OnceLock::new();
+static GLOBAL: OnceLock<Arc<AgentDefinitionRegistry>> = OnceLock::new();
impl AgentDefinitionRegistry {
/// Build a registry containing only the built-in definitions
@@ -115,7 +115,7 @@ impl AgentDefinitionRegistry {
/// custom definitions during development.
pub fn init_global(workspace: &Path) -> Result<()> {
let registry = Self::load(workspace)?;
- match GLOBAL.set(registry) {
+ match GLOBAL.set(Arc::new(registry)) {
Ok(()) => {
tracing::info!(
"[agent_defs] global registry initialised with {} definitions",
@@ -134,12 +134,21 @@ impl AgentDefinitionRegistry {
/// scan). Used by tests and by callers that don't have a workspace.
pub fn init_global_builtins() -> Result<()> {
let registry = Self::builtins_only();
- let _ = GLOBAL.set(registry);
+ let _ = GLOBAL.set(Arc::new(registry));
Ok(())
}
/// Borrow the global registry, if initialised.
pub fn global() -> Option<&'static Self> {
- GLOBAL.get()
+ GLOBAL.get().map(Arc::as_ref)
+ }
+
+ /// Clones the durable process registry for a host capability bundle.
+ ///
+ /// Hosted invocations need owned authority because their capability bundle
+ /// outlives the factory stack frame. This is the owned counterpart of
+ /// [`Self::global`], not a rebuilt or global lookup performed mid-turn.
+ pub fn global_arc() -> Option<Arc<Self>> {
+ GLOBAL.get().cloned()
}
}
diff --git a/crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs b/crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs
index 1713f80384..e57c15ca46 100644
--- a/crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs
+++ b/crates/openhuman-core/src/agent/harness/session/builder/builder_build.rs
@@ -326,6 +326,7 @@ impl AgentBuilder {
connected_integrations: Vec::new(),
connected_integrations_initialized: false,
runtime_config: None,
+ hosted_base: None,
definition: None,
// Default to `true` (omit) so legacy / custom agents built
// without a definition stay lean. Opt-in agents thread their
diff --git a/crates/openhuman-core/src/agent/harness/session/builder/factory.rs b/crates/openhuman-core/src/agent/harness/session/builder/factory.rs
index e4e2fc9770..0fd89b4191 100644
--- a/crates/openhuman-core/src/agent/harness/session/builder/factory.rs
+++ b/crates/openhuman-core/src/agent/harness/session/builder/factory.rs
@@ -1283,6 +1283,22 @@ impl Agent {
// second resident copy of a 95-field struct with nested `Vec`s
// (openhuman#6218).
agent.runtime_config = Some(Arc::clone(&base_config));
+ agent.hosted_base = AgentDefinitionRegistry::global_arc().map(|definitions| {
+ Arc::new(crate::agent::tinyagents::host::OpenHumanHostBase {
+ config: Arc::clone(&base_config),
+ definitions,
+ security_policy: security,
+ memory: agent.memory_arc(),
+ shared_experience_memory: agent.shared_experience_memory.clone(),
+ profile_id: agent.active_profile_id.clone(),
+ post_turn_hooks: agent.post_turn_hooks.clone(),
+ })
+ });
+ if agent.hosted_base.is_none() {
+ tracing::warn!(
+ "[tinyagents] hosted invocation base unavailable: agent definition registry was not initialized"
+ );
+ }
agent.definition = target_def.cloned().map(Arc::new);
agent.last_seen_integrations_hash =
crate::integrations::composio::connected_set_hash(&agent.connected_integrations);
diff --git a/crates/openhuman-core/src/agent/harness/session/turn/core/harness_turn.rs b/crates/openhuman-core/src/agent/harness/session/turn/core/harness_turn.rs
index fca0a604e8..1234e72602 100644
--- a/crates/openhuman-core/src/agent/harness/session/turn/core/harness_turn.rs
+++ b/crates/openhuman-core/src/agent/harness/session/turn/core/harness_turn.rs
@@ -195,6 +195,7 @@ impl Agent {
.unwrap_or(crate::agent::harness::definition::SandboxMode::None),
thread_id: self.thread_id.clone(),
run_context: run_context.clone(),
+ hosted_base: self.hosted_base.clone(),
})
.await?;
let subagent_usage_entries = run_context.subagent_usage_entries();
diff --git a/crates/openhuman-core/src/agent/harness/session/turn/graph.rs b/crates/openhuman-core/src/agent/harness/session/turn/graph.rs
index e57e4eb050..f8f189b429 100644
--- a/crates/openhuman-core/src/agent/harness/session/turn/graph.rs
+++ b/crates/openhuman-core/src/agent/harness/session/turn/graph.rs
@@ -95,6 +95,8 @@ pub(crate) struct ChatTurnGraph {
/// The root host carrier, built before the turn begins and retained by all
/// synchronous descendant dispatches.
pub run_context: crate::agent::tinyagents::host::OpenHumanRunContext,
+ /// Durable host authority captured at session construction.
+ pub hosted_base: Option<std::sync::Arc<crate::agent::tinyagents::host::OpenHumanHostBase>>,
}
/// Drive the chat turn graph: a thin wrapper over the shared tinyagents seam
diff --git a/crates/openhuman-core/src/agent/harness/session/types.rs b/crates/openhuman-core/src/agent/harness/session/types.rs
index e5a4ee3ab5..16d8b374aa 100644
--- a/crates/openhuman-core/src/agent/harness/session/types.rs
+++ b/crates/openhuman-core/src/agent/harness/session/types.rs
@@ -373,6 +373,9 @@ pub struct Agent {
/// re-run `Config::load_or_init()` on the hot path just to key into
/// the Composio cache.
pub(super) runtime_config: Option<Arc<crate::config::Config>>,
+ /// Durable inputs for hosted TinyAgents invocations. Built once by the
+ /// production factory; per-turn tools and progress remain outside it.
+ pub(super) hosted_base: Option<Arc<crate::agent::tinyagents::host::OpenHumanHostBase>>,
/// The definition this session was built from, when the factory had one.
///
/// Read back through [`Agent::resolved_definition`] by the in-turn sites