Skip to content

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

feat(memory): add schema definitions and handler for memory types

Steven Enamakel1d25220c6200
diff --git a/crates/openhuman-core/src/memory/schemas/defs.rs b/crates/openhuman-core/src/memory/schemas/defs.rs
index e25841cc36..da8a1e3acb 100644
--- a/crates/openhuman-core/src/memory/schemas/defs.rs
+++ b/crates/openhuman-core/src/memory/schemas/defs.rs
@@ -72,6 +72,14 @@ fn filter() -> FieldSchema {
)
}
+fn namespace() -> FieldSchema {
+ opt(
+ "namespace",
+ TypeSchema::String,
+ "Memory node, e.g. `agent:researcher` or `team:acme/agent:writer`; the root when omitted.",
+ )
+}
+
fn path() -> FieldSchema {
opt(
"path",
@@ -254,15 +262,15 @@ pub fn schema(function: &str) -> ControllerSchema {
"context_get" => ControllerSchema {
namespace: "memory",
function: "context_get",
- description: "The compiled context.md and its settings.",
- inputs: vec![],
- outputs: out("{markdown, tokens, generated_at, interval_mins, budget_tokens, enabled}"),
+ description: "The compiled context.md of one memory node (the root by default) and its settings.",
+ inputs: vec![namespace()],
+ outputs: out("{namespace, markdown, tokens, generated_at, interval_mins, budget_tokens, enabled}"),
},
"context_refresh" => ControllerSchema {
namespace: "memory",
function: "context_refresh",
- description: "Recompile context.md now.",
- inputs: vec![],
+ description: "Recompile one memory node's context.md now (the root by default).",
+ inputs: vec![namespace()],
outputs: out("Same as memory_context_get."),
},
"context_set" => ControllerSchema {
diff --git a/crates/openhuman-core/src/memory/schemas/handlers.rs b/crates/openhuman-core/src/memory/schemas/handlers.rs
index 713782d306..686558ed8c 100644
--- a/crates/openhuman-core/src/memory/schemas/handlers.rs
+++ b/crates/openhuman-core/src/memory/schemas/handlers.rs
@@ -205,15 +205,15 @@ pub(super) fn sources_sync(params: Map<String, Value>) -> ControllerFuture {
pub(super) fn context_get(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- parse::<EmptyParams>(params)?;
- to_json(context::view(&load().await?))
+ let namespace = parse::<ContextNodeParams>(params)?.node()?;
+ to_json(context::view_for(&load().await?, &namespace))
})
}
pub(super) fn context_refresh(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
- parse::<EmptyParams>(params)?;
- finish(context::refresh(&load().await?).await)
+ let namespace = parse::<ContextNodeParams>(params)?.node()?;
+ finish(context::refresh_for(&load().await?, &namespace).await)
})
}
diff --git a/crates/openhuman-core/src/memory/types.rs b/crates/openhuman-core/src/memory/types.rs
index b3be57c86b..66c741d6c0 100644
--- a/crates/openhuman-core/src/memory/types.rs
+++ b/crates/openhuman-core/src/memory/types.rs
@@ -369,6 +369,32 @@ pub struct ContextView {
pub enabled: bool,
}
+/// `memory_context_get` / `memory_context_refresh` params.
+#[derive(Debug, Clone, Default, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct ContextNodeParams {
+ /// The memory node; the root when omitted.
+ #[serde(default)]
+ pub namespace: Option<String>,
+}
+
+impl ContextNodeParams {
+ /// The node named, checked.
+ ///
+ /// # Errors
+ ///
+ /// A malformed namespace.
+ pub fn node(&self) -> Result<tinymemory::Namespace, String> {
+ self.namespace
+ .as_deref()
+ .unwrap_or_default()
+ .parse()
+ .map_err(|error: tinymemory::Error| {
+ String::from(super::error::MemoryError::invalid(error.to_string()))
+ })
+ }
+}
+
/// `memory_context_set` params.
#[derive(Debug, Clone, Default, Deserialize)]
pub struct ContextSetParams {