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/agent/session_host/builder/builder_tests_tool_exposur

Steven Enamakel3ef0b685ba77
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_tool_exposure_tests.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_tool_exposure_tests.rs
index a9e4554fd6..1a139169fe 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_tool_exposure_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_tool_exposure_tests.rs
@@ -91,49 +91,114 @@ fn wildcard_belt_advertises_collapsed_tools_not_their_hidden_members() {
);
}
+struct FakeTool(&'static str, tinytools::ToolExposure);
+
+#[async_trait::async_trait]
+impl tinytools::Tool for FakeTool {
+ fn name(&self) -> &str {
+ self.0
+ }
+ fn description(&self) -> &str {
+ "fake"
+ }
+ fn parameters_schema(&self) -> serde_json::Value {
+ serde_json::json!({"type": "object"})
+ }
+ fn exposure(&self) -> tinytools::ToolExposure {
+ self.1
+ }
+ async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<tinytools::ToolResult> {
+ Ok(tinytools::ToolResult::success("ok"))
+ }
+}
+
+fn build_with(
+ tools: Vec<Box<dyn tinytools::Tool>>,
+ visible: std::collections::HashSet<String>,
+) -> crate::agent::OpenHumanSessionHost {
+ let model: std::sync::Arc<dyn tinyinference_llm::model::ChatModel<()>> =
+ std::sync::Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));
+ crate::agent::SessionHostBuilder::new()
+ .chat_model(model)
+ .tools(tools)
+ .visible_tool_names(visible)
+ .memory(crate::memory::test_support::noop_memory())
+ .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))
+ .build()
+ .expect("session build")
+}
+
+fn direct_and_deferred() -> Vec<Box<dyn tinytools::Tool>> {
+ vec![
+ Box::new(FakeTool("plain", tinytools::ToolExposure::Direct)),
+ Box::new(FakeTool("rare", tinytools::ToolExposure::Deferred)),
+ ]
+}
+
/// A wildcard belt withholds every `Deferred` registration from the wire and
/// keeps it reachable: never advertised, always in the deferred set the
/// harness registers for its `tool_search` bridge, and classified `Allow` by
/// the policy — a found tool the gate refuses as prompt-hidden is the
/// unusable find this replaced.
#[test]
-fn wildcard_belt_defers_stock_tools_but_keeps_them_reachable() {
- let tmp = tempfile::TempDir::new().unwrap();
- let config = test_config(&tmp);
- let definition = crate::agent::harness::AgentDefinitionRegistry::builtins_only()
- .get("tools_agent")
- .cloned()
- .expect("tools_agent built-in definition");
- let agent =
- crate::agent::OpenHumanSessionHost::from_config_with_definition(&config, &definition)
- .expect("build tools agent");
+fn wildcard_belt_defers_but_keeps_reachable() {
+ let agent = build_with(direct_and_deferred(), std::collections::HashSet::new());
- let deferred = agent.deferred_tool_names_for_test();
- assert!(
- deferred.contains("stock_quote"),
- "stock_quote declares Deferred and must land in the deferred set; got {deferred:?}"
- );
- assert!(
- !agent.visible_tool_names_for_test().contains("stock_quote"),
- "a deferred tool must not be advertised"
+ assert_eq!(
+ agent.deferred_tool_names_for_test(),
+ &std::collections::HashSet::from(["rare".to_string()])
);
+ assert!(agent.visible_tool_names_for_test().contains("plain"));
+ assert!(!agent.visible_tool_names_for_test().contains("rare"));
assert!(
!agent
.visible_tool_specs_arc()
.iter()
- .any(|spec| spec.name == "stock_quote"),
+ .any(|spec| spec.name == "rare"),
"a deferred tool must not be in the prompt's spec list"
);
assert!(
- agent.tool_policy_session_for_test().is_allowed("stock_quote"),
+ agent.tool_policy_session_for_test().is_allowed("rare"),
"a deferred tool must be callable once found"
);
- assert!(
- !agent
- .visible_tool_names_for_test()
- .contains(crate::tools::implementations::meta::TOOL_SEARCH_NAME),
- "tool_search is the harness's intrinsic bridge, never a registered tool"
+}
+
+/// A named belt that lists `tool_search` opts into discovery: the name itself
+/// is the harness's intrinsic bridge and leaves the allowlist, every
+/// `Deferred` registration becomes reachable whether or not the belt named
+/// it, and the belt's own `Direct` entries stay exactly as written.
+#[test]
+fn named_belt_opts_into_discovery_by_naming_tool_search() {
+ let visible: std::collections::HashSet<String> = [
+ "plain",
+ crate::tools::implementations::meta::TOOL_SEARCH_NAME,
+ ]
+ .into_iter()
+ .map(String::from)
+ .collect();
+ let agent = build_with(direct_and_deferred(), visible);
+
+ assert_eq!(
+ agent.visible_tool_names_for_test(),
+ &std::collections::HashSet::from(["plain".to_string()])
+ );
+ assert_eq!(
+ agent.deferred_tool_names_for_test(),
+ &std::collections::HashSet::from(["rare".to_string()])
);
+ assert!(agent.tool_policy_session_for_test().is_allowed("rare"));
+}
+
+/// A named belt that does not opt in reaches nothing beyond what it wrote
+/// down: no deferred set, and a deferred tool it did not name stays hidden.
+#[test]
+fn named_belt_without_tool_search_reaches_no_deferred_tool() {
+ let visible: std::collections::HashSet<String> =
+ std::iter::once("plain".to_string()).collect();
+ let agent = build_with(direct_and_deferred(), visible);
+
+ assert!(agent.deferred_tool_names_for_test().is_empty());
+ assert!(!agent.tool_policy_session_for_test().is_allowed("rare"));
}
/// A hand-written `[tools] named` belt is left exactly as written: exposure is