Skip to content

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

fix(subagent): strip spawn tools from a child's dynamic tool list

Shanu19b98e008b9a
diff --git a/src/openhuman/agent/harness/subagent_runner/ops/runner.rs b/src/openhuman/agent/harness/subagent_runner/ops/runner.rs
index 9a4a1da1ae..ca40044b4f 100644
--- a/src/openhuman/agent/harness/subagent_runner/ops/runner.rs
+++ b/src/openhuman/agent/harness/subagent_runner/ops/runner.rs
@@ -32,7 +32,8 @@ use crate::openhuman::agent::harness::subagent_runner::handoff::ResultHandoffCac
use crate::openhuman::agent::harness::subagent_runner::subagent_iter_cap_with_autonomous_lift;
use crate::openhuman::agent::harness::subagent_runner::tool_prep::{
build_text_mode_tool_instructions, filter_tool_indices, is_subagent_spawn_tool,
- load_prompt_source, select_actions_with_essentials, top_k_for_toolkit,
+ load_prompt_source, select_actions_with_essentials, strip_spawn_tools_from_dynamic,
+ top_k_for_toolkit,
};
use crate::openhuman::agent::harness::subagent_runner::types::{
SubagentMode, SubagentRunError, SubagentRunOptions, SubagentRunOutcome, SubagentRunStatus,
@@ -1235,6 +1236,11 @@ async fn run_typed_mode(
None
};
+ // Dynamic tools never pass through `allowed_indices`, so the strip above has
+ // not seen them — the one route by which a spawn/delegate name can reach a
+ // child admitted (issue #6157). Strip before their five consumers below.
+ strip_spawn_tools_from_dynamic(&mut dynamic_tools, &definition.id);
+
// Build provider-visible tool schemas in EXECUTION-PRECEDENCE order:
// `dynamic_tools` (extra_tools at runtime) before parent specs.
let mut filtered_specs: Vec<ToolSpec> = dynamic_tools.iter().map(|t| t.spec()).collect();
diff --git a/src/openhuman/agent/harness/subagent_runner/tool_prep.rs b/src/openhuman/agent/harness/subagent_runner/tool_prep.rs
index c39b77394b..8c1c886345 100644
--- a/src/openhuman/agent/harness/subagent_runner/tool_prep.rs
+++ b/src/openhuman/agent/harness/subagent_runner/tool_prep.rs
@@ -422,3 +422,41 @@ pub(super) fn load_prompt_source(
}
}
}
+
+/// Remove every sub-agent spawn/delegate tool from a child's **dynamic**
+/// (per-spawn) tool list, in place.
+///
+/// The archetype's static surface is stripped via `allowed_indices` in
+/// [`super::ops::run_typed_mode`], but dynamic tools — per-action Composio
+/// toolkit tools and `extract_from_result` — are appended afterwards and never
+/// pass through that filter. That makes this the only route by which a
+/// spawn/delegate name can reach a child's allowlist *admitted*, so the #4452
+/// invariant has to be re-asserted here (issue #6157).
+///
+/// Strip once, at the point the list is finished, rather than at each use: the
+/// same `Vec` feeds the provider-visible specs, the resolved allowlist, the
+/// prompt catalogue, harness registration and the custom-graph request. Filter
+/// one and the others disagree — a tool advertised but not admitted, or the
+/// reverse. The registration-time backstop in
+/// `tinyagents::is_subagent_spawn_or_delegate_tool` is not sufficient on its
+/// own here: it cannot resolve `delegate_name` overrides, so it matches
+/// strictly less than [`is_subagent_spawn_tool`] does.
+pub(super) fn strip_spawn_tools_from_dynamic(
+ dynamic_tools: &mut Vec<Box<dyn Tool>>,
+ agent_id: &str,
+) {
+ dynamic_tools.retain(|tool| {
+ let name = tool.name();
+ // `spawn_worker_thread` is matched separately for the same reason the
+ // caller-side strip does it: it spawns a run without being a delegate.
+ let is_spawn = is_subagent_spawn_tool(name) || name == "spawn_worker_thread";
+ if is_spawn {
+ tracing::warn!(
+ agent_id = %agent_id,
+ tool = name,
+ "[subagent_runner] dropped a spawn/delegate tool from a sub-agent's dynamic tools"
+ );
+ }
+ !is_spawn
+ });
+}