Skip to content

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

refactor(memory): simplify memory config handling in session and subagent hosts

Steven Enamakelb44b987093c3
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index d14157103a..7d41abf40a 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1025,17 +1025,10 @@ impl OpenHumanSessionHost {
}
}
}
- // Memory acts as this agent for the whole turn: what it learns lands
- // on its node and what it recalls stays within its reach.
- let default_config;
- let memory_config = match self.runtime_config.as_deref() {
- Some(config) => config,
- None => {
- default_config = crate::config::Config::default();
- &default_config
- }
- };
- let agent_id = self.agent_definition_id.clone();
+ let (agent_id, config) = (
+ self.agent_definition_id.clone(),
+ self.runtime_config.clone(),
+ );
let turn = self
.runtime_session
.as_mut()
@@ -1044,7 +1037,7 @@ impl OpenHumanSessionHost {
SessionTurnRequest::new(user_message_from_text(user_message)),
options,
);
- let outcome = crate::memory::scope::within_agent(memory_config, &agent_id, turn)
+ let outcome = crate::memory::scope::within_agent_in(config.as_deref(), &agent_id, turn)
.await
.map_err(|error| anyhow::anyhow!(error.to_string()))?;
Ok(outcome.output.unwrap_or_default())
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
index 57b54b2bb6..fb1f362cbc 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -361,14 +361,8 @@ pub(crate) async fn run_subagent_direct(
"[subagent_host] worktree-isolated worker: descriptor will route acting-tool CWD"
);
}
- // The child acts on memory as itself, nested under the agent that
- // spawned it: its learnings land on its own node and its recall
- // reaches that node and the ones above, never a sibling's.
- let memory_config = loaded_config
- .as_ref()
- .map_or_else(|_| std::sync::Arc::new(crate::config::Config::default()), Clone::clone);
let run_result = Box::pin(with_spawn_depth(attempted_depth, async {
- crate::memory::scope::within_agent(&memory_config, &definition.id, with_file_state_agent_id(task_id.clone(), async {
+ crate::memory::scope::within_agent_in(loaded_config.as_deref().ok(), &definition.id, with_file_state_agent_id(task_id.clone(), async {
with_current_sandbox_mode(definition.sandbox_mode, async {
Box::pin(run_typed_mode(
definition,
diff --git a/crates/openhuman-core/src/memory/scope.rs b/crates/openhuman-core/src/memory/scope.rs
index 7ab9f2dc4b..f96eca72db 100644
--- a/crates/openhuman-core/src/memory/scope.rs
+++ b/crates/openhuman-core/src/memory/scope.rs
@@ -195,6 +195,19 @@ pub async fn within_agent<F: Future>(config: &Config, agent_id: &str, fut: F) ->
within(identity, fut).await
}
+/// [`within_agent`] with the host's config when it has one, else the
+/// defaults (the main agent at the root, every other agent on its own node).
+pub async fn within_agent_in<F: Future>(
+ config: Option<&Config>,
+ agent_id: &str,
+ fut: F,
+) -> F::Output {
+ match config {
+ Some(config) => within_agent(config, agent_id, fut).await,
+ None => within_agent(&Config::default(), agent_id, fut).await,
+ }
+}
+
#[cfg(test)]
#[path = "scope_tests.rs"]
mod tests;