Skip to content

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

feat(agent): add parallel graph staging for subagent spawns

Steven Enamakel61f12e626cbb
diff --git a/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/staging.rs b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/staging.rs
index 2ad310bb98..ecdd092615 100644
--- a/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/staging.rs
+++ b/crates/openhuman-core/src/agent/orchestration/spawn_parallel_graph/staging.rs
@@ -96,15 +96,6 @@ pub(crate) fn worktree_request_for_task(task: &ParallelAgentTask) -> ParallelWor
}
}
-fn disallowed_tool_matches(disallowed: &[String], name: &str) -> bool {
- disallowed.iter().any(|entry| {
- if let Some(prefix) = entry.strip_suffix('*') {
- name.starts_with(prefix)
- } else {
- entry == name
- }
- })
-}
fn definition_visible_tool_permissions(
definition: &AgentDefinition,
@@ -119,7 +110,7 @@ fn definition_visible_tool_permissions(
.iter()
.filter_map(|tool| {
let name = tool.name();
- if disallowed_tool_matches(&definition.disallowed_tools, name) {
+ if crate::tools::rules::glob_list_matches(&definition.disallowed_tools, name) {
return None;
}
if let Some(prefix) = skill_prefix.as_deref() {
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
index 2620631b74..e82110ad91 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
@@ -606,12 +606,12 @@ impl OpenHumanSessionHost {
.filter(|t| t.exposure() != tinytools::ToolExposure::Hidden)
.map(|t| t.name().to_string()),
)
- .filter(|name| !definition_disallows_tool(&def.disallowed_tools, name))
+ .filter(|name| !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name))
.collect();
}
ToolScope::Named(_) => {
visible
- .retain(|name| !definition_disallows_tool(&def.disallowed_tools, name));
+ .retain(|name| !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name));
}
}
// Disallowing every tool must remain a zero-tool scope. An
@@ -928,15 +928,6 @@ fn resolve_target_definition(
))
}
-fn definition_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
- }
- })
-}
/// Resolve the provider/workload role for a session build.
///
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
index 60702d2c6e..12956413fa 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -710,7 +710,7 @@ async fn run_typed_mode(
let name = tool.name();
if definition.extra_tools.iter().any(|n| n == name)
&& !allowed_indices.contains(&i)
- && !super::super::tool_prep::disallowed_tool_matches(
+ && !crate::tools::rules::glob_list_matches(
&definition.disallowed_tools,
name,
)
diff --git a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
index 2a19dc6929..1fd6e6db8e 100644
--- a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
@@ -106,7 +106,7 @@ pub(super) fn filter_tool_indices(
.enumerate()
.filter(|(_, tool)| {
let name = tool.name();
- if disallowed_tool_matches(disallowed, name) {
+ if crate::tools::rules::glob_list_matches(disallowed, name) {
return false;
}
// The CCR recovery tool is advertised to any agent that has a tool
@@ -146,15 +146,6 @@ pub(super) fn retain_parent_visible_tool_indices(
indices.retain(|&index| parent_visible.contains(parent_tools[index].name()));
}
-pub(super) fn disallowed_tool_matches(disallowed: &[String], name: &str) -> bool {
- disallowed.iter().any(|entry| {
- if let Some(prefix) = entry.strip_suffix('*') {
- name.starts_with(prefix)
- } else {
- entry == name
- }
- })
-}
#[cfg(test)]
#[path = "tool_prep_tests.rs"]
diff --git a/crates/openhuman-core/src/tools/rules/ops_tests.rs b/crates/openhuman-core/src/tools/rules/ops_tests.rs
new file mode 100644
index 0000000000..b93ebc8b51
--- /dev/null
+++ b/crates/openhuman-core/src/tools/rules/ops_tests.rs
@@ -0,0 +1,138 @@
+use super::*;
+
+use tinytools::{Surface, ToolSubject};
+
+fn definition(id: &str) -> AgentDefinition {
+ crate::agent::harness::builtin_definitions::all()
+ .into_iter()
+ .next()
+ .map(|mut def| {
+ def.id = id.to_string();
+ def.disallowed_tools.clear();
+ def.tool_rules = None;
+ def
+ })
+ .expect("a built-in definition")
+}
+
+fn visible(set: &ToolRuleSet, name: &str, context: &tinytools::RuleContext) -> bool {
+ set.visible(&ToolSubject::named(name), context, Surface::Catalog)
+}
+
+#[test]
+fn glob_list_keeps_the_legacy_exact_and_prefix_forms() {
+ let patterns = vec!["shell".to_string(), "spawn_*".to_string()];
+ assert!(glob_list_matches(&patterns, "shell"));
+ assert!(glob_list_matches(&patterns, "spawn_subagent"));
+ assert!(!glob_list_matches(&patterns, "shell_exec"));
+ assert!(!glob_list_matches(&patterns, "file_read"));
+ assert!(!glob_list_matches(&[], "shell"));
+}
+
+#[test]
+fn glob_list_now_also_takes_inner_wildcards_and_any_case() {
+ let patterns = vec!["mcp_*_delete_*".to_string(), "gmail_*".to_string()];
+ assert!(glob_list_matches(&patterns, "mcp_github_delete_repo_abc123"));
+ assert!(glob_list_matches(&patterns, "GMAIL_SEND_EMAIL"));
+}
+
+#[test]
+fn an_unrestricted_definition_contributes_no_layer() {
+ assert!(agent_rule_layer(&definition("plain")).is_none());
+}
+
+#[test]
+fn disallowed_tools_become_a_deny_rule_on_every_surface() {
+ let mut def = definition("researcher");
+ def.disallowed_tools = vec!["shell".into(), "web_*".into()];
+ let layer = agent_rule_layer(&def).expect("a layer");
+ assert_eq!(layer.name.as_deref(), Some("agent:researcher"));
+ let set = ToolRuleSet::single(layer);
+ let context = rule_context(None, None, None);
+ assert!(!visible(&set, "shell", &context));
+ assert!(!set.visible(&ToolSubject::named("web_fetch"), &context, Surface::Search));
+ let call = set.evaluate(&ToolSubject::named("web_fetch"), &context, Surface::Call, None);
+ assert!(!call.callable);
+ assert!(call.refusal("web_fetch").contains("disallowed_tools"));
+ assert!(visible(&set, "file_read", &context));
+}
+
+#[test]
+fn a_definition_rule_layer_keeps_its_own_name_and_adds_the_denylist() {
+ let mut def = definition("writer");
+ def.tool_rules = Some(
+ tinytools::ToolRules::from_allow_deny(["file_*"], Vec::<String>::new()).named("custom"),
+ );
+ def.disallowed_tools = vec!["file_delete".into()];
+ let layer = agent_rule_layer(&def).expect("a layer");
+ assert_eq!(layer.name.as_deref(), Some("custom"));
+ let set = ToolRuleSet::single(layer);
+ let context = rule_context(None, None, None);
+ assert!(visible(&set, "file_read", &context));
+ assert!(!visible(&set, "file_delete", &context));
+ assert!(!visible(&set, "shell", &context));
+}
+
+#[test]
+fn the_session_set_stacks_config_then_agent() {
+ let mut config = Config::default();
+ config.tool_rules = tinytools::ToolRules::from_allow_deny(Vec::<String>::new(), ["shell"]);
+ let mut def = definition("helper");
+ def.disallowed_tools = vec!["web_*".into()];
+ let set = session_rule_set(Some(&config), Some(&def));
+ assert_eq!(set.layers.len(), 2);
+ assert_eq!(set.layers[0].name.as_deref(), Some("config"));
+ assert_eq!(set.layers[1].name.as_deref(), Some("agent:helper"));
+ let context = rule_context(None, None, None);
+ assert!(!visible(&set, "shell", &context));
+ assert!(!visible(&set, "web_fetch", &context));
+ assert!(visible(&set, "file_read", &context));
+}
+
+#[test]
+fn an_empty_config_and_definition_yield_a_permissive_set() {
+ let set = session_rule_set(Some(&Config::default()), Some(&definition("x")));
+ assert!(set.is_permissive());
+ assert!(session_rule_set(None, None).is_permissive());
+}
+
+#[test]
+fn the_rule_context_drops_blank_values() {
+ let context = rule_context(Some("telegram"), Some(" "), None);
+ assert_eq!(context.get("channel"), Some("telegram"));
+ assert_eq!(context.get("agent"), None);
+ assert_eq!(context.get("origin"), None);
+}
+
+#[test]
+fn turn_policy_evaluates_when_conditions_in_its_context() {
+ let mut config = Config::default();
+ config.tool_rules = serde_json::from_value(serde_json::json!({ "rules": [
+ { "effect": "deny", "match": { "name": "shell" }, "when": { "channel": "telegram" } },
+ ] }))
+ .expect("rules");
+ let set = Arc::new(session_rule_set(Some(&config), None));
+ let telegram = turn_rule_policy(set.clone(), rule_context(Some("telegram"), None, None));
+ let web = turn_rule_policy(set, rule_context(Some("web"), None, None));
+ assert!(!visible(&telegram.rules, "shell", &telegram.context));
+ assert!(visible(&web.rules, "shell", &web.context));
+}
+
+#[test]
+fn config_parses_a_tool_rules_table_from_toml() {
+ let config: Config = toml::from_str(
+ r#"
+[tool_rules]
+default = "allow"
+
+[[tool_rules.rules]]
+id = "no-mcp"
+effect = "deny"
+match = { name = "mcp_*" }
+except = { family = "github" }
+"#,
+ )
+ .expect("config parses");
+ assert_eq!(config.tool_rules.rules.len(), 1);
+ assert_eq!(config.tool_rules.rules[0].id.as_deref(), Some("no-mcp"));
+}