Skip to content

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

test(subagent_host): cover nested spawn prompt framing and host grant

Steven Enamakeldde0163ec90f
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/prompt.rs b/crates/openhuman-core/src/agent/subagent_host/ops/prompt.rs
index 92d9ff7b45..9bbaf8b85a 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/prompt.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/prompt.rs
@@ -29,6 +29,34 @@ pub(crate) fn compose_subagent_system_prompt(
append_artifact_offload_contract(framed, agent_id, visible_tool_names)
}
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn prompt_framing_matches_the_child_spawn_surface() {
+ let nested = ["spawn_subagent".to_owned()].into_iter().collect();
+ let nested_prompt = compose_subagent_system_prompt(
+ "Worker instructions".into(),
+ "worker",
+ &nested,
+ "complete the task",
+ 1,
+ );
+ assert!(nested_prompt.contains("You may delegate parts of the work"));
+ assert!(!nested_prompt.contains("You are a leaf worker"));
+
+ let leaf_prompt = compose_subagent_system_prompt(
+ "Worker instructions".into(),
+ "worker",
+ &HashSet::new(),
+ "complete the task",
+ 1,
+ );
+ assert!(leaf_prompt.contains("You are a leaf worker"));
+ }
+}
+
/// Append the filesystem-offload contract (#3883), but only for a sub-agent
/// that actually holds a file-write tool.
///
diff --git a/crates/openhuman-core/src/agent/subagent_host/tool_prep_tests.rs b/crates/openhuman-core/src/agent/subagent_host/tool_prep_tests.rs
index 8ba81bb084..43f98b73cd 100644
--- a/crates/openhuman-core/src/agent/subagent_host/tool_prep_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/tool_prep_tests.rs
@@ -34,6 +34,27 @@ fn child_tool_surface_never_contains_any_spawn_or_continuation_tool() {
);
}
+#[test]
+fn explicitly_scoped_nested_spawn_is_retained_only_with_host_grant() {
+ let tools: Vec<Box<dyn Tool>> = vec![Box::new(NamedTool("spawn_subagent"))];
+ let scope = ToolScope::Named(vec!["spawn_subagent".to_owned()]);
+
+ assert!(filter_tool_indices_with_nested_spawn(&tools, &scope, &[], None, false).is_empty());
+ assert_eq!(
+ filter_tool_indices_with_nested_spawn(&tools, &scope, &[], None, true),
+ vec![0],
+ "an explicit host grant should preserve the definition's named spawn tool"
+ );
+ assert!(filter_tool_indices_with_nested_spawn(
+ &tools,
+ &scope,
+ &["spawn_subagent".to_owned()],
+ None,
+ true,
+ )
+ .is_empty(), "the definition denylist must still win over the grant");
+}
+
#[test]
fn child_keeps_the_parents_protocol() {
use tinytools_agent::dialect::ToolCallFormat;