Skip to content

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

fix(memory): restore missing memory exploration ops

Steven Enamakela2183b7b4e90
diff --git a/crates/openhuman-core/src/memory/explore.rs b/crates/openhuman-core/src/memory/explore.rs
index 96b70f463b..6df3596255 100644
--- a/crates/openhuman-core/src/memory/explore.rs
+++ b/crates/openhuman-core/src/memory/explore.rs
@@ -59,6 +59,9 @@ pub struct ExploreParams {
pub struct ItemsGetParams {
/// Item ids.
pub ids: Vec<String>,
+ /// Only items in this reach are returned; unset reads every namespace.
+ #[serde(default)]
+ pub reach: Option<tinymemory::Reach>,
}
/// `memory_items_get` result.
@@ -114,6 +117,7 @@ pub async fn items_get(config: &Config, params: ItemsGetParams) -> MemoryResult<
let bound = engine::resolve(config).engine()?;
let request = GetRequest {
ids: params.ids.into_iter().map(ItemId::new).collect(),
+ reach: params.reach,
};
request.validate()?;
let asked = request.ids.len();
diff --git a/crates/openhuman-core/src/memory/ops.rs b/crates/openhuman-core/src/memory/ops.rs
index 1e1b08f5bc..754c8dc9ac 100644
--- a/crates/openhuman-core/src/memory/ops.rs
+++ b/crates/openhuman-core/src/memory/ops.rs
@@ -249,6 +249,9 @@ fn merge_meta(meta: &mut MemoryMeta, host: MemoryMeta) {
observed_at
);
meta.source = host.source;
+ // The host's node is authoritative: a caller cannot write into another
+ // agent's memory.
+ meta.namespace = host.namespace;
for tag in host.tags {
if !meta.tags.contains(&tag) {
meta.tags.push(tag);
@@ -329,6 +332,14 @@ pub async fn forget(config: &Config, params: ForgetParams) -> MemoryResult<Forge
return Err(MemoryError::invalid("forget needs at least one id"));
}
let bound = bound(config)?;
+ let ids = match params.reach {
+ Some(reach) => within_reach(&bound, ids, reach).await?,
+ None => ids,
+ };
+ if ids.is_empty() {
+ tracing::debug!(engine = %bound.id, "[memory:ops] forget: nothing in reach");
+ return Ok(ForgetView { forgotten: 0 });
+ }
let report = bound.engine.forget(ForgetTarget::Ids(ids)).await?;
tracing::debug!(engine = %bound.id, forgotten = report.forgotten, "[memory:ops] forget");
Ok(ForgetView {
@@ -336,6 +347,27 @@ pub async fn forget(config: &Config, params: ForgetParams) -> MemoryResult<Forge
})
}
+/// The ids among `ids` naming an item in `reach`, read through `get` in
+/// chunks of its id limit.
+async fn within_reach(
+ bound: &BoundEngine,
+ ids: Vec<ItemId>,
+ reach: tinymemory::Reach,
+) -> MemoryResult<Vec<ItemId>> {
+ let mut kept = Vec::new();
+ for chunk in ids.chunks(tinymemory::explore::MAX_GET_IDS) {
+ let found = bound
+ .engine
+ .get(tinymemory::GetRequest {
+ ids: chunk.to_vec(),
+ reach: Some(reach.clone()),
+ })
+ .await?;
+ kept.extend(found.into_iter().map(|hit| hit.id));
+ }
+ Ok(kept)
+}
+
/// `memory_items_list`.
pub async fn items_list(config: &Config, params: ItemsListParams) -> MemoryResult<ItemsListView> {
let bound = bound(config)?;
diff --git a/crates/openhuman-core/src/memory/types.rs b/crates/openhuman-core/src/memory/types.rs
index 4486c2d268..f0eb1f16e4 100644
--- a/crates/openhuman-core/src/memory/types.rs
+++ b/crates/openhuman-core/src/memory/types.rs
@@ -167,6 +167,11 @@ pub struct LearnView {
pub struct ForgetParams {
/// Item ids.
pub ids: Vec<String>,
+ /// Only ids of items in this reach are forgotten; an id outside it is
+ /// left alone as if it named nothing. The `memory` tool always sets the
+ /// calling agent's reach.
+ #[serde(default)]
+ pub reach: Option<tinymemory::Reach>,
}
/// `memory_forget` result.