Skip to content

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

chore(runtime): remove unused context agent and overlay modules

Steven Enamakel485be2c14e74
diff --git a/crates/openhuman-core/src/core/runtime/context_agent.rs b/crates/openhuman-core/src/core/runtime/context_agent.rs
index c166eaace9..8ab6c016eb 100644
--- a/crates/openhuman-core/src/core/runtime/context_agent.rs
+++ b/crates/openhuman-core/src/core/runtime/context_agent.rs
@@ -25,7 +25,7 @@ impl AgentParts {
.definitions
.take()
.or_else(|| self.definitions.clone()),
- state: if overlay.session_agent.is_some() {
+ state: if overlay.session_agent.is_some() || overlay.profile.is_some() {
Default::default()
} else {
Arc::clone(&self.state)
@@ -62,6 +62,24 @@ impl CoreContext {
self.agent.definitions.clone()
}
+ /// The tenant (SaaS profile) this context serves, if any.
+ pub fn profile(&self) -> Option<&str> {
+ self.profile.as_deref()
+ }
+
+ /// Whether work beyond the caller's own handle still runs on this
+ /// context's tenant: another `Arc` of this context (a request scope, a
+ /// spawned task that captured it), or a turn context derived from it that
+ /// shares its state slots ([`scope_with_turn_origin`](Self::scope_with_turn_origin),
+ /// a `derive_with` naming neither agent nor profile). The caller is
+ /// assumed to hold exactly one `Arc` of `self`.
+ ///
+ /// A host must not close or evict a tenant while this is `true`: its
+ /// in-flight tables (turns, queues, caches) live in those slots.
+ pub fn tenant_in_use(self: &Arc<Self>) -> bool {
+ Arc::strong_count(self) > 1 || Arc::strong_count(&self.agent.state) > 1
+ }
+
/// The state slots this context owns.
pub fn agent_state(&self) -> &super::super::agent_scope::AgentScopedState {
&self.agent.state
diff --git a/crates/openhuman-core/src/core/runtime/context_overlay.rs b/crates/openhuman-core/src/core/runtime/context_overlay.rs
index bdec99c88c..bfe186a1c0 100644
--- a/crates/openhuman-core/src/core/runtime/context_overlay.rs
+++ b/crates/openhuman-core/src/core/runtime/context_overlay.rs
@@ -32,6 +32,11 @@ pub struct ContextOverlay {
/// journal, goals and todos to. `None` keeps the parent's. Setting it
/// gives the derived context state slots of its own.
pub session_agent: Option<String>,
+ /// The tenant (SaaS profile) the derived context serves. `None` keeps the
+ /// parent's. Setting it gives the derived context state slots of its own
+ /// and keys every tenant-scoped table on it
+ /// ([`tenant`](crate::core::runtime::tenant)).
+ pub profile: Option<String>,
/// The agent's own security policy: autonomy tier, auto-approve list,
/// action budget. `None` keeps the parent's.
pub agent_policy: Option<Arc<crate::security::SecurityPolicy>>,
@@ -54,6 +59,7 @@ impl ContextOverlay {
tool_groups,
user_skill_roots: true,
session_agent: None,
+ profile: None,
agent_policy: None,
approvals_disabled: false,
definitions: None,
@@ -73,6 +79,12 @@ impl ContextOverlay {
self
}
+ /// Make the derived context serve tenant (profile) `profile_id`.
+ pub fn profile(mut self, profile_id: impl Into<String>) -> Self {
+ self.profile = Some(profile_id.into());
+ self
+ }
+
/// Give the derived context its own security policy.
pub fn agent_policy(mut self, policy: Arc<crate::security::SecurityPolicy>) -> Self {
self.agent_policy = Some(policy);
diff --git a/crates/openhuman-core/src/core/runtime/spawn.rs b/crates/openhuman-core/src/core/runtime/spawn.rs
index dc87002e2b..91a56a2a34 100644
--- a/crates/openhuman-core/src/core/runtime/spawn.rs
+++ b/crates/openhuman-core/src/core/runtime/spawn.rs
@@ -61,6 +61,36 @@ where
}
}
+/// What [`CoreContext::propagate`] wraps a future in: the caller's context
+/// captured now and re-entered wherever the future is polled.
+///
+/// Single-user processes carry [`CoreContext::current`] and nothing else, as
+/// before. In SaaS only the caller's own task scope is carried (an unscoped
+/// caller's future runs with no context and so fails closed), together with
+/// the memory identity, exactly as [`scoped`] does — but without requiring
+/// the future to be `Send`.
+pub(crate) fn carry<F: Future>(fut: F) -> impl Future<Output = F::Output> {
+ let saas = super::is_saas();
+ let ctx = captured();
+ let identity = if saas {
+ crate::memory::scope::current()
+ } else {
+ None
+ };
+ async move {
+ let fut = async move {
+ match ctx {
+ Some(ctx) => CoreContext::scope(ctx, fut).await,
+ None => fut.await,
+ }
+ };
+ match identity {
+ Some(identity) => crate::memory::scope::within(identity, fut).await,
+ None => fut.await,
+ }
+ }
+}
+
/// Like `tokio::task::spawn_blocking`, but the closure runs under the caller's
/// [`CoreContext`] and memory identity.
pub fn spawn_blocking_scoped<F, R>(f: F) -> JoinHandle<R>
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs
index 9f8cd616c4..bda026f01a 100644
--- a/crates/openhuman-embed/src/agent/build.rs
+++ b/crates/openhuman-embed/src/agent/build.rs
@@ -210,6 +210,7 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn
user_skill_roots: parts.include_user_skills,
// A host session store keeps each agent's conversations apart by id.
session_agent: Some(id.to_string()),
+ profile: None,
agent_policy: Some(std::sync::Arc::new(
openhuman_core::security::SecurityPolicy::from_config(
&config.autonomy,