Skip to content

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

feat(sources): add source tool with tests

Steven Enamakel73866a81817e
diff --git a/crates/openhuman-core/src/tools/sources.rs b/crates/openhuman-core/src/tools/sources.rs
index 7d175cac7d..be0728ed60 100644
--- a/crates/openhuman-core/src/tools/sources.rs
+++ b/crates/openhuman-core/src/tools/sources.rs
@@ -121,6 +121,15 @@ pub fn unregister_tool_source(id: &str) -> bool {
TOOL_SOURCES.unregister(id)
}
+/// The placement of every registered source, in registration order.
+pub fn registered_tool_source_placements() -> Vec<(String, ToolSourcePlacement)> {
+ TOOL_SOURCES
+ .entries()
+ .into_iter()
+ .map(|(id, entry)| (id, entry.placement))
+ .collect()
+}
+
/// Builds the tools of every registered source placed at `anchor`
/// (`Some(name)`) or at the end (`None`, which also collects sources whose
/// anchor is unknown), in registration order.
diff --git a/crates/openhuman-core/src/tools/sources_tests.rs b/crates/openhuman-core/src/tools/sources_tests.rs
index 72591822d7..e72d8ddbb0 100644
--- a/crates/openhuman-core/src/tools/sources_tests.rs
+++ b/crates/openhuman-core/src/tools/sources_tests.rs
@@ -115,3 +115,65 @@ fn unregistering_a_source_removes_its_tools() {
assert!(unregister_tool_source("test::gone"));
assert!(!assemble(&tmp).contains(&"source_fake_gone".to_string()));
}
+
+#[test]
+fn anchored_sources_sit_where_the_catalogue_always_listed_them() {
+ // The pre-refactor catalogue built a host's media / file-storage tools
+ // right after the search tools (before hosting, web3 and image_info) and
+ // its place / market-data tools right after the delegation tool, ahead of
+ // the Composio tools; the order is a prompt-cache input.
+ let tmp = TempDir::new().unwrap();
+ let baseline = assemble(&tmp);
+ let anchor_tools = |names: &[&str]| -> Vec<Box<dyn Tool>> {
+ names
+ .iter()
+ .map(|n| Box::new(FakeTool(Box::leak(n.to_string().into_boxed_str()))) as Box<dyn Tool>)
+ .collect()
+ };
+
+ register_tool_source_at(
+ "test::after_search_a",
+ ToolSourcePlacement::After(ANCHOR_AFTER_SEARCH),
+ move |_| anchor_tools(&["anchor_fake_search_a"]),
+ );
+ register_tool_source_at(
+ "test::after_search_b",
+ ToolSourcePlacement::After(ANCHOR_AFTER_SEARCH),
+ move |_| anchor_tools(&["anchor_fake_search_b"]),
+ );
+ register_tool_source_at(
+ "test::after_delegate",
+ ToolSourcePlacement::After(ANCHOR_AFTER_DELEGATE),
+ move |_| anchor_tools(&["anchor_fake_delegate"]),
+ );
+ register_tool_source("test::end", |_| vec![Box::new(FakeTool("anchor_fake_end"))]);
+ register_tool_source_at(
+ "test::unknown_anchor",
+ ToolSourcePlacement::After("nowhere"),
+ |_| vec![Box::new(FakeTool("anchor_fake_unknown"))],
+ );
+ let names = assemble(&tmp);
+ for id in [
+ "test::after_search_a",
+ "test::after_search_b",
+ "test::after_delegate",
+ "test::end",
+ "test::unknown_anchor",
+ ] {
+ unregister_tool_source(id);
+ }
+
+ let pos = |name: &str| names.iter().position(|n| n == name).unwrap_or_else(|| panic!("{name} missing"));
+ // Registration order within an anchor.
+ assert_eq!(pos("anchor_fake_search_b"), pos("anchor_fake_search_a") + 1);
+ // After-search sources precede the image-info built-in registered after
+ // hosting/web3, and follow the built-ins that precede the search tools.
+ assert!(pos("file_read") < pos("anchor_fake_search_a"));
+ assert!(pos("anchor_fake_search_b") < pos("image_info"));
+ // End sources, and sources with an unknown anchor, trail every built-in
+ // and keep registration order.
+ assert!(pos("anchor_fake_delegate") < pos("anchor_fake_end"));
+ assert!(pos("anchor_fake_end") < pos("anchor_fake_unknown"));
+ assert_eq!(pos("anchor_fake_unknown"), names.len() - 1);
+ assert_eq!(names.len(), baseline.len() + 5);
+}
diff --git a/crates/openhuman-embed/src/host_internals.rs b/crates/openhuman-embed/src/host_internals.rs
index 4198bcea53..2efb799629 100644
--- a/crates/openhuman-embed/src/host_internals.rs
+++ b/crates/openhuman-embed/src/host_internals.rs
@@ -292,7 +292,7 @@ pub mod util {
pub mod tool_sources {
pub use openhuman_core::tools::sources::{
register_tool_source, register_tool_source_at, register_tool_source_in,
- unregister_tool_source, ToolSourceCtx, ToolSourceFactory, ToolSourcePlacement,
+ registered_tool_source_placements, unregister_tool_source, ToolSourceCtx, ToolSourceFactory, ToolSourcePlacement,
ANCHOR_AFTER_DELEGATE, ANCHOR_AFTER_SEARCH,
};
}
diff --git a/crates/openhuman-tinyhumans/src/integrations/mod_tests.rs b/crates/openhuman-tinyhumans/src/integrations/mod_tests.rs
index 9ce668f386..f49fa1c6ee 100644
--- a/crates/openhuman-tinyhumans/src/integrations/mod_tests.rs
+++ b/crates/openhuman-tinyhumans/src/integrations/mod_tests.rs
@@ -77,3 +77,44 @@ fn register_plugs_every_hosted_integration_into_the_core_registries() {
assert!(unregister_tool_source(FILE_STORAGE_SOURCE_ID));
register(&InstallOptions::default());
}
+
+/// The catalogue order is a prompt-cache input. Before the move the core built
+/// the media and file-storage tools right after the search tools, and the
+/// Google Places / stock tools right after the delegation tool (ahead of
+/// Composio); the sources must register at those same anchors and in that order.
+#[test]
+fn tool_sources_register_at_the_pre_refactor_catalogue_positions() {
+ use openhuman_embed::__host::tool_sources::{
+ registered_tool_source_placements, unregister_tool_source, ToolSourcePlacement,
+ ANCHOR_AFTER_DELEGATE, ANCHOR_AFTER_SEARCH,
+ };
+
+ register(&InstallOptions::default());
+ let ours: Vec<_> = registered_tool_source_placements()
+ .into_iter()
+ .filter(|(id, _)| id.starts_with("tinyhumans-"))
+ .collect();
+ let placement = |id: &str| ours.iter().find(|(i, _)| i == id).map(|(_, p)| *p);
+ let position = |id: &str| ours.iter().position(|(i, _)| i == id);
+
+ assert_eq!(
+ placement(FILE_STORAGE_SOURCE_ID),
+ Some(ToolSourcePlacement::After(ANCHOR_AFTER_SEARCH))
+ );
+ assert_eq!(
+ placement(INTEGRATION_TOOLS_SOURCE_ID),
+ Some(ToolSourcePlacement::After(ANCHOR_AFTER_DELEGATE))
+ );
+ #[cfg(feature = "media")]
+ {
+ assert_eq!(
+ placement(media::TOOL_SOURCE_ID),
+ Some(ToolSourcePlacement::After(ANCHOR_AFTER_SEARCH))
+ );
+ // media before file storage, as the core built them.
+ assert!(position(media::TOOL_SOURCE_ID) < position(FILE_STORAGE_SOURCE_ID));
+ assert!(unregister_tool_source(media::TOOL_SOURCE_ID));
+ }
+ assert!(unregister_tool_source(FILE_STORAGE_SOURCE_ID));
+ assert!(unregister_tool_source(INTEGRATION_TOOLS_SOURCE_ID));
+}