Skip to content

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

refactor(memory): extract session memory identity and readability helpers

Steven Enamakelb3ca30944419
diff --git a/crates/openhuman-core/src/memory/lifecycle/session_hooks.rs b/crates/openhuman-core/src/memory/lifecycle/session_hooks.rs
index 3e8a519aba..7e87ae0558 100644
--- a/crates/openhuman-core/src/memory/lifecycle/session_hooks.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/session_hooks.rs
@@ -110,7 +110,7 @@ impl OpenHumanTurnPrelude {
}
/// The config memory runs under: the session's own, else the
/// workspace's on disk.
- async fn memory_config(&self) -> Option<Arc<crate::config::Config>> {
+ pub(super) async fn memory_config(&self) -> Option<Arc<crate::config::Config>> {
if let Some(config) = &self.runtime_config {
return Some(config.clone());
}
@@ -126,6 +126,27 @@ impl OpenHumanTurnPrelude {
.ok()
}
+ /// The identity this session's memory runs as: the host environment's
+ /// (a team member's), narrowed to this agent.
+ pub(super) fn memory_identity(&self, config: &crate::config::Config) -> ResolvedIdentity {
+ let acting = self.host_env.memory_identity.clone().unwrap_or_default();
+ acting
+ .child(&self.agent_definition_id)
+ .resolve(&crate::memory::scope::identity_pins(config))
+ }
+
+ /// Whether this session may read memory at all: a SaaS turn without an
+ /// authenticated profile may not (see `capture_profile_context`).
+ pub(super) fn memory_readable(&self) -> bool {
+ !matches!(
+ capture_profile_context(
+ &self.dispatch_ctx(),
+ crate::profiles::host::host().as_deref(),
+ ),
+ ProfileMemoryContext::Denied
+ )
+ }
+
/// Takes completed memory and queues a user-authored turn's log and recall.
/// Remembers the turn so the reply is logged under the same identity and
/// index, and returns its memory for the run context without engine I/O.
@@ -148,12 +169,7 @@ impl OpenHumanTurnPrelude {
.clone()?;
let thread_id = self.thread_id.clone()?;
let config = self.memory_config().await?;
- // The identity the turn's run context carries: the host environment's
- // (a team member's), narrowed to this agent.
- let acting = self.host_env.memory_identity.clone().unwrap_or_default();
- let mut identity = acting
- .child(&self.agent_definition_id)
- .resolve(&crate::memory::scope::identity_pins(&config));
+ let mut identity = self.memory_identity(&config);
if self.omit_memory_context {
identity.recall = false;
}