Skip to content

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

feat(tools): inherit parent tool rules in sub-agent runs

Steven Enamakelf76c2df00368
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 12956413fa..a0b5d46002 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -985,7 +985,15 @@ async fn run_typed_mode(
task_id,
definition.iteration_policy == IterationPolicy::Extended,
options.thread_id.clone(),
- options.run_context.clone(),
+ {
+ let mut run_context = options.run_context.clone();
+ run_context.tool_rules = crate::tools::rules::child_rule_policy(
+ options.run_context.tool_rules.as_deref(),
+ config.as_ref().ok().map(|c| c.as_ref()),
+ &definition,
+ );
+ run_context
+ },
options.worker_thread_id.clone(),
parent.workspace_dir.clone(),
workspace_descriptor.clone(),
diff --git a/crates/openhuman-core/src/tools/rules/mod.rs b/crates/openhuman-core/src/tools/rules/mod.rs
index c7203191e5..f8207afbcc 100644
--- a/crates/openhuman-core/src/tools/rules/mod.rs
+++ b/crates/openhuman-core/src/tools/rules/mod.rs
@@ -19,7 +19,7 @@
mod ops;
pub use ops::{
- agent_rule_layer, 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.rs
index c322fb86b8..ac2702c536 100644
--- a/crates/openhuman-core/src/tools/rules/ops.rs
+++ b/crates/openhuman-core/src/tools/rules/ops.rs
@@ -80,6 +80,46 @@ pub fn rule_context(channel: Option<&str>, agent: Option<&str>, origin: Option<&
context
}
+/// 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 context keeps the parent's `channel` and `origin`; `agent` becomes the
+/// child's id. `None` when nothing restricts the child.
+#[must_use]
+pub fn child_rule_policy(
+ parent: Option<&ToolRulePolicy>,
+ config: Option<&Config>,
+ def: &AgentDefinition,
+) -> Option<Arc<ToolRulePolicy>> {
+ let mut set = match parent {
+ Some(parent) => (*parent.rules).clone(),
+ None => session_rule_set(config, None),
+ };
+ if let Some(layer) = agent_rule_layer(def) {
+ set.push(layer);
+ }
+ if set.is_permissive() {
+ return None;
+ }
+ let context = parent
+ .map(|parent| parent.context.clone())
+ .unwrap_or_default()
+ .with("agent", def.id.clone());
+ tracing::debug!(
+ agent = %def.id,
+ layers = set.layers.len(),
+ inherited = parent.is_some(),
+ "[tool_rules] sub-agent rule policy composed"
+ );
+ Some(Arc::new(ToolRulePolicy {
+ rules: Arc::new(set),
+ context,
+ }))
+}
+
/// The harness policy for one turn: `rules` evaluated in `context`.
#[must_use]
pub fn turn_rule_policy(rules: Arc<ToolRuleSet>, context: RuleContext) -> ToolRulePolicy {