Skip to content

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

fix(embed): withhold host tools per turn

Steven Enamakel87ae1b39bdde
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_host_tools_tests.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_host_tools_tests.rs
index ac3bf94e87..fc2df3ecf3 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_host_tools_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_host_tools_tests.rs
@@ -64,6 +64,44 @@ fn a_host_tool_is_on_the_belt_and_advertised() {
);
}
+/// A host can hide a config-derived tool for one turn without changing the
+/// agent's static scope or the tool belt used on its other turns.
+#[test]
+fn a_host_can_withhold_a_config_tool_for_one_turn() {
+ let tmp = tempfile::TempDir::new().unwrap();
+ let config = test_config(&tmp);
+ let normally_visible =
+ crate::agent::OpenHumanSessionHost::from_config_with_definition(&config, &definition())
+ .expect("build a session without a host belt")
+ .visible_tool_specs_arc()
+ .first()
+ .map(|spec| spec.name.clone())
+ .expect("the config-derived belt advertises at least one tool");
+
+ let host: crate::agent::HostTools = {
+ let normally_visible = normally_visible.clone();
+ Arc::new(move |_| crate::agent::HostTurnTools {
+ withheld: std::collections::HashSet::from([normally_visible.clone()]),
+ ..Default::default()
+ })
+ };
+ let agent = crate::agent::OpenHumanSessionHost::from_config_with_host_tools(
+ &config,
+ &definition(),
+ &host,
+ None,
+ )
+ .expect("build a session with a per-turn withheld name");
+
+ assert!(
+ !agent
+ .visible_tool_specs_arc()
+ .iter()
+ .any(|spec| spec.name == normally_visible),
+ "a per-turn host withholding must remove a config-derived tool from the provider view"
+ );
+}
+
/// Without this the seam would be a belt, not a factory, and a host whose
/// tools belong to something shorter-lived than the agent -- one episode, one
/// room -- would have to register a second agent to express that. It is also
diff --git a/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs b/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs
index e47902934f..567b9490cb 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/host_tools.rs
@@ -48,6 +48,13 @@ pub struct HostTurnTools {
pub tools: Vec<Box<dyn Tool>>,
/// Names to add to the provider-visible allow-list.
pub visible: HashSet<String>,
+ /// Names to remove from the provider-visible allow-list for this turn.
+ ///
+ /// This is applied after the config-derived scope and `visible` names are
+ /// combined, so a host can hide a tool that the agent normally receives
+ /// without changing the agent's scope for other turns. Withheld tools
+ /// remain registered and their execution policy is unchanged.
+ pub withheld: HashSet<String>,
/// The session's admission gate, if the host sets one.
pub policy: Option<Arc<dyn ToolPolicy>>,
}
@@ -103,6 +110,7 @@ impl HostTurnTools {
);
tools.splice(0..0, self.tools);
visible.extend(self.visible);
+ visible.retain(|name| !self.withheld.contains(name));
self.policy
}
@@ -129,7 +137,10 @@ impl HostTurnTools {
/// Whether this contributes nothing, so a caller can skip the union.
#[must_use]
pub fn is_empty(&self) -> bool {
- self.tools.is_empty() && self.visible.is_empty() && self.policy.is_none()
+ self.tools.is_empty()
+ && self.visible.is_empty()
+ && self.withheld.is_empty()
+ && self.policy.is_none()
}
}
@@ -145,6 +156,7 @@ impl std::fmt::Debug for HostTurnTools {
.collect::<Vec<_>>(),
)
.field("visible", &self.visible)
+ .field("withheld", &self.withheld)
.field("policy", &self.policy.is_some())
.finish()
}