Skip to content

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

feat(memory): add as_bus_scope to expose host-side source scope to providers

Steven Enamakel7d4f3c3985ba
diff --git a/src/openhuman/memory/mod.rs b/src/openhuman/memory/mod.rs
index ebe12bbe6a..28a1f3b820 100644
--- a/src/openhuman/memory/mod.rs
+++ b/src/openhuman/memory/mod.rs
@@ -39,6 +39,9 @@ pub mod sync_events_bridge;
pub mod query;
pub mod read_rpc;
pub mod schemas;
+/// The host-side per-turn memory-source allowlist. See the module docs for why
+/// this is OpenHuman's and not the engine's.
+pub mod source_scope;
pub mod tools;
// Domains that are *mostly* extracted but keep their JSON-RPC surface here.
diff --git a/src/openhuman/memory/source_scope.rs b/src/openhuman/memory/source_scope.rs
index 87d44634ae..64eee166fd 100644
--- a/src/openhuman/memory/source_scope.rs
+++ b/src/openhuman/memory/source_scope.rs
@@ -51,6 +51,8 @@
use std::collections::HashSet;
use std::future::Future;
+use tinymemory_api::provider::types::SourceScope;
+
tokio::task_local! {
static SOURCE_SCOPE: Option<HashSet<String>>;
}
@@ -100,6 +102,22 @@ pub fn scope_allowed(scope: &str) -> bool {
}
}
+/// Render the ambient scope in the vocabulary a `MemoryProvider` call takes.
+///
+/// This is the whole point of keeping the task-local host-side: the ambient
+/// value is gathered once per turn, and every provider call that accepts a
+/// scope passes the result of this function rather than relying on the driver
+/// to read a task-local it cannot see.
+///
+/// `None` means unrestricted and must stay `None` — [`SourceScope`] treats an
+/// **empty** allowlist as denying every source-attributed item, so mapping
+/// "no restriction" onto `Some(SourceScope::new([]))` would invert the policy
+/// and silently blank out recall.
+#[must_use]
+pub fn as_bus_scope() -> Option<SourceScope> {
+ current_source_scope().map(|set| SourceScope::new(set))
+}
+
/// The tag every memory-source–ingested chunk carries (set by
/// `memory_sources::sync` and the github reader). Used as the discriminator so
/// the chunk-level gate only touches memory-SOURCE chunks and never working /