Skip to content

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

chore: files changed crates/openhuman-core/src/memory/tool_budget_tests.rs,crates/openhuman-core/src

Steven Enamakeldb424f01584a
diff --git a/crates/openhuman-core/src/memory/tool_budget_tests.rs b/crates/openhuman-core/src/memory/tool_budget_tests.rs
index a908038c11..a5749022e6 100644
--- a/crates/openhuman-core/src/memory/tool_budget_tests.rs
+++ b/crates/openhuman-core/src/memory/tool_budget_tests.rs
@@ -21,7 +21,10 @@ async fn a_slow_memory_call_returns_and_disables_memory_only_for_its_turn() {
budget.run(Some("turn-one"), async { "must not run" }).await,
Err(Refusal::Denied(DenialReason::CircuitOpen))
);
- assert_eq!(budget.run(Some("turn-two"), async { "healthy" }).await, Ok("healthy"));
+ assert_eq!(
+ budget.run(Some("turn-two"), async { "healthy" }).await,
+ Ok("healthy")
+ );
}
#[tokio::test]
@@ -42,7 +45,10 @@ async fn successful_memory_churn_is_bounded_without_blocking_the_next_turn() {
}
}
assert_eq!(calls.load(Ordering::SeqCst), 8);
- assert_eq!(budget.run(Some("turn-two"), async { "healthy" }).await, Ok("healthy"));
+ assert_eq!(
+ budget.run(Some("turn-two"), async { "healthy" }).await,
+ Ok("healthy")
+ );
}
#[tokio::test(start_paused = true)]
@@ -133,7 +139,10 @@ async fn parallel_memory_reads_reserve_from_the_same_time_budget() {
async fn completed_run_tracking_is_bounded() {
let budget = budget();
for i in 0..200 {
- assert!(budget.run(Some(&format!("turn-{i}")), async { "ok" }).await.is_ok());
+ assert!(budget
+ .run(Some(&format!("turn-{i}")), async { "ok" })
+ .await
+ .is_ok());
}
// The first idle record was evicted, so it receives a fresh call allowance.
for _ in 0..8 {
@@ -148,15 +157,20 @@ async fn completed_run_tracking_is_bounded() {
#[tokio::test(start_paused = true)]
async fn an_outstanding_memory_call_survives_other_runs_and_keeps_its_timeout_circuit() {
let budget = budget();
- let call = budget.run(Some("active"), std::future::pending::<()>()) ;
+ let call = budget.run(Some("active"), std::future::pending::<()>());
tokio::pin!(call);
assert!(futures::poll!(call.as_mut()).is_pending());
for i in 0..128 {
- assert!(budget.run(Some(&format!("other-{i}")), async { "ok" }).await.is_ok());
+ assert!(budget
+ .run(Some(&format!("other-{i}")), async { "ok" })
+ .await
+ .is_ok());
}
assert_eq!(call.await, Err(Refusal::TimedOut));
assert_eq!(
- budget.run(Some("active"), async { "must not execute" }).await,
+ budget
+ .run(Some("active"), async { "must not execute" })
+ .await,
Err(Refusal::Denied(DenialReason::CircuitOpen))
);
}
@@ -166,7 +180,8 @@ async fn full_tracking_refuses_new_work_until_an_active_reservation_is_released(
let budget = budget();
let mut pending = Vec::new();
for i in 0..128 {
- let mut call = Box::pin(budget.run(Some(&format!("active-{i}")), std::future::pending::<()>())) ;
+ let mut call =
+ Box::pin(budget.run(Some(&format!("active-{i}")), std::future::pending::<()>()));
assert!(futures::poll!(call.as_mut()).is_pending());
pending.push(call);
}
@@ -175,13 +190,16 @@ async fn full_tracking_refuses_new_work_until_an_active_reservation_is_released(
Err(Refusal::Denied(DenialReason::TrackingFull))
);
drop(pending);
- assert_eq!(budget.run(Some("new"), async { "healthy" }).await, Ok("healthy"));
+ assert_eq!(
+ budget.run(Some("new"), async { "healthy" }).await,
+ Ok("healthy")
+ );
}
#[tokio::test(start_paused = true)]
async fn cancelling_a_call_returns_its_unused_time_reservation() {
let budget = budget();
- let mut call = Box::pin(budget.run(Some("cancelled"), std::future::pending::<()>())) ;
+ let mut call = Box::pin(budget.run(Some("cancelled"), std::future::pending::<()>()));
assert!(futures::poll!(call.as_mut()).is_pending());
drop(call);
for _ in 0..2 {
diff --git a/crates/openhuman-core/src/memory/tool_writes_tests.rs b/crates/openhuman-core/src/memory/tool_writes_tests.rs
index 6514ab6921..273fa854de 100644
--- a/crates/openhuman-core/src/memory/tool_writes_tests.rs
+++ b/crates/openhuman-core/src/memory/tool_writes_tests.rs
@@ -38,9 +38,9 @@ pub(crate) fn enqueue(
scope,
);
let single = SingleTool::new(crate::memory::tools::MEMORY_TOOL_NAME, tools)
- .with_write_sink(std::sync::Arc::new(
- super::HostWriteSink::new(std::sync::Arc::new(config)),
- ));
+ .with_write_sink(std::sync::Arc::new(super::HostWriteSink::new(
+ std::sync::Arc::new(config),
+ )));
let outcome = single
.call_with_details(args, CallContext::default())
.await
diff --git a/crates/openhuman-core/src/memory/tools.rs b/crates/openhuman-core/src/memory/tools.rs
index be70856aae..a2486c161e 100644
--- a/crates/openhuman-core/src/memory/tools.rs
+++ b/crates/openhuman-core/src/memory/tools.rs
@@ -8,11 +8,11 @@ use std::time::Duration;
use async_trait::async_trait;
use serde_json::{json, Value};
use tinymemory_api::{Namespace, Reach, ThreadWindow, ToolCallRef};
-use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolResult, ToolRunContext};
use tinymemory_tools::{
- CallContext, ConcurrencyClass, MemoryTools, PermissionClass, Refusal, RunBudget, SingleTool,
- ToolScope, concurrency_for, is_write_action, permission_for,
+ concurrency_for, is_write_action, permission_for, CallContext, ConcurrencyClass, MemoryTools,
+ PermissionClass, Refusal, RunBudget, SingleTool, ToolScope,
};
+use tinytools::{PermissionLevel, Tool, ToolCallOptions, ToolResult, ToolRunContext};
use crate::config::Config;
use crate::core::bus::BUS;
@@ -55,20 +55,29 @@ impl CallFacts {
.and_then(ToolRunContext::workspace_root)
.map(std::path::Path::to_path_buf)
.unwrap_or_else(|| config.action_dir.clone());
- let identity = 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(
- tinymemory_tools::layout::identity::Identity::root,
- |parent_agent_id| tinymemory_tools::layout::identity::Identity::agent(&parent_agent_id),
- )
- });
+ let identity =
+ 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(
+ tinymemory_tools::layout::identity::Identity::root,
+ |parent_agent_id| {
+ tinymemory_tools::layout::identity::Identity::agent(
+ &parent_agent_id,
+ )
+ },
+ )
+ });
Self {
workspace: Some(workspace.display().to_string()),
- thread_id: context.and_then(ToolRunContext::thread_id).map(str::to_string),
+ thread_id: context
+ .and_then(ToolRunContext::thread_id)
+ .map(str::to_string),
tool_call_id: crate::tools::host_extensions::tool_call_id(context),
chat: crate::agent::tinyagents::host::run_context::approval_for_tool(context).chat,
- in_prompt: crate::agent::tinyagents::host::run_context::memory_in_prompt_for_tool(context),
+ in_prompt: crate::agent::tinyagents::host::run_context::memory_in_prompt_for_tool(
+ context,
+ ),
..Self::of(config, &identity)
}
}
@@ -100,7 +109,6 @@ impl CallFacts {
}),
}
}
-
}
/// OpenHuman's monotonic Tokio clock for TinyMemory's runtime-neutral budget.
@@ -186,11 +194,7 @@ impl MemoryTool {
});
}
if is_write_action(&args) {
- super::tool_writes::schedule(
- &dispatch,
- self.config.clone(),
- &facts.reach.at,
- );
+ super::tool_writes::schedule(&dispatch, self.config.clone(), &facts.reach.at);
}
ToolResult::success(outcome.value.to_string())
};
@@ -252,7 +256,9 @@ impl Tool for MemoryTool {
.and_then(ToolRunContext::host_extension)
.and_then(|any| any.downcast_ref::<tinyagents_harness::tool::ToolExecutionContext>())
.map(|ctx| ctx.run_id.as_str().to_string());
- Ok(self.call_with_facts(args, dispatch, facts, run_id.as_deref()).await)
+ Ok(self
+ .call_with_facts(args, dispatch, facts, run_id.as_deref())
+ .await)
}
}
@@ -287,28 +293,28 @@ pub fn is_budget_refusal(result: &ToolResult) -> bool {
}
#[cfg(test)]
-#[path = "tools_tests.rs"]
-mod tests;
+#[path = "tools_activity_tests.rs"]
+mod activity_tests;
#[cfg(test)]
#[path = "tools_agent_tests.rs"]
mod agent_tests;
#[cfg(test)]
-#[path = "tools_schema_tests.rs"]
-mod schema_tests;
-#[cfg(test)]
#[path = "tools_budget_tests.rs"]
mod budget_tests;
#[cfg(test)]
#[path = "tool_budget_tests.rs"]
mod native_budget_tests;
#[cfg(test)]
-#[path = "tools_activity_tests.rs"]
-mod activity_tests;
-#[cfg(test)]
#[path = "tools_read_tests.rs"]
mod read_tests;
#[cfg(test)]
+#[path = "tools_schema_tests.rs"]
+mod schema_tests;
+#[cfg(test)]
#[path = "tools_test_support.rs"]
mod test_support;
#[cfg(test)]
+#[path = "tools_tests.rs"]
+mod tests;
+#[cfg(test)]
use test_support::run_action;
diff --git a/crates/openhuman-core/src/memory/tools_read_tests.rs b/crates/openhuman-core/src/memory/tools_read_tests.rs
index 46ab81cf26..3615213951 100644
--- a/crates/openhuman-core/src/memory/tools_read_tests.rs
+++ b/crates/openhuman-core/src/memory/tools_read_tests.rs
@@ -51,7 +51,11 @@ fn capped_evidence(evidence: &str) -> String {
}
let left = entries.len() - whole - usize::from(cut_short);
if left > 0 || cut_short {
- let shortened = if cut_short { ", the last one shortened," } else { "" };
+ let shortened = if cut_short {
+ ", the last one shortened,"
+ } else {
+ ""
+ };
out.push_str(&format!(
"\n\n({left} more memory entries left out{shortened} to keep this under about \
{TOKENS} tokens; search again with more specific words to see others.)"
diff --git a/crates/openhuman-core/src/memory/tools_test_support.rs b/crates/openhuman-core/src/memory/tools_test_support.rs
index 5a66a99f06..638dd23f06 100644
--- a/crates/openhuman-core/src/memory/tools_test_support.rs
+++ b/crates/openhuman-core/src/memory/tools_test_support.rs
@@ -1,6 +1,6 @@
//! Shared test adapters for the memory tool's native facade.
-use super::{CallFacts, MemoryTool, is_write_action};
+use super::{is_write_action, CallFacts, MemoryTool};
use crate::config::Config;
use crate::core::runtime::DispatchCtx;
use serde_json::Value;
diff --git a/crates/openhuman-core/src/memory/tools_tests.rs b/crates/openhuman-core/src/memory/tools_tests.rs
index 70f576d641..02e2c8f9b1 100644
--- a/crates/openhuman-core/src/memory/tools_tests.rs
+++ b/crates/openhuman-core/src/memory/tools_tests.rs
@@ -435,12 +435,10 @@ async fn learnings_are_shared_under_a_root_and_a_team_root_is_kept_apart() {
"{}",
forgot.text()
);
- assert!(
- stored(&engine, MetaFilter::default())
- .await
- .iter()
- .all(|hit| hit.meta.namespace != Namespace::agent("nobody"))
- );
+ assert!(stored(&engine, MetaFilter::default())
+ .await
+ .iter()
+ .all(|hit| hit.meta.namespace != Namespace::agent("nobody")));
}
/// The reference engine, recording how far each single store waited.
@@ -687,4 +685,3 @@ async fn learning_is_durably_queued_even_when_the_backend_refuses_writes() {
assert_eq!(value["status"], "queued; not yet saved to memory");
assert_eq!(super::super::tool_writes::drain(&config).await, 0);
}
-