Skip to content

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

fix(subagent_host): grant orchestrator role when nested spawn is allowed

Steven Enamakel48afabf98bd9
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 db50e9dbb2..22411a5389 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -476,20 +476,7 @@ async fn run_typed_mode(
};
// ── Filter tools per definition + per-spawn override ───────────────
- let mut allowed_indices = filter_tool_indices(
- &parent.all_tools,
- &definition.tools,
- &definition.disallowed_tools,
- options
- .skill_filter_override
- .as_deref()
- .or(definition.skill_filter.as_deref()),
- );
-
- // Sub-agents are leaves unless their own definition explicitly declares a
- // spawn tool, and the host's checked depth budget admits another child.
- // Keep the normal definition scope, denylist, and inherited ceiling as
- // independent constraints on that opt-in.
+ let nested_spawn_ids = definition.allowed_subagent_ids();
let explicitly_declares_nested_spawn = |name: &str| {
is_subagent_spawn_tool(name)
&& (definition.extra_tools.iter().any(|tool| tool == name)
@@ -499,12 +486,30 @@ async fn run_typed_mode(
if names.iter().any(|tool| tool == name)
))
};
- let nested_spawn_ids = definition.allowed_subagent_ids();
let nested_spawn_allowed = |name: &str| {
nested_spawn_depth_available
&& !nested_spawn_ids.is_empty()
&& explicitly_declares_nested_spawn(name)
};
+ let nested_spawn_granted = parent
+ .all_tools
+ .iter()
+ .any(|tool| nested_spawn_allowed(tool.name()));
+ let mut allowed_indices = filter_tool_indices_with_nested_spawn(
+ &parent.all_tools,
+ &definition.tools,
+ &definition.disallowed_tools,
+ options
+ .skill_filter_override
+ .as_deref()
+ .or(definition.skill_filter.as_deref()),
+ nested_spawn_granted,
+ );
+
+ // Sub-agents are leaves unless their own definition explicitly declares a
+ // spawn tool, and the host's checked depth budget admits another child.
+ // Keep the normal definition scope, denylist, and inherited ceiling as
+ // independent constraints on that opt-in.
let before = allowed_indices.len();
allowed_indices.retain(|&i| {
let name = parent.all_tools[i].name();
@@ -541,6 +546,7 @@ async fn run_typed_mode(
&mut allowed_indices,
&parent.all_tools,
&parent.subagent_tool_ceiling_names,
+ nested_spawn_granted,
);
// Rule-withheld tools stay callable (`allowed_names`) but off the prompt.
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 c97f546a0c..efb0696a8c 100644
--- a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
@@ -65,7 +65,6 @@ pub(super) fn filter_tool_indices_with_nested_spawn(
skill_filter: Option<&str>,
nested_spawn_granted: bool,
) -> Vec<usize> {
- let _ = nested_spawn_granted;
let mut first_specs = std::collections::HashMap::new();
let mut specs = Vec::new();
let mut disallowed_recovery = std::collections::HashSet::new();
@@ -91,7 +90,11 @@ pub(super) fn filter_tool_indices_with_nested_spawn(
};
let restricted = restrict_tools_with_scope(
&snapshot,
- SubagentRole::Leaf,
+ if nested_spawn_granted {
+ SubagentRole::Orchestrator
+ } else {
+ SubagentRole::Leaf
+ },
None,
&delegation_tools,
Some(scope),
@@ -131,6 +134,7 @@ pub(super) fn retain_parent_visible_tool_indices(
indices: &mut Vec<usize>,
parent_tools: &[Box<dyn Tool>],
parent_visible: &std::collections::HashSet<String>,
+ nested_spawn_granted: bool,
) {
if parent_visible.is_empty() {
return;
@@ -159,7 +163,11 @@ pub(super) fn retain_parent_visible_tool_indices(
};
let narrowed = restrict_tools_with_scope(
&snapshot,
- SubagentRole::Leaf,
+ if nested_spawn_granted {
+ SubagentRole::Orchestrator
+ } else {
+ SubagentRole::Leaf
+ },
Some(&ceiling),
&[],
None,