Skip to content

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

fix(memory): reject writes that exceed the configured memory budget

Steven Enamakel6ab61c0f39ac
diff --git a/crates/openhuman-core/src/memory/guard.rs b/crates/openhuman-core/src/memory/guard.rs
index 881084bf41..e8f74f9cb3 100644
--- a/crates/openhuman-core/src/memory/guard.rs
+++ b/crates/openhuman-core/src/memory/guard.rs
@@ -171,6 +171,13 @@ impl MemoryEngine for ScrubbingEngine {
.await
}
+ async fn list_preview(&self, req: ListRequest) -> Result<ListPage> {
+ self.timed("list_preview", self.inner.list_preview(req), |page| {
+ page.items.len()
+ })
+ .await
+ }
+
async fn export(&self, req: ListRequest) -> Result<ExportPage> {
self.timed("export", self.inner.export(req), |page| page.items.len())
.await
diff --git a/crates/openhuman-core/src/memory/ops.rs b/crates/openhuman-core/src/memory/ops.rs
index c9b1bbeb1f..00e73fd8f6 100644
--- a/crates/openhuman-core/src/memory/ops.rs
+++ b/crates/openhuman-core/src/memory/ops.rs
@@ -403,7 +403,11 @@ pub async fn items_list(config: &Config, params: ItemsListParams) -> MemoryResul
cursor: params.cursor,
};
request.validate()?;
- let page = bound.engine.list(request).await?;
+ let page = if params.preview {
+ bound.engine.list_preview(request).await?
+ } else {
+ bound.engine.list(request).await?
+ };
Ok(ItemsListView {
items: page.items,
next_cursor: page.next_cursor,
diff --git a/crates/openhuman-core/src/memory/schemas/defs.rs b/crates/openhuman-core/src/memory/schemas/defs.rs
index 4c46c619b5..aacb2de484 100644
--- a/crates/openhuman-core/src/memory/schemas/defs.rs
+++ b/crates/openhuman-core/src/memory/schemas/defs.rs
@@ -178,7 +178,13 @@ pub fn schema(function: &str) -> ControllerSchema {
namespace: "memory",
function: "items_list",
description: "Page through stored items, newest first.",
- inputs: vec![filter(), limit(), cursor(), path()],
+ inputs: vec![
+ filter(),
+ limit(),
+ cursor(),
+ path(),
+ opt("preview", TypeSchema::Bool, "Snippet listing: a conversation or chunked document may carry only its start; read it whole with items_get."),
+ ],
outputs: out("{items: Hit[], next_cursor?}"),
},
"explore" => ControllerSchema {
diff --git a/crates/openhuman-core/src/memory/types.rs b/crates/openhuman-core/src/memory/types.rs
index cf0b4fef51..206b764b3b 100644
--- a/crates/openhuman-core/src/memory/types.rs
+++ b/crates/openhuman-core/src/memory/types.rs
@@ -213,6 +213,12 @@ pub struct ItemsListParams {
/// Explorer path, applied on top of `filter` (see [`super::explore`]).
#[serde(default)]
pub path: Vec<super::explore::PathStep>,
+ /// A view that shows a snippet of each item and reads one whole with
+ /// `memory_items_get` when it is opened: a conversation's or chunked
+ /// document's text may then be only its start, which an engine can
+ /// list without assembling each item (`MemoryEngine::list_preview`).
+ #[serde(default)]
+ pub preview: bool,
}
/// `memory_items_list` result.