Skip to content

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

refactor(memory): import tinymemory_tools identity helpers directly

Steven Enamakel80f0677fd3aa
diff --git a/crates/openhuman-core/src/memory/engine.rs b/crates/openhuman-core/src/memory/engine.rs
index e5e393ba7e..549ced7207 100644
--- a/crates/openhuman-core/src/memory/engine.rs
+++ b/crates/openhuman-core/src/memory/engine.rs
@@ -415,7 +415,7 @@ fn rooted(
let Some(root) = root else {
return (settings, "|root=legacy".to_string());
};
- let actor = super::tinymemory_tools::layout::identity::actor_of_root(root);
+ let actor = tinymemory_tools::layout::identity::actor_of_root(root);
let retired = legacy_read.then(|| actor.clone());
let fingerprint = format!(
"|root={root}|tenant={tenant}|retired={}",
diff --git a/crates/openhuman-core/src/memory/engine_tests.rs b/crates/openhuman-core/src/memory/engine_tests.rs
index f60268f51a..cecd570a03 100644
--- a/crates/openhuman-core/src/memory/engine_tests.rs
+++ b/crates/openhuman-core/src/memory/engine_tests.rs
@@ -367,7 +367,7 @@ async fn switching_to_v3_persists_and_rebinds_the_persons_own_config() {
.await
.unwrap();
assert!(
- super::super::scope::layout_is_v3(&saved),
+ saved.memory.layout == crate::config::MemoryLayoutMode::V3,
"v3 written to this person's file"
);
let v3 = resolve(&saved).engine().expect("v3 bound");
diff --git a/crates/openhuman-core/src/memory/layout_migration/app_host.rs b/crates/openhuman-core/src/memory/layout_migration/app_host.rs
index 0caa6586dd..08e9bd3925 100644
--- a/crates/openhuman-core/src/memory/layout_migration/app_host.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/app_host.rs
@@ -96,7 +96,7 @@ impl lm::LayoutHost for AppHost {
}
fn is_switched(&self) -> bool {
- scope::layout_is_v3(&self.config)
+ self.config.memory.layout == MemoryLayoutMode::V3
}
async fn switch(&self) -> lm::Result<()> {
diff --git a/crates/openhuman-core/src/memory/layout_migration/app_host_tests.rs b/crates/openhuman-core/src/memory/layout_migration/app_host_tests.rs
index 00b26f7431..5c77675e37 100644
--- a/crates/openhuman-core/src/memory/layout_migration/app_host_tests.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/app_host_tests.rs
@@ -122,7 +122,7 @@ async fn the_switch_writes_the_migrated_persons_own_config_fresh() {
let saved = Config::load_from_config_path(&snapshot.config_path, &snapshot.workspace_dir)
.await
.unwrap();
- assert!(crate::memory::scope::layout_is_v3(&saved));
+ assert_eq!(saved.memory.layout, crate::config::MemoryLayoutMode::V3);
assert_eq!(saved.memory.agent_id.as_deref(), Some("changed-later"));
}
diff --git a/crates/openhuman-core/src/memory/lifecycle/mod.rs b/crates/openhuman-core/src/memory/lifecycle/mod.rs
index 73537fc4e4..05b107899d 100644
--- a/crates/openhuman-core/src/memory/lifecycle/mod.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/mod.rs
@@ -83,7 +83,7 @@ pub fn agent_memory(config: &Config, identity: &ResolvedIdentity) -> Result<Agen
/// The memory of `identity` (the default agent for the root identity).
pub fn current_agent_memory(
config: &Config,
- identity: &super::tinymemory_tools::layout::identity::Identity,
+ identity: &tinymemory_tools::layout::identity::Identity,
) -> Result<(AgentMemory, ResolvedIdentity)> {
let identity = identity.resolve(&crate::memory::scope::identity_pins(config));
let memory = agent_memory(config, &identity)?;
@@ -94,7 +94,7 @@ pub fn current_agent_memory(
/// itself when none is named.
pub fn named_agent_memory(
config: &Config,
- identity: &super::tinymemory_tools::layout::identity::Identity,
+ identity: &tinymemory_tools::layout::identity::Identity,
agent_id: Option<&str>,
) -> Result<(AgentMemory, ResolvedIdentity)> {
let mut identity = identity.resolve(&crate::memory::scope::identity_pins(config));
diff --git a/crates/openhuman-core/src/memory/lifecycle/views_tests.rs b/crates/openhuman-core/src/memory/lifecycle/views_tests.rs
index 9df266e47f..cd74459812 100644
--- a/crates/openhuman-core/src/memory/lifecycle/views_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/views_tests.rs
@@ -22,7 +22,10 @@ fn the_policy_round_trips_and_refuses_out_of_range_values() {
let mut config = Config::default();
let view = policy_view(&config);
assert!(view.log_conversations);
- assert_eq!(view.agent_id, scope::DEFAULT_AGENT_ID);
+ assert_eq!(
+ view.agent_id,
+ tinymemory_tools::layout::identity::DEFAULT_AGENT_ID
+ );
assert_eq!(view.root, "root");
assert!(!view.host_bound);
diff --git a/crates/openhuman-core/src/memory/scope_tests.rs b/crates/openhuman-core/src/memory/scope_tests.rs
index 299848afba..304ab6a6d1 100644
--- a/crates/openhuman-core/src/memory/scope_tests.rs
+++ b/crates/openhuman-core/src/memory/scope_tests.rs
@@ -3,7 +3,10 @@ use super::*;
use crate::config::schema::MemoryAgentConfig;
use tinymemory_api::{MetaFilter, Reach};
use tinymemory_tools::confine::{Confinement, Policy};
-use tinymemory_tools::layout::identity::{Identity, ResolvedIdentity};
+use tinymemory_tools::layout::identity::{
+ account_root, actor_of_root, chat_node, validate_root, Identity, ResolvedIdentity,
+ DEFAULT_AGENT_ID,
+};
fn ns(value: &str) -> Namespace {
value.parse().unwrap()
@@ -273,10 +276,10 @@ fn layout_v3_pools_every_agents_chats_at_ws_main() {
legacy.layout.conversations("researcher").unwrap(),
ns("agent:researcher")
);
- assert!(!layout_is_v3(&config));
+ assert_ne!(config.memory.layout, MemoryLayoutMode::V3);
config.memory.layout = MemoryLayoutMode::V3;
- assert!(layout_is_v3(&config));
+ assert_eq!(config.memory.layout, MemoryLayoutMode::V3);
let researcher = tinymemory_tools::layout::identity::Identity::agent("researcher").resolve(&crate::memory::scope::identity_pins(&config));
let coder = tinymemory_tools::layout::identity::Identity::agent("coder").resolve(&crate::memory::scope::identity_pins(&config));
assert_eq!(
diff --git a/crates/openhuman-core/src/memory/tool_writes.rs b/crates/openhuman-core/src/memory/tool_writes.rs
index 808c6c37dc..bdfb16d5c8 100644
--- a/crates/openhuman-core/src/memory/tool_writes.rs
+++ b/crates/openhuman-core/src/memory/tool_writes.rs
@@ -558,7 +558,7 @@ fn schedule_partition(ctx: &crate::core::runtime::DispatchCtx, config: Arc<Confi
pub(crate) async fn drain(config: &Config) -> usize {
let file = queue_path(
config,
- super::tinymemory_tools::layout::identity::Identity::root().resolve(&crate::memory::scope::identity_pins(config)).root(),
+ tinymemory_tools::layout::identity::Identity::root().resolve(&crate::memory::scope::identity_pins(config)).root(),
);
let owner = owner_state(config);
let _owner = owner.barrier.read().await;
diff --git a/crates/openhuman-core/src/memory/tools.rs b/crates/openhuman-core/src/memory/tools.rs
index 54c6c0189a..9e0b62ce33 100644
--- a/crates/openhuman-core/src/memory/tools.rs
+++ b/crates/openhuman-core/src/memory/tools.rs
@@ -98,8 +98,8 @@ impl CallFacts {
crate::agent::tinyagents::host::run_context::memory_identity_for_tool(context)
.unwrap_or_else(|| {
crate::agent::tinyagents::host::run_context::parent_agent_id_for_tool(context)
- .map_or_else(super::tinymemory_tools::layout::identity::Identity::root, |parent_agent_id| {
- super::tinymemory_tools::layout::identity::Identity::agent(&parent_agent_id)
+ .map_or_else(tinymemory_tools::layout::identity::Identity::root, |parent_agent_id| {
+ tinymemory_tools::layout::identity::Identity::agent(&parent_agent_id)
})
});
Self {
@@ -119,7 +119,7 @@ impl CallFacts {
/// The facts of a call made by `identity` under `config`, with no run
/// context.
#[must_use]
- pub fn of(config: &Config, identity: &super::tinymemory_tools::layout::identity::Identity) -> Self {
+ pub fn of(config: &Config, identity: &tinymemory_tools::layout::identity::Identity) -> Self {
let resolved = identity.resolve(&crate::memory::scope::identity_pins(config));
Self {
agent_id: Some(resolved.agent_id.clone()),
diff --git a/crates/openhuman-core/src/memory/tools_agent_tests.rs b/crates/openhuman-core/src/memory/tools_agent_tests.rs
index 84956fcbf1..bee4550a3e 100644
--- a/crates/openhuman-core/src/memory/tools_agent_tests.rs
+++ b/crates/openhuman-core/src/memory/tools_agent_tests.rs
@@ -31,7 +31,7 @@ fn gather_acts_as_the_identity_the_run_carries() {
let bare = CallFacts::gather(&config, None);
assert_eq!(
bare.agent_id.as_deref(),
- Some(super::super::scope::DEFAULT_AGENT_ID)
+ Some(tinymemory_tools::layout::identity::DEFAULT_AGENT_ID)
);
assert!(bare.reach.at.is_root());
}
diff --git a/crates/openhuman-embed/src/agent/build.rs b/crates/openhuman-embed/src/agent/build.rs
index 62f02e8f51..4b6a7d7981 100644
--- a/crates/openhuman-embed/src/agent/build.rs
+++ b/crates/openhuman-embed/src/agent/build.rs
@@ -169,7 +169,7 @@ pub(crate) fn instantiate(runtime: &Runtime, spec: AgentSpec) -> Result<AgentInn
));
}
if let Some(root) = binding.root_namespace() {
- openhuman_core::memory::tinymemory_tools::layout::identity::validate_root(root)
+ tinymemory_tools::layout::identity::validate_root(root)
.map_err(|reason| AgentError::Invalid(format!("memory root {root:?}: {reason}")))?;
}
log::debug!("[embed][agent] id={id} binds its memory agent_id={agent_id}");
diff --git a/crates/openhuman-embed/src/memory.rs b/crates/openhuman-embed/src/memory.rs
index 50b0c0c383..4c01c94fb6 100644
--- a/crates/openhuman-embed/src/memory.rs
+++ b/crates/openhuman-embed/src/memory.rs
@@ -36,7 +36,6 @@
use openhuman_core::config::Config;
use openhuman_core::memory::engine::{self, Binding};
-use openhuman_core::memory::tinymemory_tools::layout::identity::Identity;
use openhuman_core::memory::{brain, explore, lifecycle, ops, types};
use tinymemory_api::{
ItemKind, MemoryMeta, MetaFilter, Namespace, Reach, StoreItem, StoreReceipt, WriteOptions,
@@ -131,7 +130,7 @@ impl Memory {
/// Binds `base` to the layout root `root` (`team:acme`).
pub(crate) fn bind(mut base: Config, root: &str) -> Result<Self> {
let root = root.trim();
- openhuman_core::memory::tinymemory_tools::layout::identity::validate_root(root).map_err(Error::InvalidRequest)?;
+ tinymemory_tools::layout::identity::validate_root(root).map_err(Error::InvalidRequest)?;
let namespace: Namespace = root
.parse()
.map_err(|error: tinymemory_api::Error| Error::InvalidRequest(error.to_string()))?;