diff --git a/python/packages/core/agent_framework/_skills.py b/python/packages/core/agent_framework/_skills.py index 91bdb61914..e863ada3ec 100644 --- a/python/packages/core/agent_framework/_skills.py +++ b/python/packages/core/agent_framework/_skills.py @@ -3092,6 +3092,7 @@ def _search(directory: str, current_depth: int) -> None: dir_path = Path(directory) if (dir_path / SKILL_FILE_NAME).is_file(): discovered.append(str(dir_path.absolute())) + return if current_depth >= MAX_SEARCH_DEPTH: return diff --git a/python/packages/core/tests/core/test_skills.py b/python/packages/core/tests/core/test_skills.py index 12d636ef41..43211e5f15 100644 --- a/python/packages/core/tests/core/test_skills.py +++ b/python/packages/core/tests/core/test_skills.py @@ -1917,6 +1917,19 @@ def test_finds_nested_skill(self, tmp_path: Path) -> None: assert len(dirs) == 1 assert str(sub.absolute()) in dirs[0] + def test_stops_searching_below_skill_boundary(self, tmp_path: Path) -> None: + skill_dir = tmp_path / "parent-skill" + nested_skill_dir = skill_dir / "nested-skill" + nested_skill_dir.mkdir(parents=True) + (skill_dir / "SKILL.md").write_text("---\nname: parent-skill\ndescription: d\n---\n", encoding="utf-8") + (nested_skill_dir / "SKILL.md").write_text( + "---\nname: nested-skill\ndescription: d\n---\n", encoding="utf-8" + ) + + dirs = FileSkillsSource._discover_skill_directories([str(tmp_path)]) + + assert dirs == [str(skill_dir.absolute())] + def test_skips_empty_path_string(self) -> None: dirs = FileSkillsSource._discover_skill_directories(["", " "]) assert dirs == []