Skip to content

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

feat(agent): scope spawn_async_subagent spec to allowed subagent ids

Steven Enamakelc54e0375e18b
diff --git a/crates/openhuman-core/src/agent/orchestration/tools.rs b/crates/openhuman-core/src/agent/orchestration/tools.rs
index e58bf1cc92..97bdf666d6 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools.rs
@@ -79,7 +79,7 @@ pub(crate) use list_subagents::ListSubagentsDispatch;
pub use list_subagents::ListSubagentsTool;
pub use skill_delegation::{SkillDelegationTool, INTEGRATIONS_DELEGATE_TOOL_NAME};
pub(crate) use spawn_async_subagent::SpawnAsyncSubagentDispatch;
-pub use spawn_async_subagent::SpawnAsyncSubagentTool;
+pub use spawn_async_subagent::{scope_spawn_async_subagent_spec, SpawnAsyncSubagentTool};
pub(crate) use spawn_parallel_agents::SpawnParallelAgentsDispatch;
pub use spawn_parallel_agents::SpawnParallelAgentsTool;
pub(crate) use spawn_subagent::SpawnSubagentDispatch;
diff --git a/crates/openhuman-core/src/agent/session_host/builder/mod.rs b/crates/openhuman-core/src/agent/session_host/builder/mod.rs
index db38f6afc4..9c18d52ae2 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/mod.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/mod.rs
@@ -139,6 +139,18 @@ pub(super) fn visible_tool_specs_for_policy(
})
.cloned()
.filter_map(|mut spec| {
+ if spec.name == "spawn_async_subagent" {
+ // Same narrowing for the spawn enum: advertise only the ids
+ // this agent's `[subagents]` allowlist lets `execute` dispatch.
+ let allowed = allowed_subagent_ids_for(&tool_policy.profile.agent_id);
+ if !allowed.is_empty() {
+ crate::agent::orchestration::tools::scope_spawn_async_subagent_spec(
+ Arc::make_mut(&mut spec),
+ &allowed,
+ );
+ }
+ return Some(spec);
+ }
if spec.name == crate::tools::toolpacks::USE_SKILL {
// `false` means no pack has a callable tool: an empty index and
// an empty enum are not a tool, so drop it rather than ship one.
@@ -194,3 +206,44 @@ pub(super) fn should_synthesize_delegation_tools(def: &AgentDefinition) -> bool
}),
}
}
+
+/// The sub-agent ids `agent_id`'s registry entry allows it to spawn.
+///
+/// Tolerates the web channel's `orchestrator_<thread>` rename the same way the
+/// orchestrator prompt does: exact match first, then the longest registry id
+/// the name extends at an `_` boundary. Empty when the registry is not up or
+/// the id resolves to nothing, which leaves the schema untouched.
+fn allowed_subagent_ids_for(agent_id: &str) -> Vec<String> {
+ use crate::agent::harness::definition::SubagentEntry;
+ let Some(registry) = crate::agent::harness::AgentDefinitionRegistry::global() else {
+ return Vec::new();
+ };
+ let definition = registry.get(agent_id).or_else(|| {
+ let best = registry
+ .list()
+ .iter()
+ .filter(|d| {
+ agent_id
+ .strip_prefix(d.id.as_str())
+ .is_some_and(|rest| rest.starts_with('_'))
+ })
+ .max_by_key(|d| d.id.len())?
+ .id
+ .clone();
+ registry.get(&best)
+ });
+ let Some(definition) = definition else {
+ return Vec::new();
+ };
+ definition
+ .subagents
+ .iter()
+ .filter_map(|entry| match entry {
+ SubagentEntry::AgentId(id) => Some(id.clone()),
+ SubagentEntry::Skills(wildcard) if wildcard.matches_all() => {
+ Some("integrations_agent".to_string())
+ }
+ SubagentEntry::Skills(_) => None,
+ })
+ .collect()
+}