The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(rules): stop sub-agents inheriting their parent's agent layer
Steven Enamakel1b450f5dbbf7
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.rsindex ecdd092615..b2d5701073 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,7 +96,6 @@ pub(crate) fn worktree_request_for_task(task: &ParallelAgentTask) -> ParallelWor}}-fn definition_visible_tool_permissions(definition: &AgentDefinition,parent: &ParentExecutionContext,diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rsindex e82110ad91..977b361b62 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,15 @@ impl OpenHumanSessionHost {.filter(|t| t.exposure() != tinytools::ToolExposure::Hidden).map(|t| t.name().to_string()),)- .filter(|name| !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name))+ .filter(|name| {+ !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name)+ }).collect();}ToolScope::Named(_) => {- visible- .retain(|name| !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name));+ visible.retain(|name| {+ !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name)+ });}}// Disallowing every tool must remain a zero-tool scope. An@@ -928,7 +931,6 @@ fn resolve_target_definition())}-/// Resolve the provider/workload role for a session build.////// Explicit `hint:<role>` markers route to their workload; everything elsediff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rsindex a0b5d46002..517271ac6f 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs@@ -710,10 +710,7 @@ async fn run_typed_mode(let name = tool.name();if definition.extra_tools.iter().any(|n| n == name)&& !allowed_indices.contains(&i)- && !crate::tools::rules::glob_list_matches(- &definition.disallowed_tools,- name,- )+ && !crate::tools::rules::glob_list_matches(&definition.disallowed_tools, name)&& !is_subagent_spawn_tool(name){allowed_indices.push(i);diff --git a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rsindex 1fd6e6db8e..046ada3615 100644--- a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs+++ b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs@@ -146,7 +146,6 @@ pub(super) fn retain_parent_visible_tool_indices(indices.retain(|&index| parent_visible.contains(parent_tools[index].name()));}-#[cfg(test)]#[path = "tool_prep_tests.rs"]mod tests;diff --git a/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs b/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rsindex aca609b1c9..b469fedc0f 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/definition_registry.rs@@ -355,7 +355,9 @@ impl OpenHumanDefinitionRegistry {// named scope. Under `Wildcard` it is meaningless — everything// is already in scope.names.extend(def.extra_tools.iter().cloned());- names.retain(|name| !crate::tools::rules::glob_list_matches(&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@@ -369,7 +371,9 @@ impl OpenHumanDefinitionRegistry {Some(registered) => {let mut names: Vec<String> = registered.iter()- .filter(|name| !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name))+ .filter(|name| {+ !crate::tools::rules::glob_list_matches(&def.disallowed_tools, name)+ }).cloned().collect();dedupe_preserving_order(&mut names);diff --git a/crates/openhuman-core/src/tools/rules/mod.rs b/crates/openhuman-core/src/tools/rules/mod.rsindex f8207afbcc..357f73e8d2 100644--- a/crates/openhuman-core/src/tools/rules/mod.rs+++ b/crates/openhuman-core/src/tools/rules/mod.rs@@ -19,7 +19,8 @@mod ops;pub use ops::{- agent_rule_layer, child_rule_policy, glob_list_matches, rule_context, session_rule_set, turn_rule_policy,+ agent_rule_layer, child_rule_policy, glob_list_matches, rule_context, session_rule_set,+ turn_rule_policy,};#[cfg(test)]diff --git a/crates/openhuman-core/src/tools/rules/ops.rs b/crates/openhuman-core/src/tools/rules/ops.rsindex ac2702c536..fa01557585 100644--- a/crates/openhuman-core/src/tools/rules/ops.rs+++ b/crates/openhuman-core/src/tools/rules/ops.rs@@ -3,7 +3,7 @@use std::sync::Arc;use tinyagents_harness::tool::ToolRulePolicy;-use tinytools::{RuleContext, RuleEffect, ToolRule, ToolRuleSet, ToolRules, glob_matches};+use tinytools::{glob_matches, RuleContext, RuleEffect, ToolRule, ToolRuleSet, ToolRules};use crate::agent::harness::definition::AgentDefinition;use crate::config::Config;@@ -21,6 +21,9 @@ pub fn glob_list_matches(patterns: &[String], name: &str) -> bool {patterns.iter().any(|pattern| glob_matches(pattern, name))}+/// Name prefix of every layer an agent definition contributes.+const AGENT_LAYER_PREFIX: &str = "agent:";+/// The rule layer an agent definition contributes: its `tool_rules`, plus a/// `deny` for its `disallowed_tools`, so a denied tool is refused on every/// surface — including `tool_search` and a call by a guessed name — not only@@ -38,9 +41,13 @@ pub fn agent_rule_layer(def: &AgentDefinition) -> Option<ToolRules> {if layer.is_permissive() {return None;}- if layer.name.is_none() {- layer.name = Some(format!("agent:{}", def.id));- }+ // Always `agent:<id>`, keeping an author's own name as a suffix: the+ // prefix is how a sub-agent tells its parent's agent layer from the+ // operator's layers it inherits (see `child_rule_policy`).+ layer.name = Some(match layer.name.take() {+ Some(own) => format!("{AGENT_LAYER_PREFIX}{}/{own}", def.id),+ None => format!("{AGENT_LAYER_PREFIX}{}", def.id),+ });Some(layer)}@@ -70,7 +77,11 @@ pub fn session_rule_set(config: Option<&Config>, def: Option<&AgentDefinition>)/// The context `when` conditions match: `channel`, `agent`, `origin`. Absent/// or blank values are left out, so a condition on them does not match.#[must_use]-pub fn rule_context(channel: Option<&str>, agent: Option<&str>, origin: Option<&str>) -> RuleContext {+pub fn rule_context(+ channel: Option<&str>,+ agent: Option<&str>,+ origin: Option<&str>,+) -> RuleContext {let mut context = RuleContext::new();for (key, value) in [("channel", channel), ("agent", agent), ("origin", origin)] {if let Some(value) = value.map(str::trim).filter(|value| !value.is_empty()) {@@ -82,10 +93,12 @@ pub fn rule_context(channel: Option<&str>, agent: Option<&str>, origin: Option<&/// The rule policy for a sub-agent run of `def`.///-/// The child keeps every layer its parent turn carried — a sub-agent is never-/// less restricted than the run that spawned it — and adds its own-/// definition's layer. A parent without rules (an entry point that built its-/// context from scratch) contributes the operator's `[tool_rules]` instead.+/// The child keeps every operator layer its parent turn carried — the+/// `[tool_rules]` an operator set bind every agent in the tree — and adds its+/// own definition's layer. It does **not** inherit the parent *agent's* layer:+/// an orchestrator commonly disallows exactly the tools it delegates to its+/// workers. A parent without rules (an entry point that built its context+/// from scratch) contributes the operator's `[tool_rules]` directly./// The context keeps the parent's `channel` and `origin`; `agent` becomes the/// child's id. `None` when nothing restricts the child.#[must_use]@@ -95,7 +108,19 @@ pub fn child_rule_policy(def: &AgentDefinition,) -> Option<Arc<ToolRulePolicy>> {let mut set = match parent {- Some(parent) => (*parent.rules).clone(),+ Some(parent) => {+ let mut inherited = ToolRuleSet::new();+ for layer in &parent.rules.layers {+ let is_agent_layer = layer+ .name+ .as_deref()+ .is_some_and(|name| name.starts_with(AGENT_LAYER_PREFIX));+ if !is_agent_layer {+ inherited.push(layer.clone());+ }+ }+ inherited+ }None => session_rule_set(config, None),};if let Some(layer) = agent_rule_layer(def) {diff --git a/crates/openhuman-core/src/tools/rules/ops_tests.rs b/crates/openhuman-core/src/tools/rules/ops_tests.rsindex b93ebc8b51..34727a6ce9 100644--- a/crates/openhuman-core/src/tools/rules/ops_tests.rs+++ b/crates/openhuman-core/src/tools/rules/ops_tests.rs@@ -32,7 +32,10 @@ fn glob_list_keeps_the_legacy_exact_and_prefix_forms() {#[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,+ "mcp_github_delete_repo_abc123"+ ));assert!(glob_list_matches(&patterns, "GMAIL_SEND_EMAIL"));}@@ -51,7 +54,12 @@ fn disallowed_tools_become_a_deny_rule_on_every_surface() {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);+ 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));@@ -65,7 +73,7 @@ fn a_definition_rule_layer_keeps_its_own_name_and_adds_the_denylist() {);def.disallowed_tools = vec!["file_delete".into()];let layer = agent_rule_layer(&def).expect("a layer");- assert_eq!(layer.name.as_deref(), Some("custom"));+ assert_eq!(layer.name.as_deref(), Some("agent:writer/custom"));let set = ToolRuleSet::single(layer);let context = rule_context(None, None, None);assert!(visible(&set, "file_read", &context));@@ -136,3 +144,46 @@ except = { family = "github" }assert_eq!(config.tool_rules.rules.len(), 1);assert_eq!(config.tool_rules.rules[0].id.as_deref(), Some("no-mcp"));}++#[test]+fn a_child_inherits_operator_layers_but_not_its_parents_agent_layer() {+ let mut config = Config::default();+ config.tool_rules = tinytools::ToolRules::from_allow_deny(Vec::<String>::new(), ["shell"]);+ let mut orchestrator = definition("orchestrator");+ orchestrator.disallowed_tools = vec!["file_*".into()];+ let parent = turn_rule_policy(+ Arc::new(session_rule_set(Some(&config), Some(&orchestrator))),+ rule_context(+ Some("telegram"),+ Some("orchestrator"),+ Some("ExternalChannel(telegram)"),+ ),+ );+ let mut worker = definition("code_executor");+ worker.disallowed_tools = vec!["web_*".into()];++ let child = child_rule_policy(Some(&parent), None, &worker).expect("child rules");+ assert_eq!(child.context.get("agent"), Some("code_executor"));+ assert_eq!(child.context.get("channel"), Some("telegram"));+ assert!(+ !visible(&child.rules, "shell", &child.context),+ "operator layer inherited"+ );+ assert!(+ visible(&child.rules, "file_write", &child.context),+ "parent agent layer dropped"+ );+ assert!(+ !visible(&child.rules, "web_fetch", &child.context),+ "own layer added"+ );+}++#[test]+fn a_child_without_parent_rules_takes_the_operator_layer() {+ let mut config = Config::default();+ config.tool_rules = tinytools::ToolRules::from_allow_deny(Vec::<String>::new(), ["shell"]);+ let child = child_rule_policy(None, Some(&config), &definition("worker")).expect("rules");+ assert!(!visible(&child.rules, "shell", &child.context));+ assert!(child_rule_policy(None, None, &definition("worker")).is_none());+}