Skip to content

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

refactor(memory): use tinymemory_api error types in the embed facade

Steven Enamakel8999e5e7e657
diff --git a/crates/openhuman-embed/src/memory.rs b/crates/openhuman-embed/src/memory.rs
index 46d98be3de..0fe3b739a0 100644
--- a/crates/openhuman-embed/src/memory.rs
+++ b/crates/openhuman-embed/src/memory.rs
@@ -32,7 +32,7 @@
//! The engine is the one every agent uses: the configured `[memory]` engine,
//! or one the host installed with [`install_host_engine`]. With neither, memory
//! is off and every call but [`Memory::status`] answers
-//! [`MemoryError::Off`].
+//! [`Error::Off`].
use openhuman_core::config::Config;
use openhuman_core::memory::engine::{self, Binding};
@@ -52,7 +52,7 @@ pub use openhuman_core::memory::lifecycle::views::{AgentCount, AgentsView};
pub use openhuman_core::memory::types::{
FetchView, ForgetView, ItemsListView, LearnParams, LearnView, RecallView,
};
-pub use openhuman_core::memory::{MemoryError, MemoryResult};
+pub use tinymemory_api::{Error, Result};
/// The TinyMemory engine contract, for a host that implements or installs an
/// engine ([`install_host_engine`]) or reads the items this facade returns.
@@ -129,14 +129,14 @@ impl std::fmt::Debug for Memory {
impl Memory {
/// Binds `base` to the layout root `root` (`team:acme`).
- pub(crate) fn bind(mut base: Config, root: &str) -> MemoryResult<Self> {
+ pub(crate) fn bind(mut base: Config, root: &str) -> Result<Self> {
let root = root.trim();
- openhuman_core::memory::scope::validate_root(root).map_err(MemoryError::invalid)?;
+ openhuman_core::memory::scope::validate_root(root).map_err(Error::invalid)?;
let namespace: Namespace = root
.parse()
- .map_err(|error: tinymemory_api::Error| MemoryError::invalid(error.to_string()))?;
+ .map_err(|error: tinymemory_api::Error| Error::InvalidRequest(error.to_string()))?;
if namespace.is_root() {
- return Err(MemoryError::invalid(
+ return Err(Error::InvalidRequest(
"a tenant's memory needs a root below the store root",
));
}
@@ -159,7 +159,7 @@ impl Memory {
}
/// The node `agent_id`'s conversations live at.
- pub fn agent_node(&self, agent_id: &str) -> MemoryResult<String> {
+ pub fn agent_node(&self, agent_id: &str) -> Result<String> {
Ok(self.layout.conversations(agent_id)?.to_string())
}
@@ -193,12 +193,12 @@ impl Memory {
}
/// The agents with logged turns under the root, most first.
- pub async fn agents(&self) -> MemoryResult<AgentsView> {
+ pub async fn agents(&self) -> Result<AgentsView> {
lifecycle::views::agents_list(&self.config, &MemoryIdentity::root()).await
}
/// A page of items, newest first.
- pub async fn list(&self, query: ItemsQuery) -> MemoryResult<ItemsListView> {
+ pub async fn list(&self, query: ItemsQuery) -> Result<ItemsListView> {
let reach = self.reach_of(query.agent_id.as_deref())?;
ops::items_list(
&self.config,
@@ -219,7 +219,7 @@ impl Memory {
}
/// The items among `ids` the root holds.
- pub async fn get(&self, ids: Vec<String>) -> MemoryResult<Vec<api::Hit>> {
+ pub async fn get(&self, ids: Vec<String>) -> Result<Vec<api::Hit>> {
let view = explore::items_get(
&self.config,
explore::ItemsGetParams {
@@ -238,7 +238,7 @@ impl Memory {
question: impl Into<String>,
agent_id: Option<&str>,
limit: Option<usize>,
- ) -> MemoryResult<RecallView> {
+ ) -> Result<RecallView> {
ops::recall(
&self.config,
types::RecallParams {
@@ -257,7 +257,7 @@ impl Memory {
query: impl Into<String>,
kinds: Vec<ItemKind>,
limit: Option<usize>,
- ) -> MemoryResult<FetchView> {
+ ) -> Result<FetchView> {
ops::fetch(
&self.config,
types::FetchParams {
@@ -279,7 +279,7 @@ impl Memory {
/// Ranked items matching `query.query` under the root, narrowed by kind
/// and tag: [`Memory::fetch`] for a host that files what it captures
/// under tags of its own and reads only some of them back.
- pub async fn search(&self, query: SearchQuery) -> MemoryResult<FetchView> {
+ pub async fn search(&self, query: SearchQuery) -> Result<FetchView> {
let mut filter = self.reading(query.agent_id.as_deref())?;
filter.kinds = query.kinds;
filter.tags_any = query.tags_any;
@@ -313,7 +313,7 @@ impl Memory {
mut item: StoreItem,
agent_id: Option<&str>,
options: WriteOptions,
- ) -> MemoryResult<StoreReceipt> {
+ ) -> Result<StoreReceipt> {
let node = match agent_id.map(str::trim).filter(|agent| !agent.is_empty()) {
Some(agent) => self.layout.conversations(agent)?,
None => self.layout.learnings().clone(),
@@ -324,7 +324,7 @@ impl Memory {
/// Stores a shared learning at the root. The root is authoritative: a
/// namespace in `params.meta` is overwritten.
- pub async fn learn(&self, params: LearnParams) -> MemoryResult<LearnView> {
+ pub async fn learn(&self, params: LearnParams) -> Result<LearnView> {
let host = MemoryMeta {
namespace: self.layout.learnings().clone(),
..MemoryMeta::default()
@@ -334,7 +334,7 @@ impl Memory {
/// Forgets the items among `ids` the root holds; any other id is left
/// alone.
- pub async fn forget(&self, ids: Vec<String>) -> MemoryResult<ForgetView> {
+ pub async fn forget(&self, ids: Vec<String>) -> Result<ForgetView> {
ops::forget(
&self.config,
types::ForgetParams {
@@ -347,7 +347,7 @@ impl Memory {
/// Forgets everything stored at and below one agent's node: its logged
/// turns and the beliefs built from them. Returns how many were removed.
- pub async fn forget_agent(&self, agent_id: &str) -> MemoryResult<usize> {
+ pub async fn forget_agent(&self, agent_id: &str) -> Result<usize> {
let mut forgotten = 0;
loop {
let page = self
@@ -377,7 +377,7 @@ impl Memory {
}
/// The brain's sources under the root and their sizes.
- pub async fn brain_sources(&self) -> MemoryResult<BrainSourcesView> {
+ pub async fn brain_sources(&self) -> Result<BrainSourcesView> {
brain::sources(&self.config, &MemoryIdentity::root()).await
}
@@ -387,7 +387,7 @@ impl Memory {
query: impl Into<String>,
source: Option<String>,
limit: Option<usize>,
- ) -> MemoryResult<BrainSearchView> {
+ ) -> Result<BrainSearchView> {
brain::search(
&self.config,
&MemoryIdentity::root(),
@@ -401,12 +401,12 @@ impl Memory {
}
/// Files a document (a file on disk, or text) in the root's brain.
- pub async fn brain_ingest(&self, params: BrainIngestParams) -> MemoryResult<BrainIngestView> {
+ pub async fn brain_ingest(&self, params: BrainIngestParams) -> Result<BrainIngestView> {
brain::ingest(&self.config, &MemoryIdentity::root(), params).await
}
/// Forgets every brain document of one source under the root.
- pub async fn brain_forget(&self, source: impl Into<String>) -> MemoryResult<BrainForgetView> {
+ pub async fn brain_forget(&self, source: impl Into<String>) -> Result<BrainForgetView> {
brain::forget(
&self.config,
&MemoryIdentity::root(),
@@ -423,7 +423,7 @@ impl Memory {
/// The reach a listing reads: the root's subtree, or one agent's node
/// and everything below it.
- fn reach_of(&self, agent_id: Option<&str>) -> MemoryResult<Reach> {
+ fn reach_of(&self, agent_id: Option<&str>) -> Result<Reach> {
match agent_id.map(str::trim).filter(|agent| !agent.is_empty()) {
Some(agent) => Ok(Reach {
at: self.layout.conversations(agent)?,
@@ -436,7 +436,7 @@ impl Memory {
/// What a recall reads: the whole root, or one agent's node with the
/// root's shared learnings it inherits — never a sibling agent's turns.
- fn reading(&self, agent_id: Option<&str>) -> MemoryResult<MetaFilter> {
+ fn reading(&self, agent_id: Option<&str>) -> Result<MetaFilter> {
match agent_id.map(str::trim).filter(|agent| !agent.is_empty()) {
Some(agent) => Ok(MetaFilter {
reach: Some(Reach {
diff --git a/crates/openhuman-embed/src/memory_tests.rs b/crates/openhuman-embed/src/memory_tests.rs
index f3f9f2ea28..47ee711180 100644
--- a/crates/openhuman-embed/src/memory_tests.rs
+++ b/crates/openhuman-embed/src/memory_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-fn bind(root: &str) -> MemoryResult<Memory> {
+fn bind(root: &str) -> Result<Memory> {
Memory::bind(Config::default(), root)
}
@@ -15,10 +15,10 @@ fn binds_a_tenant_root_and_pins_it_on_the_config() {
#[test]
fn refuses_the_store_root_and_invalid_roots() {
- assert!(matches!(bind(""), Err(MemoryError::InvalidRequest(_))));
+ assert!(matches!(bind(""), Err(Error::InvalidRequest(_))));
assert!(matches!(
bind("not a namespace"),
- Err(MemoryError::InvalidRequest(_))
+ Err(Error::InvalidRequest(_))
));
}
diff --git a/crates/openhuman-embed/src/runtime/mod.rs b/crates/openhuman-embed/src/runtime/mod.rs
index c408687504..814a46781a 100644
--- a/crates/openhuman-embed/src/runtime/mod.rs
+++ b/crates/openhuman-embed/src/runtime/mod.rs
@@ -509,11 +509,11 @@ impl Runtime {
///
/// # Errors
///
- /// [`MemoryError::InvalidRequest`](crate::memory::MemoryError::InvalidRequest)
+ /// [`Error::InvalidRequest`](crate::memory::Error::InvalidRequest)
/// when `root` is not a valid layout root, or is the store root itself.
- pub fn memory(&self, root: &str) -> crate::memory::MemoryResult<crate::memory::Memory> {
+ pub fn memory(&self, root: &str) -> crate::memory::Result<crate::memory::Memory> {
if let Some(error) = &self.config_unavailable {
- return Err(crate::memory::MemoryError::InvalidRequest(format!(
+ return Err(crate::memory::Error::InvalidRequest(format!(
"the runtime's config failed to load ({error})"
)));
}