Skip to content

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

fix(agent): enforce definition tool rules in hosted runs

Steven Enamakel512084191cc6
diff --git a/crates/openhuman-core/src/agent/registry/rpc.rs b/crates/openhuman-core/src/agent/registry/rpc.rs
index 439949a060..3d5efe1247 100644
--- a/crates/openhuman-core/src/agent/registry/rpc.rs
+++ b/crates/openhuman-core/src/agent/registry/rpc.rs
@@ -105,6 +105,7 @@ impl CreateCustomRequest {
system_prompt: self.system_prompt,
tool_allowlist: self.tool_allowlist,
tool_denylist: self.tool_denylist,
+ tool_rules: self.tool_rules.filter(|rules| !rules.is_permissive()),
subagents: self.subagents,
tags: self.tags,
metadata: self.metadata.unwrap_or(Value::Null),
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs b/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs
index ac92a08e52..aca609b1c9 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs
@@ -304,6 +304,10 @@ impl OpenHumanDefinitionRegistry {
model: model_for(&def.model),
subagents: declared_subagent_ids(def),
tools: self.tools_for(def),
+ // The definition's rule layer (its `tool_rules` plus its
+ // `disallowed_tools` as a deny), enforced by the harness gate on
+ // the catalogue, `tool_search` and every call of a hosted run.
+ tool_rules: crate::tools::rules::agent_rule_layer(def),
}
}
@@ -351,7 +355,7 @@ impl OpenHumanDefinitionRegistry {
// named scope. Under `Wildcard` it is meaningless — everything
// is already in scope.
names.extend(def.extra_tools.iter().cloned());
- names.retain(|name| !disallows_tool(&def.disallowed_tools, name));
+ names.retain(|name| !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name));
dedupe_preserving_order(&mut names);
// Deliberately *not* collapsed to `Wildcard` when empty: an
// agent configured with no tools, or one whose whole scope was
@@ -365,7 +369,7 @@ impl OpenHumanDefinitionRegistry {
Some(registered) => {
let mut names: Vec<String> = registered
.iter()
- .filter(|name| !disallows_tool(&def.disallowed_tools, name))
+ .filter(|name| !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name))
.cloned()
.collect();
dedupe_preserving_order(&mut names);
@@ -478,26 +482,6 @@ fn model_for(spec: &ModelSpec) -> Option<String> {
}
}
-/// Whether `name` is blocked by a definition's `disallowed_tools`.
-///
-/// Mirrors the private `definition_disallows_tool` in
-/// `agent/session_host/builder/factory.rs`, including its trailing-`*`
-/// prefix-match form. Duplicated rather than imported because that helper is
-/// module-private and Phase 4 must not edit existing files.
-///
-/// TODO(phase4): make `definition_disallows_tool` `pub(crate)` in
-/// `agent/session_host/builder/factory.rs` and delete this copy, so the
-/// denylist grammar has one implementation.
-fn disallows_tool(disallowed: &[String], name: &str) -> bool {
- disallowed.iter().any(|entry| {
- if let Some(prefix) = entry.strip_suffix('*') {
- name.starts_with(prefix)
- } else {
- entry == name
- }
- })
-}
-
/// Drops repeated names while keeping first-occurrence order.
///
/// `extra_tools` may restate something already in the named scope; the crate